-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·118 lines (107 loc) · 3.81 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
112
113
114
115
116
var path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlwebpackPlugin = require('html-webpack-plugin');
const devMode = process.env.NODE_ENV !== 'production';
module.exports = {
mode: 'production',
devtool: 'cheap-module-eval-source-map', // 调试
entry: "./src/main.js", //模块的入口文件
output: {
filename: devMode ? "bundle.js" : "bundle.[hash].js", //打包后输出文件的文件名
publicPath: '/dist/',
path: __dirname + '/dist', //打包后的文件存放的地方;注:"__dirname"是node.js中的一个全局变量,它指向当前执行脚本所在的目录。
chunkFilename: '[name].chunk.js',
},
// devServer: {
// contentBase: "./dist",//本地服务器所加载的页面所在的目录
// historyApiFallback: true,//不跳转
// inline: true//实时刷新
// },
performance: {
hints: 'warning',
maxAssetSize: 30000000, // 整数类型(以字节为单位)
maxEntrypointSize: 50000000, // 整数类型(以字节为单位)
// assetFilter: function (assetFilename) {
// // 提供资源文件名的断言函数
// return assetFilename.endsWith('.jpg') || assetFilename.endsWith('.js')
// }
},
plugins: [
new MiniCssExtractPlugin({
filename: devMode ? '[name].css' : '[name].[hash].css',
chunkFilename: devMode ? '[id].css' : '[id].[hash].css',
}),
new VueLoaderPlugin(),
new HtmlwebpackPlugin({
filename: 'index.html',
template: 'index.ejs',
inject: false,
// minify: { // 压缩HTML文件
// removeComments: true, // 移除HTML中的注释
// collapseWhitespace: true, // 删除空白符与换行符
// minifyCSS: true// 压缩内联css
// },
}),
],
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
css: ExtractTextPlugin.extract({
use: 'css-loader',
fallback: 'vue-style-loader'
})
}
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/i,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
// {
// loader: MiniCssExtractPlugin.loader,
// options: {
// publicPath: '/dist/',
// }
// },
'css-loader',
],
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
},
// 图片,字体等文件的支持
{
test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
loader: 'url-loader',
options: {
limit: 10000,
name: 'images/[name].[hash:7].[ext]'
}
}
],
},
resolve: {
extensions: ['.js', '.vue', '.json', '.scss'],
alias: {
'@': path.resolve(__dirname,'./src'),
},
modules:['node_modules'],
// mainFields: ['browser', 'module', 'main']
},
};