-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config-helper.js
More file actions
executable file
·98 lines (87 loc) · 2.31 KB
/
webpack.config-helper.js
File metadata and controls
executable file
·98 lines (87 loc) · 2.31 KB
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
'use strict';
const Path = require('path');
const Webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ExtractSASS = new ExtractTextPlugin('styles/bundle.css');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
module.exports = (options) => {
const dest = Path.join(__dirname, 'dist');
let webpackConfig = {
mode: options.mode,
devtool: options.devtool,
entry: [
'./src/scripts/index'
],
output: {
path: dest,
filename: 'bundle.[hash].js'
},
plugins: [
new Webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(options.isProduction ? 'production' : 'development')
}
}),
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new CleanWebpackPlugin([dest])
],
module: {
rules: [{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015']
}
}
}, {
test: /\.(png|jp(e*)g|svg)$/,
use: {
loader: 'file-loader',
options: {
limit: 8000, // Convert images < 8kb to base64 strings
name: 'images/[hash]-[name].[ext]'
}
}
}]
}
};
if (options.isProduction) {
webpackConfig.entry = ['./src/scripts/index'];
webpackConfig.plugins.push(
new UglifyJSPlugin({
sourceMap: true,
}),
ExtractSASS
);
webpackConfig.module.rules.push({
test: /\.s?css/i,
use: ExtractSASS.extract(['css-loader?sourceMap=true&minimize=true', 'sass-loader'])
});
} else {
webpackConfig.plugins.push(
new Webpack.HotModuleReplacementPlugin()
);
webpackConfig.module.rules.push({
test: /\.s?css$/i,
use: ['style-loader', 'css-loader?sourceMap=true', 'sass-loader']
}, {
test: /\.js$/,
use: 'eslint-loader',
exclude: /node_modules/
});
webpackConfig.devServer = {
contentBase: dest,
hot: true,
port: options.port,
inline: true
};
}
return webpackConfig;
};