-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.js
83 lines (77 loc) · 1.86 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
/**
* External dependencies
*/
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
const { BUILD_TARGET, NODE_ENV = 'development' } = process.env;
/** @type {import('webpack').Configuration} */
const config = ( module.exports = {
mode: NODE_ENV,
entry: './src/index.js',
output: {
path: __dirname + '/dist',
filename: 'app' + ( BUILD_TARGET ? '-' + BUILD_TARGET : '' ) + '.js',
publicPath: '/',
},
resolve: {
modules: [ 'src', 'node_modules' ],
alias: {
lodash: 'lodash-es',
},
},
module: {
rules: [
{
test: /\.js$/,
use: [ 'babel-loader' ],
exclude: /node_modules/,
},
],
},
} );
if ( 'production' === NODE_ENV ) {
config.module.rules.unshift( {
test: /\/action-types\.js$/,
use: {
loader: 'babel-loader',
options: {
plugins: [ 'minify-export-mirror' ],
},
},
include: __dirname + '/src/state',
} );
config.module.rules.push( {
test: /\.s?css$/,
use: ExtractTextPlugin.extract( {
use: [
'postcss-loader',
{
loader: 'sass-loader',
options: {
sassOptions: {
outputStyle: 'compressed',
},
},
},
],
} ),
} );
config.plugins = [
new ExtractTextPlugin( {
filename: './style.css',
disable: false,
allChunks: true,
} ),
];
} else if ( 'development' === NODE_ENV ) {
config.devtool = 'cheap-module-source-map';
config.entry = [ 'preact/debug', config.entry ];
config.resolve.alias.preact$ = 'preact/src/index.js';
config.resolve.alias[ 'preact/compat$' ] = 'preact/compat/src/index.js';
config.resolve.alias[ 'preact/debug$' ] = 'preact/debug/src/index.js';
config.resolve.alias[ 'preact/devtools$' ] = 'preact/devtools/src/index.js';
config.resolve.alias[ 'preact/hooks$' ] = 'preact/hooks/src/index.js';
config.module.rules.push( {
test: /\.s?css$/,
use: [ 'style-loader', 'css-loader', 'postcss-loader', 'sass-loader' ],
} );
}