-
Notifications
You must be signed in to change notification settings - Fork 230
/
webpack.config.js
106 lines (102 loc) · 2.43 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
const path = require('path')
const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const env = process.env.NODE_ENV
const production = env === 'production'
// render page
const page = (name) => {
return new HtmlWebpackPlugin({
inject: true,
template: path.join(__dirname, `./${name}.html`),
filename: path.join(__dirname, `./dist/${name}.html`)
})
}
const config = {
mode: production ? 'production' : 'development',
devtool: production ? 'source-map' : 'cheap-source-map',
entry: {
app: path.join(__dirname, './index.js')
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'js/[name].js'
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/style.css'
}),
new CleanWebpackPlugin(['./dist']),
new VueLoaderPlugin(),
new webpack.LoaderOptionsPlugin({ options: {} }),
new FriendlyErrorsWebpackPlugin(),
new ProgressBarPlugin(),
page('index')
],
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
stats: 'errors-only',
host: '0.0.0.0',
port: 8080
},
module: {
rules: [
{
test: /.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
enforce: 'pre'
},
{
test: /.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: { babelrc: true }
}
},
{
test: /\.vue$/,
loader: 'eslint-loader',
enforce: 'pre'
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.css$/,
loader: ['style-loader', 'css-loader']
},
{
test: /\.scss?$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
},
{
test: /\.(ttf|eot|svg)(\?.*)?$/,
loader: 'file-loader',
options: {
name: 'font/[name].[ext]'
}
}
]
},
resolve: {
extensions: ['.js', '.vue', '.json']
}
}
module.exports = config