Skip to content

Commit

Permalink
feat: add server nodeExternalsWhitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
imsunhao committed Mar 18, 2019
1 parent 2dbf2b7 commit 3505775
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
7 changes: 6 additions & 1 deletion @types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,12 @@ declare namespace build {
mode?: webpackMode
base?: Configuration
client?: Configuration
server?: Configuration
server?: serverConfig
}

interface serverConfig extends Configuration {
nodeExternalsWhitelist: any[]
webpack: Configuration
}

/**
Expand Down
70 changes: 39 additions & 31 deletions src/config/webpack.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,45 @@ export function getServerConfig(options: ConfigOptions.options) {
consola.fatal(
'getBaseConfig options.babelrc or options.webpack is undefined'
)
return process.exit(0)
return process.exit(1)
}
const server = options.webpack.server || {}
const mode = options.webpack.mode || 'production'
const isProd = mode === 'production'
return (merge as any)(
getBaseConfig(options),
{
name: 'server',
target: 'node',
entry: './src/entry-server.js',
output: {
libraryTarget: 'commonjs2'
if (options.webpack.server) {
const server = options.webpack.server.webpack || options.webpack.server || {}
const whitelist = [/\.css$/, /\?vue&type=style/].concat(options.webpack.server.nodeExternalsWhitelist || [])
const mode = options.webpack.mode || 'production'
const isProd = mode === 'production'
return (merge as any)(
getBaseConfig(options),
{
name: 'server',
target: 'node',
entry: './src/entry-server.js',
output: {
libraryTarget: 'commonjs2'
},
externals: nodeExternals({
// whitelist: /\.css$/
whitelist
}),
performance: {
maxEntrypointSize: 1024 * 1024 * 6,
maxAssetSize: 1024 * 1024 * 3,
hints: isProd ? 'warning' : false
},
plugins: [
new VueSSRServerPlugin(),
new webpack.DefinePlugin({
'process.env.VUE_ENV': '"server"'
})
]
},
externals: nodeExternals({
// whitelist: /\.css$/
whitelist: [/\.css$/, /\?vue&type=style/]
}),
performance: {
maxEntrypointSize: 1024 * 1024 * 6,
maxAssetSize: 1024 * 1024 * 3,
hints: isProd ? 'warning' : false
},
plugins: [
new VueSSRServerPlugin(),
new webpack.DefinePlugin({
'process.env.VUE_ENV': '"server"'
})
]
},
getStyle(options, { isServer: true }),
server
)
getStyle(options, { isServer: true }),
server
)
} else {
consola.fatal(
'getServerConfig options.webpack.server is undefined'
)
return process.exit(1)
}
}

0 comments on commit 3505775

Please sign in to comment.