This repository has been archived by the owner on May 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
111 lines (103 loc) · 2.8 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
const { VueLoaderPlugin } = require('vue-loader')
const nodeSassMagicImporter = require('node-sass-magic-importer')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const env = process.env.NODE_ENV
const minify = env === 'production'
const sourceMap = env === 'development'
const config = {
entry: path.join(__dirname, 'src', 'index.js'),
mode: env,
output: {
publicPath: '/'
},
optimization: {
splitChunks: {
// Must be specified for HtmlWebpackPlugin to work correctly
// See: https://github.com/jantimon/html-webpack-plugin/issues/882
chunks: 'all'
},
},
devtool: sourceMap ? 'cheap-module-eval-source-map' : undefined,
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [path.join(__dirname, 'src')],
exclude: /node_modules/
},
{
test: /\.(css|scss)$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
options: {
sourceMap
}
},
{
loader: 'sass-loader',
options: {
importer: nodeSassMagicImporter(),
sourceMap
}
}
]
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader'
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader'
}
]
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
},
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
filename: path.join(__dirname, 'dist', 'index.html'),
template: path.join(__dirname, 'static', 'index.html'),
inject: true,
minify: minify ? {
// More options: https://github.com/kangax/html-minifier#options-quick-reference
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
} : false
})
]
}
if (minify) {
config.optimization.minimizer = [
new OptimizeCSSAssetsPlugin(),
// Enabled by default in production mode if the 'minimizer' option isn't overridden
new UglifyJsPlugin({
cache: true,
parallel: true
})
]
}
if (env !== 'development') {
config.plugins.push(new MiniCssExtractPlugin())
const sassLoader = config.module.rules.find(({ test }) => test.test('.scss'))
// Replace the 'vue-style-loader' with the MiniCssExtractPlugin loader
sassLoader.use[0] = MiniCssExtractPlugin.loader
}
module.exports = config