Skip to content

Commit 6017ed5

Browse files
committed
chore: adjust example config
1 parent a9944ff commit 6017ed5

File tree

2 files changed

+79
-69
lines changed

2 files changed

+79
-69
lines changed

Diff for: example/webpack.config.js

+78-68
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,87 @@ const path = require('path')
22
const VueLoaderPlugin = require('../dist/plugin')
33
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
44

5-
module.exports = {
6-
mode: 'development',
7-
entry: path.resolve(__dirname, './main.js'),
8-
devtool: 'cheap-module-eval-source-map',
9-
output: {
10-
path: path.resolve(__dirname, 'dist'),
11-
filename: 'bundle.js',
12-
publicPath: '/dist/'
13-
},
14-
module: {
15-
rules: [
16-
{
17-
test: /\.vue$/,
18-
loader: 'vue-loader'
19-
},
20-
{
21-
test: /\.png$/,
22-
use: [
23-
{
24-
loader: 'url-loader',
25-
options: {
26-
limit: 8192
27-
}
28-
}
29-
]
30-
},
31-
{
32-
test: /\.css$/,
33-
use: [
34-
{
35-
loader: MiniCssExtractPlugin.loader,
36-
options: {
37-
hmr: process.env.NODE_ENV !== 'production'
5+
module.exports = (env = {}) => {
6+
const isProd = env.prod
7+
const minimize = isProd && !env.noMinimize
8+
const babel = isProd && !env.noBabel
9+
10+
return {
11+
mode: isProd ? 'production' : 'development',
12+
entry: path.resolve(__dirname, './main.js'),
13+
devtool: isProd ? 'source-map' : 'cheap-module-eval-source-map',
14+
output: {
15+
path: path.resolve(__dirname, 'dist'),
16+
filename: 'bundle.js',
17+
publicPath: '/dist/'
18+
},
19+
module: {
20+
rules: [
21+
{
22+
test: /\.vue$/,
23+
loader: 'vue-loader'
24+
},
25+
{
26+
test: /\.png$/,
27+
use: [
28+
{
29+
loader: 'url-loader',
30+
options: {
31+
limit: 8192
32+
}
3833
}
39-
},
40-
'css-loader'
41-
]
42-
},
43-
{
44-
test: /\.js$/,
45-
use: {
46-
loader: 'babel-loader',
47-
options: {
48-
presets: ['@babel/preset-env']
49-
}
34+
]
35+
},
36+
{
37+
test: /\.css$/,
38+
use: [
39+
{
40+
loader: MiniCssExtractPlugin.loader,
41+
options: {
42+
hmr: !isProd
43+
}
44+
},
45+
'css-loader'
46+
]
47+
},
48+
{
49+
test: /\.js$/,
50+
use: babel
51+
? {
52+
loader: 'babel-loader',
53+
options: {
54+
presets: ['@babel/preset-env']
55+
}
56+
}
57+
: [
58+
/* skip babel */
59+
]
60+
},
61+
// target <docs> custom blocks
62+
{
63+
resourceQuery: /blockType=docs/,
64+
loader: require.resolve('./docs-loader')
5065
}
51-
},
52-
// target <docs> custom blocks
53-
{
54-
resourceQuery: /blockType=docs/,
55-
loader: require.resolve('./docs-loader')
66+
]
67+
},
68+
plugins: [
69+
new VueLoaderPlugin(),
70+
new MiniCssExtractPlugin({
71+
filename: '[name].css'
72+
})
73+
],
74+
optimization: {
75+
minimize
76+
},
77+
devServer: {
78+
stats: 'minimal',
79+
contentBase: __dirname,
80+
overlay: true
81+
},
82+
resolveLoader: {
83+
alias: {
84+
'vue-loader': require.resolve('../')
5685
}
57-
]
58-
},
59-
plugins: [
60-
new VueLoaderPlugin(),
61-
new MiniCssExtractPlugin({
62-
filename: '[name].css'
63-
})
64-
],
65-
devServer: {
66-
stats: 'minimal',
67-
contentBase: __dirname,
68-
overlay: true
69-
},
70-
resolveLoader: {
71-
alias: {
72-
'vue-loader': require.resolve('../')
7386
}
74-
},
75-
optimization: {
76-
// minimize: false
7787
}
7888
}

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dev": "tsc --watch",
1313
"build": "tsc",
1414
"dev-example": "webpack-dev-server --config example/webpack.config.js --inline --hot",
15-
"build-example": "webpack --config example/webpack.config.js --mode=production --devtool=source-map",
15+
"build-example": "webpack --config example/webpack.config.js --env.prod",
1616
"lint": "prettier --write --parser typescript \"src/**/*.ts\""
1717
},
1818
"gitHooks": {

0 commit comments

Comments
 (0)