-
Notifications
You must be signed in to change notification settings - Fork 916
/
Copy pathwebpack.config.js
138 lines (134 loc) · 3.79 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const path = require('path')
const webpack = require('webpack')
const VueLoaderPlugin = require('../dist/plugin').default
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = (env = {}) => {
const isProd = env.prod
const isSSR = env.ssr
/**
* Some notes regarding config for the server build of an SSR app:
* 1. target: 'node'
* 2. output.libraryTarget: 'commonjs' (so the exported app can be required)
* 3. externals: this is mostly for faster builds.
* - externalize @vue/* deps via commonjs require()
* - externalize client side deps that are never used on the server, e.g.
* ones that are only used in onMounted() to empty modules
* 4. If using cache-loader or any other forms of cache, make sure the cache
* key takes client vs. server builds into account!
*/
const genConfig = (isServerBuild = false) => {
const minimize = isProd && !isServerBuild && !env.noMinimize
return {
mode: isProd ? 'production' : 'development',
entry: path.resolve(__dirname, './main.js'),
target: isServerBuild ? 'node' : 'web',
devtool: 'source-map',
resolve: {
extensions: ['.js', '.ts'],
alias: process.env.WEBPACK4
? {
webpack: 'webpack4',
}
: {},
},
output: {
path: path.resolve(
__dirname,
isSSR ? (isServerBuild ? 'dist-ssr/server' : 'dist-ssr/dist') : 'dist'
),
filename: '[name].js',
publicPath: '/dist/',
libraryTarget: isServerBuild ? 'commonjs' : undefined,
},
externals: isServerBuild
? [
(ctx, request, cb) => {
if (/^@vue/.test(request)) {
return cb(null, 'commonjs ' + request)
}
cb()
},
]
: undefined,
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
// reactivityTransform: true,
compilerOptions: {
isCustomElement: (tag) => tag.startsWith('custom-'),
},
},
},
{
test: /\.png$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.ts$/,
use: [
{
loader: process.env.WEBPACK4
? require.resolve('ts-loader')
: require.resolve('ts-loader-v9'),
options: {
transpileOnly: true,
appendTsSuffixTo: [/\.vue$/],
},
},
],
},
// target <docs> custom blocks
{
resourceQuery: /blockType=docs/,
loader: require.resolve('./docs-loader'),
},
],
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new webpack.DefinePlugin({
__IS_SSR__: !!isSSR,
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: false,
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false,
}),
],
optimization: {
minimize,
},
devServer: {
hot: true,
stats: 'minimal',
contentBase: __dirname,
overlay: true,
},
resolveLoader: {
alias: {
'vue-loader': require.resolve('../'),
},
},
}
}
if (!isSSR) {
return genConfig()
} else {
return [genConfig(), genConfig(true)]
}
}