-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
103 lines (95 loc) · 2.65 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const path = require('path');
const webpack = require('webpack');
const pkg = require('./package.json');
const bannerPack = new webpack.BannerPlugin({
banner: [
`Quill Smart Break v${pkg.version}`,
'https://github.com/simialbi/quill-smart-break',
'Copyright (c) 2017, Ahad Birang',
'Copyright (c) 2017, Mike Ackerman',
'Copyright (c) 2020, Simon Karlen'
].join('\n'),
entryOnly: true
});
const constantPack = new webpack.DefinePlugin({
QUILL_SMART_BREAK_VERSION: JSON.stringify(pkg.version)
});
const source = [
'smart-breaker.js',
'blots'
].map(file => {
return path.resolve(__dirname, 'src', file);
});
const jsRules = {
test: /\.js$/,
include: source,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/env',
{
targets: {
browsers: [
'last 2 Chrome major versions',
'last 2 Firefox major versions',
'last 2 Safari major versions',
'last 2 Edge major versions',
'last 2 iOS major versions',
'last 2 ChromeAndroid major versions',
]
}
}
]
]
}
}
]
};
const baseConfig = {
mode: 'development',
context: path.resolve(__dirname, 'src'),
entry: {
'smart-breaker.js': './smart-breaker.js'
},
output: {
filename: '[name]',
path: path.resolve(__dirname, 'dist')
},
externals: {
quill: 'Quill'
},
module: {
rules: [jsRules],
// noParse: []
},
plugins: [
bannerPack,
constantPack
],
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
hot: false,
port: process.env.npm_package_config_ports_webpack,
stats: 'minimal',
disableHostCheck: true
}
};
module.exports = env => {
if (env && env.minimize) {
const { devServer, ...prodConfig } = baseConfig;
return {
...prodConfig,
mode: 'production',
entry: { 'smart-breaker.min.js': './smart-breaker.js' },
devtool: 'source-map'
};
}
if (env && env.coverage) {
baseConfig.module.rules[0].use[0].options.plugins = ['istanbul'];
return baseConfig;
}
return baseConfig;
};