-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.babel.js
112 lines (110 loc) · 3.07 KB
/
webpack.config.babel.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
104
105
106
107
108
109
110
111
112
const Path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const VisualizerPlugin = require('webpack-visualizer-plugin2');
const MAX_DEVELOPMENT_OUTPUT_SIZE = 3300000;
const MAX_PRODUCTION_OUTPUT_SIZE = 440000;
module.exports = (env, argv) => ({
devtool: argv.mode === 'production'
? false
: 'eval-cheap-module-source-map',
entry: {
'docs-custom-properties': Path.join(__dirname, 'src/docsCustomProperties.js'),
'react-ui': Path.join(__dirname, 'src/index.js'),
},
externals: {
react: {
amd: 'react',
commonjs: 'react',
commonjs2: 'react',
root: 'React',
umd: 'react',
},
'react-dom': {
amd: 'react-dom',
commonjs: 'react-dom',
commonjs2: 'react-dom',
root: 'ReactDOM',
umd: 'react-dom',
},
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: [{ loader: 'babel-loader' }],
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
auto: true, // Enable CSS Modules only for files with `.module.*` extension
exportLocalsConvention: 'as-is',
localIdentName: argv.mode === 'production'
? '[hash:base64:8]'
: '[name]__[local]__[hash:base64:8]',
namedExport: false,
},
},
},
{ loader: 'postcss-loader' },
{
loader: 'sass-loader',
options: {
sassOptions: {
includePaths: ['node_modules'],
},
},
},
],
},
],
},
optimization: {
minimize: argv.mode === 'production',
minimizer: [new TerserPlugin()],
},
output: {
filename: argv.mode === 'production'
? '[name].js'
: '[name].development.js',
libraryTarget: 'umd',
path: Path.join(__dirname, 'src/docs/_assets/generated/'),
},
performance: {
hints: 'error',
maxAssetSize: argv.mode === 'production'
? MAX_PRODUCTION_OUTPUT_SIZE
: MAX_DEVELOPMENT_OUTPUT_SIZE,
maxEntrypointSize: argv.mode === 'production'
? MAX_PRODUCTION_OUTPUT_SIZE
: MAX_DEVELOPMENT_OUTPUT_SIZE,
},
plugins: [
new MiniCssExtractPlugin({
chunkFilename: argv.mode === 'production'
? '[id].css'
: '[id].development.css',
filename: argv.mode === 'production'
? '[name].css'
: '[name].development.css',
ignoreOrder: false, // Enable to remove warnings about conflicting order
}),
new StyleLintPlugin({
configFile: 'stylelint.config.js',
files: 'src/**/*.scss',
}),
new VisualizerPlugin({
filename: Path.join('..', '..', '..', '..', 'statistics.html'), // Relative to output.path
}),
],
resolve: {
extensions: ['.js', '.jsx', '.scss'],
modules: ['src', 'node_modules'],
},
});