forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
76 lines (71 loc) · 2.13 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
'use strict';
const path = require('path');
const Autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const sass = require('node-sass');
/**
* If the "--production" command-line parameter is specified when invoking Heft, then the
* "production" function parameter will be true. You can use this to enable bundling optimizations.
*/
function createWebpackConfig({ production }) {
const webpackConfig = {
// Documentation: https://webpack.js.org/configuration/mode/
mode: production ? 'production' : 'development',
resolve: {
extensions: ['.js', '.jsx', '.json', '.css']
},
module: {
rules: [
{
test: /\.css$/,
exclude: /node_modules/,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
{
loader: 'css-loader',
options: {
importLoaders: 2,
modules: true
}
},
// Autoprefix CSS
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [new Autoprefixer()]
}
}
}
]
}
]
},
entry: {
app: path.join(__dirname, 'lib', 'index.js'),
// Put these libraries in a separate vendor bundle
vendor: ['react', 'react-dom']
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name]_[contenthash].js'
},
performance: {
// This specifies the bundle size limit that will trigger Webpack's warning saying:
// "The following entrypoint(s) combined asset size exceeds the recommended limit."
maxEntrypointSize: 250000,
maxAssetSize: 250000
},
devtool: production ? undefined : 'source-map',
plugins: [
// See here for documentation: https://github.com/jantimon/html-webpack-plugin
new HtmlWebpackPlugin({
template: 'assets/index.html'
})
]
};
return webpackConfig;
}
module.exports = createWebpackConfig;