-
Notifications
You must be signed in to change notification settings - Fork 64
/
webpack.config.js
83 lines (73 loc) · 1.93 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
const { merge } = require( 'webpack-merge' );
const common = require( './.dev/config/webpack.common.js' );
const BrowserSyncPlugin = require( 'browser-sync-webpack-plugin' );
const CssMinimizerPlugin = require( 'css-minimizer-webpack-plugin' );
const RtlCssPlugin = require( 'rtlcss-webpack-plugin' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const settings = require( './.dev/config/webpack.settings.js' );
const isProduction = 'production' === process.env.NODE_ENV;
if ( isProduction ) {
module.exports = merge( common, {
mode: 'production',
optimization: {
minimize: true,
},
} );
return;
}
const config = merge(
common,
{
devtool: 'inline-cheap-module-source-map',
mode: 'development',
optimization: {
minimizer: [
`...`,
new CssMinimizerPlugin(),
],
},
plugins: [
new BrowserSyncPlugin(
{
files: settings.BrowserSyncConfig.files,
host: settings.BrowserSyncConfig.host,
open: settings.BrowserSyncConfig.open,
port: settings.BrowserSyncConfig.port,
proxy: settings.BrowserSyncConfig.proxy,
},
{
injectCss: true,
reload: false,
}
),
],
}
);
let flags = [];
if ( undefined !== process.argv[ 5 ] ) {
flags = process.argv[ 5 ].replace( '--', '' ).split( ',' );
}
// Generate the RTL files when running `npm run start` and a --rtl flag is set
if ( flags.includes( 'rtl' ) ) {
config.plugins.push(
new RtlCssPlugin( { filename: 'css/[name]-rtl.css' } ),
);
if ( flags.includes( 'min' ) ) {
config.plugins.push(
new MiniCssExtractPlugin( {
chunkFilename: '[id].css',
filename: 'css/[name]-rtl.min.css',
} ),
);
}
}
// Minify both the standard .css file and the -rtl.css files when running `npm run start` and a --min flag is set
if ( flags.includes( 'min' ) ) {
config.plugins.push(
new MiniCssExtractPlugin( {
chunkFilename: '[id].css',
filename: 'css/[name].min.css',
} ),
);
}
module.exports = config;