From 74eb5a6302afc498cddf4e9abeaf04b1054ac5db Mon Sep 17 00:00:00 2001 From: Lajos Veres Date: Sat, 29 Sep 2018 21:05:20 +0100 Subject: [PATCH 1/8] * Typofixes - https://github.com/vlajos/misspell-fixer (#4013) --- examples/custom-layouts/layouts/error.vue | 2 +- examples/dynamic-layouts/layouts/error.vue | 2 +- examples/typescript/store/modules/people.ts | 2 +- examples/web-worker/pages/index.vue | 4 ++-- lib/app/client.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/custom-layouts/layouts/error.vue b/examples/custom-layouts/layouts/error.vue index 3b4dc0ffc7..126edd0af2 100644 --- a/examples/custom-layouts/layouts/error.vue +++ b/examples/custom-layouts/layouts/error.vue @@ -1,7 +1,7 @@ diff --git a/examples/dynamic-layouts/layouts/error.vue b/examples/dynamic-layouts/layouts/error.vue index 61f4ddcebd..aa064f32ec 100644 --- a/examples/dynamic-layouts/layouts/error.vue +++ b/examples/dynamic-layouts/layouts/error.vue @@ -1,7 +1,7 @@ diff --git a/examples/typescript/store/modules/people.ts b/examples/typescript/store/modules/people.ts index e73da3a343..25f3fb6f4a 100644 --- a/examples/typescript/store/modules/people.ts +++ b/examples/typescript/store/modules/people.ts @@ -29,7 +29,7 @@ export interface Person { gender: string ip_address: string avatar: string - addres: PersonAddress + address: PersonAddress } export interface State { diff --git a/examples/web-worker/pages/index.vue b/examples/web-worker/pages/index.vue index ce7cc49ce3..eb307006c3 100644 --- a/examples/web-worker/pages/index.vue +++ b/examples/web-worker/pages/index.vue @@ -82,7 +82,7 @@ export default { if (worker) worker.postMessage({ hello: 'world' }) else this.notification = 'No more test workers available' }, - long (miliseconds) { + long (milliseconds) { let worker = this.workers.shift() if (worker) { @@ -96,7 +96,7 @@ export default { worker = this.longRunningWorkers[ this.longIndex++ % this.longRunningWorkers.length] } - worker.postMessage({ action: 'expensive', time: miliseconds }) + worker.postMessage({ action: 'expensive', time: milliseconds }) }, freeWorker () { // we can't really free a worker, we can only terminate it and create a new diff --git a/lib/app/client.js b/lib/app/client.js index c8c52c3122..e9a5209bd1 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -665,7 +665,7 @@ async function mountApp(__app) { if (!path) { normalizeComponents(router.currentRoute, router.currentRoute) showNextPage.call(_app, router.currentRoute) - // Dont call fixPrepatch.call(_app, router.currentRoute, router.currentRoute) since it's first render + // Don't call fixPrepatch.call(_app, router.currentRoute, router.currentRoute) since it's first render mount() return } From f08cc76055154b9757c0c32056a8dd219bbe7f30 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Sat, 29 Sep 2018 21:18:33 +0100 Subject: [PATCH 2/8] exmaple: remove unnecessary transpile for vuetify --- examples/with-vuetify/nuxt.config.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/with-vuetify/nuxt.config.js b/examples/with-vuetify/nuxt.config.js index 050a1d9e14..90677abf77 100644 --- a/examples/with-vuetify/nuxt.config.js +++ b/examples/with-vuetify/nuxt.config.js @@ -14,8 +14,7 @@ export default { }, build: { - extractCSS: true, - transpile: [/^vuetify/] + extractCSS: true }, /* ** Load Vuetify into the app From 1bf6385d484db13344aff20150f5cdd5ca8d5312 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Sat, 29 Sep 2018 21:40:04 +0100 Subject: [PATCH 3/8] fix: wrong extension for dev mode css file --- lib/common/nuxt.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/nuxt.config.js b/lib/common/nuxt.config.js index 97004e3ec4..8cb771e512 100644 --- a/lib/common/nuxt.config.js +++ b/lib/common/nuxt.config.js @@ -55,7 +55,7 @@ export default { // { isDev, isClient, isServer } app: ({ isDev }) => isDev ? '[name].js' : '[chunkhash].js', chunk: ({ isDev }) => isDev ? '[name].js' : '[chunkhash].js', - css: ({ isDev }) => isDev ? '[name].js' : '[contenthash].css', + css: ({ isDev }) => isDev ? '[name].css' : '[contenthash].css', img: ({ isDev }) => isDev ? '[path][name].[ext]' : 'img/[hash:7].[ext]', font: ({ isDev }) => isDev ? '[path][name].[ext]' : 'fonts/[hash:7].[ext]', video: ({ isDev }) => isDev ? '[path][name].[ext]' : 'videos/[hash:7].[ext]' From 8f06a187db2ef9124926eb942498a8c1b9578677 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 30 Sep 2018 19:39:06 +0330 Subject: [PATCH 4/8] feat(builder): allow to customize or disable minimizer plugins (#4018) * feat(builder): allow to customize or disable minimizer plugins * feat: support optimization.minimize https://webpack.js.org/configuration/optimization/#optimization-minimize * fix typos --- lib/builder/webpack/client.js | 41 ++++++++++++++++++++--------------- lib/common/nuxt.config.js | 4 ++++ lib/common/options.js | 10 +++++++++ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/lib/builder/webpack/client.js b/lib/builder/webpack/client.js index 4ed5549aaf..0f0cc9bc91 100644 --- a/lib/builder/webpack/client.js +++ b/lib/builder/webpack/client.js @@ -99,31 +99,36 @@ export default class WebpackClientConfig extends WebpackBaseConfig { extendConfig() { const config = super.extendConfig(...arguments) - if (!this.options.dev && !config.optimization.minimizer) { + // Add minimizer plugins + if (config.optimization.minimize && config.optimization.minimizer === undefined) { config.optimization.minimizer = [] // https://github.com/webpack-contrib/terser-webpack-plugin - const terserJsPlugin = new TerserWebpackPlugin({ - parallel: true, - cache: this.options.build.cache, - sourceMap: config.devtool && /source-?map/.test(config.devtool), - extractComments: { - filename: 'LICENSES' - }, - terserOptions: { - output: { - comments: /^\**!|@preserve|@license|@cc_on/ - } - } - }) - config.optimization.minimizer.push(terserJsPlugin) + if (this.options.build.terser) { + config.optimization.minimizer.push( + new TerserWebpackPlugin(Object.assign({ + parallel: true, + cache: this.options.build.cache, + sourceMap: config.devtool && /source-?map/.test(config.devtool), + extractComments: { + filename: 'LICENSES' + }, + terserOptions: { + output: { + comments: /^\**!|@preserve|@license|@cc_on/ + } + } + }, this.options.build.terser)) + ) + } // https://github.com/NMFR/optimize-css-assets-webpack-plugin // https://github.com/webpack-contrib/mini-css-extract-plugin#minimizing-for-production // TODO: Remove OptimizeCSSAssetsPlugin when upgrading to webpack 5 - if (this.options.build.extractCSS) { - const optimizeCSSPlugin = new OptimizeCSSAssetsPlugin({}) - config.optimization.minimizer.push(optimizeCSSPlugin) + if (this.options.build.optimizeCSS) { + config.optimization.minimizer.push( + new OptimizeCSSAssetsPlugin(Object.assign({}, this.options.build.optimizeCSS)) + ) } } diff --git a/lib/common/nuxt.config.js b/lib/common/nuxt.config.js index 8cb771e512..cefbb2051d 100644 --- a/lib/common/nuxt.config.js +++ b/lib/common/nuxt.config.js @@ -87,8 +87,12 @@ export default { }, styleResources: {}, plugins: [], + terser: {}, + optimizeCSS: undefined, optimization: { runtimeChunk: 'single', + minimize: undefined, + minimizer: undefined, splitChunks: { chunks: 'all', automaticNameDelimiter: '.', diff --git a/lib/common/options.js b/lib/common/options.js index 86749abad5..f2f5c56e6f 100644 --- a/lib/common/options.js +++ b/lib/common/options.js @@ -239,6 +239,16 @@ Options.from = function (_options) { options.build.extractCSS = false } + // Enable minimize for production builds + if (options.build.optimization.minimize === undefined) { + options.build.optimization.minimize = !options.dev + } + + // Enable optimizeCSS only when extractCSS is enabled + if (options.build.optimizeCSS === undefined) { + options.build.optimizeCSS = options.build.extractCSS ? {} : false + } + const loaders = options.build.loaders const vueLoader = loaders.vue if (vueLoader.productionMode === undefined) { From 0393bf781cef954ebf88703782a78435eb52e207 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Sun, 30 Sep 2018 17:11:20 +0100 Subject: [PATCH 5/8] feat: use understandable file names for analyze mode (#4014) * feat: use understandable file names for analyze mode * test: asset name for analyze mode * refactor: add warning message for analyze mode * refactor: move analyze warning to builder * test: analyze warning message --- lib/builder/builder.js | 9 +++++++++ lib/builder/webpack/client.js | 10 ++++++++++ test/fixtures/with-config/with-config.test.js | 18 ++++++++++++------ test/unit/with-config.test.js | 5 +++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/builder/builder.js b/lib/builder/builder.js index b1190f638a..bafaccfa7d 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -59,6 +59,15 @@ export default class Builder { this.mfs = new MFS() } + if (this.options.build.analyze) { + this.nuxt.hook('build:done', () => { + consola.warn({ + message: 'Notice: Please do not deploy bundles built with analyze mode, it\'s only for analyzing purpose.', + badge: true + }) + }) + } + // if(!this.options.dev) { // TODO: enable again when unsafe concern resolved.(common/options.js:42) // this.nuxt.hook('build:done', () => this.generateConfig()) diff --git a/lib/builder/webpack/client.js b/lib/builder/webpack/client.js index 0f0cc9bc91..775862ff36 100644 --- a/lib/builder/webpack/client.js +++ b/lib/builder/webpack/client.js @@ -15,6 +15,16 @@ export default class WebpackClientConfig extends WebpackBaseConfig { super(builder, { name: 'client', isServer: false }) } + getFileName(...args) { + if (this.options.build.analyze) { + const key = args[0] + if (['app', 'chunk'].includes(key)) { + return '[name].js' + } + } + return super.getFileName(...args) + } + env() { return Object.assign(super.env(), { 'process.env.VUE_ENV': JSON.stringify('client'), diff --git a/test/fixtures/with-config/with-config.test.js b/test/fixtures/with-config/with-config.test.js index 3de1cbe586..d16e0f0a1e 100644 --- a/test/fixtures/with-config/with-config.test.js +++ b/test/fixtures/with-config/with-config.test.js @@ -14,13 +14,19 @@ const hooks = [ describe('with-config', () => { buildFixture('with-config', () => { - expect(consola.warn).toHaveBeenCalledTimes(1) + expect(consola.warn).toHaveBeenCalledTimes(2) expect(consola.fatal).toHaveBeenCalledTimes(0) - expect(consola.warn.mock.calls[0]).toMatchObject([{ - message: 'Found 2 plugins that match the configuration, suggest to specify extension:', - additional: expect.stringContaining('plugins/test.json'), - badge: true - }]) + expect(consola.warn.mock.calls).toMatchObject([ + [{ + message: 'Found 2 plugins that match the configuration, suggest to specify extension:', + additional: expect.stringContaining('plugins/test.json'), + badge: true + }], + [{ + message: 'Notice: Please do not deploy bundles built with analyze mode, it\'s only for analyzing purpose.', + badge: true + }] + ]) expect(customCompressionMiddlewareFunctionName).toBe('damn') }, hooks) }) diff --git a/test/unit/with-config.test.js b/test/unit/with-config.test.js index 76659d6372..2ad6726adf 100644 --- a/test/unit/with-config.test.js +++ b/test/unit/with-config.test.js @@ -19,6 +19,11 @@ describe('with-config', () => { expect(html.includes('

I have custom configurations

')).toBe(true) }) + test('/ (asset name for analyze mode)', async () => { + const { html } = await nuxt.renderRoute('/') + expect(html).toContain('