-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
get-config.js
83 lines (78 loc) · 2.05 KB
/
get-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
let { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
let escapeRegexp = require('escape-string-regexp')
let OptimizeCss = require('optimize-css-assets-webpack-plugin')
let PnpWebpackPlugin = require('pnp-webpack-plugin')
const STATIC =
/\.(eot|woff2?|ttf|otf|svg|png|jpe?g|gif|webp|mp4|mp3|ogg|pdf|html|ico|md)$/
module.exports = function getConfig (limitConfig, check, output) {
let config = {
entry: {
index: check.path
},
output: {
filename: limitConfig.why && `${ limitConfig.project }.js`,
path: output
},
optimization: {
concatenateModules: !check.disableModuleConcatenation
},
resolve: {
plugins: [
PnpWebpackPlugin
]
},
resolveLoader: {
plugins: [
PnpWebpackPlugin.moduleLoader(module)
]
},
module: {
rules: [
{
test: STATIC,
use: 'file-loader'
},
{
test: /\.css$/,
exclude: /\.module\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.module\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true
}
}
]
}
]
},
plugins: [
new OptimizeCss()
]
}
if (check.ignore && check.ignore.length > 0) {
let escaped = check.ignore.map(i => escapeRegexp(i))
let ignorePattern = new RegExp(`^(${ escaped.join('|') })($|/)`)
config.externals = (context, request, callback) => {
if (ignorePattern.test(request)) {
callback(null, 'root a')
} else {
callback()
}
}
}
if (limitConfig.why) {
config.plugins.push(new BundleAnalyzerPlugin({
openAnalyzer: process.env.NODE_ENV !== 'test',
analyzerMode: process.env.NODE_ENV === 'test' ? 'static' : 'server',
defaultSizes: check.gzip === false ? 'parsed' : 'gzip',
analyzerPort: 8888 + limitConfig.checks.findIndex(i => i === check)
}))
}
return config
}