/
webpack.prod.js
86 lines (84 loc) · 1.96 KB
/
webpack.prod.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
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');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const root = path.resolve(path.dirname(__dirname));
module.exports = {
mode: 'production',
entry: path.resolve(root, 'src', 'main.js'),
output: {
path: path.resolve(root, 'dist'),
filename: '[name].[chunkhash:8].js',
},
optimization: {
minimize: true,
},
devtool: 'source-map',
resolve: {
alias: {
vue$: 'vue/dist/vue.runtime.min.js',
'@': path.resolve(root, 'src', 'components'),
},
extensions: ['*', '.js', '.vue', '.json'],
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.js$/,
loader: 'babel-loader',
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(eot|woff|woff2|ttf)$/i,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[contenthash:8].[ext]',
},
},
],
},
{
test: /\.(png|jpg|gif|svg)$/i,
use: [
{
loader: 'url-loader',
options: {
name: '[name].[contenthash:8].[ext]',
limit: 8192,
},
},
],
},
{
test: /\.html$/,
loader: 'html-loader',
},
],
},
plugins: [
new CleanWebpackPlugin(),
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(root, 'src', 'index.html'),
inject: true,
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash:8].css',
}),
],
};