forked from ElemeFE/page-skeleton-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.preview.config.js
64 lines (61 loc) · 1.54 KB
/
webpack.preview.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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const CleanPlugin = require('clean-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const PATH = {
app: __dirname,
build: __dirname
}
module.exports = {
mode: 'development',
entry: path.resolve(PATH.app, './index.js'),
output: {
filename: 'bundle.[hash:20].js',
path: path.join(PATH.build, 'dist')
},
module: {
rules: [{
test: /\.js$/,
use: {
loader: 'babel-loader'
}
}, {
test: /\.vue$/,
loader: 'vue-loader',
options: {
extractCSS: true
}
}, {
test: /\.css$/,
use: [
process.env.NODE_ENV === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
"css-loader"
]
}, {
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000
}
}]
},
plugins: [
new VueLoaderPlugin(),
new CleanPlugin('dist'),
new HtmlWebpackPlugin({
template: path.resolve(PATH.app, './index.html'),
filename: path.resolve(PATH.build, './dist/index.html'),
inject: true
})
]
}
if (process.env.NODE_ENV === 'production') {
module.exports.mode = 'production'
module.exports.plugins.push(new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: '[name].[hash].css',
chunkFilename: '[id].[hash].css'
}))
}