-
Notifications
You must be signed in to change notification settings - Fork 20
/
webpack.config.js
103 lines (98 loc) · 2.18 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// required
const path = require( 'path' );
const webpack = require( 'webpack' );
const devMode = false; //process.env.NODE_ENV !== 'production';
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const OptimizeCssAssetsPlugin = require( 'optimize-css-assets-webpack-plugin' );
const FixStyleOnlyEntriesPlugin = require( 'webpack-fix-style-only-entries' );
const UglifyJsPlugin = require( 'uglifyjs-webpack-plugin' )
// extract sass
const extractSCSS = new MiniCssExtractPlugin( {
path: path.resolve( __dirname ),
filename: '[name].css'
} );
// fix separate styles
const fixSCSS = new FixStyleOnlyEntriesPlugin();
// scss config
const scssConfig = [
/* extract into separate scss files
{
loader: 'file-loader',
options: {
name: '[name].min.css',
context: './',
outputPath: '/',
publicPath: path.resolve( __dirname, 'css' ),
}
},
{
loader: 'extract-loader'
},
*/
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'sass-loader',
options: {
outputStyle: devMode ? 'expanded' : 'compressed'
}
}
];
// webpack plugins
const plugins = [
extractSCSS,
fixSCSS
];
// webpack config
module.exports = {
context: __dirname,
cache: false,
devtool: devMode ? 'inline-sourcemap' : false,
mode: devMode ? 'development' : 'production',
entry: {
'js/block-editor.min': './src/block-editor.js',
"css/block-editor.min": './src/block-editor.scss'
},
output: {
path: path.resolve( __dirname ),
filename: '[name].js',
/* filename: ( chunkData ) => {
return chunkData.chunk.name === 'css/block-editor.min' ? '[name].css': '[name].js';
}, */
},
watch: false,
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader'
}
]
},
{
test: /\.(sa|sc|c)ss$/,
exclude: /node_modules/,
use: scssConfig
},
]
},
optimization: {
// minimize in dev mode only
minimizer: ! devMode
? [
// enable the js minification plugin
new UglifyJsPlugin( {
cache: false,
parallel: true,
extractComments: false
} ),
// enable the css minification plugin
new OptimizeCssAssetsPlugin( { } )
]
: [ ]
},
plugins: plugins
};