Skip to content

Commit b622c59

Browse files
committed
more externals edits
1 parent ca4d352 commit b622c59

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

en/build-config.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The server config is meant for generating the server bundle that will be passed
88

99
``` js
1010
const merge = require('webpack-merge')
11+
const nodeExternals = require('wepback-node-externals')
1112
const baseConfig = require('./webpack.base.config.js')
1213
const VueSSRServerPlugin = require('vue-server-renderer/server-plugin')
1314

@@ -29,21 +30,14 @@ module.exports = merge(baseConfig, {
2930
},
3031

3132
// https://webpack.js.org/configuration/externals/#function
33+
// https://github.com/liady/webpack-node-externals
3234
// Externalize app dependencies. This makes the server build much faster
3335
// and generates a smaller bundle file.
34-
externals: (context, request, cb) => {
35-
// a module is externalized if...
36-
if (
37-
// it's inside node_modules
38-
/node_modules/.test(context) &&
39-
// ... and not a CSS file, in case we need to import CSS from a dependency
40-
!/\.(css|styl(us)?|less|sass|scss)(\?[^.]+)?$/.test(request)
41-
) {
42-
cb(null, `commonjs ${request}`)
43-
} else {
44-
cb()
45-
}
46-
},
36+
externals: nodeExternals({
37+
// do not externalize dependencies that need to be processed by webpack.
38+
// you can add more file types here e.g. raw *.vue files
39+
whitelist: /\.css$/
40+
}),
4741

4842
// This is the plugin that turns the entire output of the server build
4943
// into a single JSON file. The default file name will be

en/css.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,16 @@ A few things to take note when importing CSS from an NPM dependency:
9191
module.exports = {
9292
// ...
9393
plugins: [
94-
// extract files in `node_modules` into a vendor chunk for better caching
94+
// it is common to extract deps into a vendor chunk for better caching.
9595
new webpack.optimize.CommonsChunkPlugin({
9696
name: 'vendor',
9797
minChunks: function (module) {
98-
// The extraction logic is actually the same as `externals`
99-
// in the server config. We can extract the common logic into
100-
// a helper.
98+
// a module is extracted into the vendor chunk when...
10199
return (
102100
// if it's inside node_modules
103101
/node_modules/.test(module.context) &&
104102
// do not externalize if the request is a CSS file
105-
!/\.(css|styl(us)?|less|sass|scss)(\?[^.]+)?$/.test(module.request)
103+
!/\.css$/.test(module.request)
106104
)
107105
}
108106
}),

0 commit comments

Comments
 (0)