-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
91 lines (79 loc) · 2.15 KB
/
index.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
/* eslint-disable sonarjs/no-duplicate-string */
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
const makeLoaderFinder = require('razzle-dev-utils/makeLoaderFinder')
module.exports = () => ({
modifyWebpackConfig({env: {target, dev: isDev}, webpackConfig}) {
const isServer = target === 'node'
const localIdentName = isDev ? '[path][name]__[local]' : '[contenthash:base64:8]'
let loaders
let vendorCSSLoaders
if (isServer) {
loaders = [
{
loader: 'css-loader',
options: {
esModule: true,
modules: {
localIdentName,
exportOnlyLocals: true
}
}
},
'postcss-loader'
]
vendorCSSLoaders = ['css-loader']
} else if (isDev) {
loaders = [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {localIdentName}
}
},
'postcss-loader'
]
vendorCSSLoaders = ['style-loader', 'css-loader', 'postcss-loader']
} else {
loaders = [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {localIdentName}
}
},
'postcss-loader'
]
vendorCSSLoaders = [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: {
// NOTE: игнорируем загрузку base64 изображений в стилях
filter: (url) => !/^data:image/.test(url)
}
}
},
'postcss-loader'
]
}
const cssLoader = webpackConfig.module.rules.find(
makeLoaderFinder('css-loader')
)
cssLoader.test = /\.css$/
cssLoader.exclude = [/node_modules/]
cssLoader.use = loaders
webpackConfig.module.rules.push({
test: /\.css$/,
include: [/node_modules/],
use: vendorCSSLoaders
})
if (!isServer) {
webpackConfig.plugins.push(new CssMinimizerPlugin())
}
return webpackConfig
}
})