-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.common.js
117 lines (114 loc) · 3.11 KB
/
webpack.common.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
117
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const { resolve, getEntries, getHtmlWebpackPlugins } = require('./webpack.until.js')
const cfg = require('./webpack.cfg.js')
let otherEntries = {}
// 公共css文件入口
if (cfg.commonCss && cfg.commonCss.entry) {
otherEntries.common_css = cfg.commonCss.entry
}
module.exports = (env, argv) => {
console.log(argv.mode, '========================')
return {
entry: {
...otherEntries,
...getEntries(argv)
},
resolve: { //导入的时候不用写拓展名
extensions: ['.js', '.vue', '.json'],
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
},
output: {
path: resolve('dist'),
filename: `${cfg.build.assetsSubDirectory}/js/[name].[chunkhash].js`,
// chunkFilename: `${cfg.build.assetsSubDirectory}/js/[name].[chunkhash].js`,
publicPath: argv.mode === 'production'
? cfg.build.assetsPublicPath
: cfg.dev.assetsPublicPath
},
module: {
rules: [
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: {
}
}]
},
{
test: /\.pug$/,
use: [
'html-loader',
// 'raw-loader',
{
loader: 'pug-html-loader',
options: {
data: { aa: 2222 } // set of data to pass to the pug render.
}
}]
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
}
},
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
}
]
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
exclude: /(node_modules|bower_components)/,
use: [
{
loader: 'url-loader',
options: {
limit: 8 * 1024,
name: `${cfg.build.assetsSubDirectory}/img/[name]-[hash:7].[ext]`,
}
}
]
},
{
test: /\.(woff|svg|eot|ttf)\??.*$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'url-loader',
options: {
name: `${cfg.build.assetsSubDirectory}/font/[name].[hash:7].[ext]`,
limit: 8192
}
}
},
]
},
plugins: [
new VueLoaderPlugin(),
// new webpack.HotModuleReplacementPlugin(), // 启用 热更新
...getHtmlWebpackPlugins(argv),
new webpack.LoaderOptionsPlugin({
options: {
htmlLoader: {
root: path.resolve(__dirname, './src') // 对于html中的绝对路径进行定位, /assets/a.jpg => path.resolve(__dirname, '/src/assets/a.jpg')
}
}
}),
],
}
}