-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.util.js
94 lines (89 loc) · 2.21 KB
/
webpack.util.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
const path = require('path')
const fs = require('fs')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { isEnvDevelopment, isEnvProduction } = require('./config')
const appSrc = path.resolve(fs.realpathSync(process.cwd()), 'src')
const getStyleLoaders = (cssOptions, preProcessor) => {
const loaders = [
isEnvDevelopment && require.resolve('style-loader'),
isEnvProduction && {
loader: MiniCssExtractPlugin.loader,
options: { publicPath: '../../' }
},
{
loader: require.resolve('css-loader'),
options: cssOptions
},
{
loader: require.resolve('postcss-loader'),
options: {
postcssOptions: {
// https://github.com/facebook/create-react-app/issues/2677
ident: 'postcss',
config: false,
plugins: [
'postcss-flexbugs-fixes',
[
'postcss-preset-env',
{
autoprefixer: {
flexbox: 'no-2009'
},
stage: 3
}
]
]
},
sourceMap: isEnvDevelopment
}
}
].filter(Boolean)
if (preProcessor) {
loaders.push(
{
loader: require.resolve('resolve-url-loader'),
options: {
sourceMap: isEnvDevelopment,
root: appSrc
}
},
{
loader: require.resolve(preProcessor),
options: {
sourceMap: true
}
}
)
}
return loaders
}
const getHTMLPluginDefaultConfig = () =>
Object.assign(
{},
{
inject: true
},
isEnvProduction
? {
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
}
: undefined
)
const getPkgDirByName = (pkgName) => path.resolve(__dirname, '.', 'packages', pkgName)
module.exports = {
appSrc,
getStyleLoaders,
getPkgDirByName,
getHTMLPluginDefaultConfig
}