-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
131 lines (122 loc) · 3.74 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const path = require('path');
const packageJson = require('./package.json');
const webpack = require('webpack');
const
HtmlWebpackPlugin = require('html-webpack-plugin'),
MiniCssExtractPlugin = require("mini-css-extract-plugin"),
CleanWebpackPlugin = require('clean-webpack-plugin'),
BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin,
webpackDevServerWaitpage = require('webpack-dev-server-waitpage');
const mode = process.env.NODE_ENV || 'development';
const node_modules = /[\\/]node_modules[\\/]/;
const PRODUCTION = mode === 'production';
const ANALYZE = process.env.ANALYZE;
module.exports = {
mode,
entry: './src/index.js',
output: {
filename: '[name].[hash].js',
path: path.resolve(__dirname, 'dist'),
publicPath : "/",
chunkFilename: "[name].[chunkhash].js",
devtoolModuleFilenameTemplate: info =>
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
},
devtool: ANALYZE ? 'source-map' : (PRODUCTION ? false : 'cheap-module-source-map'),
/*optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: node_modules, // Create a vendor chunk with all the imported node_modules in it
name: "vendor",
chunks: "all"
}
}
}
},*/
devServer: {
before: (app, server) => {
// Be sure to pass the server argument from the arguments
app.use(webpackDevServerWaitpage(server));
}
},
resolve: {
modules: [ path.resolve(__dirname, 'src'), 'node_modules' ]
},
plugins: [
new webpack.BannerPlugin({ // Add copyright notice
banner: (() => {
const packageJson = require('./package.json');
const author = (packageJson.author && packageJson.author.name) || packageJson.author;
return `Copyright (c) ${(new Date()).getFullYear()} ${author}. All Rights Reserved.`;
})(),
raw: false // wrap in a comment
}),
new MiniCssExtractPlugin({ // Minify and create one css file
filename: "assets/style.[contenthash].css"
}),
new HtmlWebpackPlugin({ // Create index.html file
title: packageJson.name,
cache: PRODUCTION,
template: 'src/index.ejs',
}),
new CleanWebpackPlugin(['dist'], { // Cleanup before each build
verbose: false,
dry: !PRODUCTION
}),
new BundleAnalyzerPlugin({
analyzerMode: ANALYZE ? 'static' : 'disabled',
openAnalyzer: false
}),
],
module: {
strictExportPresence: true,
rules: [
{ test: /\.(c|le)ss$/,
use: [
PRODUCTION ? MiniCssExtractPlugin.loader : "style-loader",
{
loader: "css-loader",
options: {
sourceMap: true,
modules: true,
importLoaders: 1,
localIdentName: '[local]__[hash:base64:5]',
}
},
{
loader: "less-loader",
options: {
sourceMap: true,
strictMath: true,
}
}
],
},
{ test: /\.(ico|gif|png|jpe?g|svg)$/,
use: {
loader: 'url-loader',
options: {
limit: 10 * 1024, // 10KB
name: '[path][name].[ext]',
context: 'src'
}
}
},
{ test: /\.js$/, exclude: node_modules,
use: [
'babel-loader',
{
loader: "eslint-loader",
options: {
formatter: require("eslint-friendly-formatter"),
failOnWarning: PRODUCTION,
failOnError: PRODUCTION,
emitWarning: !PRODUCTION
}
}
]
}
]
},
};