-
Notifications
You must be signed in to change notification settings - Fork 360
/
webpack.config.js
84 lines (78 loc) · 1.99 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
var webpack = require('webpack');
var path = require('path');
var htmlWebpackPlugin = require('html-webpack-plugin');
// var extractTextPlugin = require('extract-text-webpack-plugin'); // separate css
var miniCssExtractPlugin = require('mini-css-extract-plugin')
var copyWebpackPlugin = require('copy-webpack-plugin');
var vueLoaderPlugin = require('vue-loader/lib/plugin')
var webpackConfig = module.exports = {}; // init object
var isProduction = process.env.NODE_ENV === 'production'; // production environment
// input
webpackConfig.entry = {
app: './src/app.js', // main
};
// output
webpackConfig.output = {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
filename: isProduction ? '[name].[hash].js' : '[name].js',
};
// loader
webpackConfig.module = {
rules: [
{
test: /\.css$/,
use: [
miniCssExtractPlugin.loader,
"css-loader"
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.(eot(|\?v=.*)|woff(|\?v=.*)|woff2(|\?v=.*)|ttf(|\?v=.*)|svg(|\?v=.*))$/,
loader: 'file-loader',
options: { name: 'fonts/[name].[ext]' },
},
{
test: /\.(png|jpg|gif)$/,
loader: 'file-loader',
},
]
};
webpackConfig.plugins = [
// make index.html
new htmlWebpackPlugin({
template: './src/index.html'
}),
// separate css file
new miniCssExtractPlugin({
filename: isProduction ? 'app.[hash].css' : 'app.css',
// disable: false,
// allChunks: true
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new copyWebpackPlugin([
{ from: 'src/mock/api.json', to: 'mock' },
{ context: 'src/images', from: '*', to: path.join(__dirname, 'dist', 'images') }
]),
new vueLoaderPlugin()
];
if (!isProduction) {
webpackConfig.devServer = {
contentBase: path.resolve(__dirname, 'dist'),
compress: true,
historyApiFallback: true,
};
}