Skip to content

Commit

Permalink
feat(build): optimization should only works with production build
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwa committed May 7, 2020
1 parent 203ea5c commit ba50cd3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
}
]
},
"eslintIgnore": [
"vue.config.js"
],
"browserslist": [
"> 1%",
"last 2 versions"
Expand Down
43 changes: 24 additions & 19 deletions vue.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* SHOULD read https://cli.vuejs.org first to modify these configurations.
*/
/* eslint-disable @typescript-eslint/no-var-requires */
const { externals, thirdPartiesUrls } = require('./third-parties.js')
const mocker = require('./mock.config.js')
const appVersion = require('./package.json').version
Expand Down Expand Up @@ -60,27 +59,33 @@ module.exports = {
args.commitHash = commitHash.value
return [args]
})

config.externals(externals)
})

/**
* extract and inline webpack runtime code
* @see https://webpack.js.org/configuration/optimization/#optimizationruntimechunk
* @further https://github.com/facebook/create-react-app/blob/v3.4.1/packages/react-dev-utils/InlineChunkHtmlPlugin.js
*/
config.optimization.runtimeChunk('single')
config.plugin('preload').tap(([args]) => {
args.fileBlacklist = (args.fileBlacklist || []).concat(
/runtime\..+\.js$/i
)
return [args]
/**
* extract and inline webpack runtime code
* @see https://webpack.js.org/configuration/optimization/#optimizationruntimechunk
* @further https://github.com/facebook/create-react-app/blob/v3.4.1/packages/react-dev-utils/InlineChunkHtmlPlugin.js
*/
config.optimization.runtimeChunk('single')
config.plugin('preload').tap(([args]) => {
args.fileBlacklist = (args.fileBlacklist || []).concat(
/runtime\..+\.js$/i
)
return [args]
})
config
.plugin('ScriptExtHtmlWebpackPlugin')
.before('preload')
.use(require('script-ext-html-webpack-plugin'), [
{ inline: /runtime\..+\.js$/i }
])

// config terser plugin options
config.optimization.minimizer('terser').tap(([options]) => {
options.terserOptions.compress.drop_console = true
return [options]
})
})
config
.plugin('ScriptExtHtmlWebpackPlugin')
.use(require('script-ext-html-webpack-plugin'), [
{ inline: /runtime\..+\.js$/i }
])

// webpack bundles analyzer
config.when(process.env.npm_config_report, config => {
Expand Down

0 comments on commit ba50cd3

Please sign in to comment.