Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
103 lines (101 loc) · 2.51 KB
/
Copy pathwebpack.config.js
File metadata and controls
103 lines (101 loc) · 2.51 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
99
100
101
102
103
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin')
const isProduction = process.env.NODE_ENV === 'production'
const baseUrl = 'https://1001v.github.io/webpack-generator'
module.exports = {
entry: !isProduction ? './src/index.js' : ['@babel/polyfill', './src/index.js'],
mode: isProduction ? 'production' : 'development',
optimization: {
minimize: isProduction,
minimizer: [
new UglifyJsPlugin({ exclude: /vendor/ }),
new OptimizeCSSAssetsPlugin()
],
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all'
}
}
}
},
devtool: isProduction ? '' : 'source-map',
output: {
path: path.resolve(__dirname, isProduction ? 'docs': 'dist'),
filename: `[name]${isProduction ? '' : ''}.js`,
publicPath: isProduction ? baseUrl : ''
},
devServer: {
contentBase: './dist',
hot: true,
historyApiFallback: true
},
module: {
rules: [{
test: /\.js$/,
exclude: isProduction ? /node_modules/ : /.*/i,
use: {
loader: 'babel-loader'
}
}, {
test: /(\.scss|\.sass|\.css)$/,
use: [
'vue-style-loader',
isProduction ? MiniCssExtractPlugin.loader : {
loader: 'style-loader',
options: {
sourceMap: !isProduction
}
},
{
loader: 'css-loader',
options: {
sourceMap: !isProduction
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: !isProduction
}
},
{
loader: 'sass-loader',
options: {
sourceMap: !isProduction
}
}
]
}, {
test: /\.vue$/,
loader: 'vue-loader'
}],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new CleanWebpackPlugin(['dist', 'docs'], {
exclude: ['favicon.ico']
}),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: isProduction ? '404.html' : 'index.html',
hash: true,
favicon: './docs/favicon.ico'
}),
new BaseHrefWebpackPlugin({ baseHref: isProduction ? baseUrl : '/' }),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: 'vendor.css'
}),
new VueLoaderPlugin()
]
}