nuxt-build-optimisations
Advanced tools
Comparing version
@@ -6,3 +6,2 @@ import { Module } from '@nuxt/types'; | ||
interface FeatureFlags { | ||
babelNotDead: boolean; | ||
esbuildLoader: boolean; | ||
@@ -9,0 +8,0 @@ esbuildMinifier: boolean; |
@@ -1910,4 +1910,4 @@ 'use strict'; | ||
const webpackOptimiser = ({config, env}) => { | ||
if (!config.resolve || !config.output || !config.optimization) { | ||
const webpackOptimiser = ({config, env, options}) => { | ||
if (!config.resolve || !config.output || !config.optimization || !options.features.webpackOptimisations) { | ||
return; | ||
@@ -1927,12 +1927,4 @@ } | ||
const babelOptimiser = ({nuxtOptions}) => { | ||
nuxtOptions.build.babel.presets = ({isServer}, [, options]) => { | ||
if (!isServer) { | ||
options.targets = "> 0.5%, last 2 versions, Firefox ESR, not dead"; | ||
} | ||
}; | ||
}; | ||
const imageOptimiser = ({config, env}) => { | ||
if (!config.module || !env.isDev) { | ||
const imageOptimiser = ({config, env, options}) => { | ||
if (!config.module || !env.isDev || !options.features.imageFileLoader) { | ||
return; | ||
@@ -2164,3 +2156,3 @@ } | ||
} | ||
if (env.isDev || options.profile !== "safe") { | ||
if (options.features.esbuildLoader && (env.isDev || options.profile !== "safe")) { | ||
let cacheLoader = []; | ||
@@ -2209,3 +2201,3 @@ config.module.rules.forEach((rule, ruleKey) => { | ||
} | ||
if (!env.isDev && options.profile !== "safe" && nuxtOptions.build.optimization) { | ||
if (options.features.esbuildMinifier && !env.isDev && options.profile !== "safe" && nuxtOptions.build.optimization) { | ||
nuxtOptions.build.optimization.minimize = true; | ||
@@ -2231,2 +2223,8 @@ nuxtOptions.build.optimization.minimizer = [ | ||
target: "es2015" | ||
}, | ||
features: { | ||
esbuildLoader: true, | ||
esbuildMinifier: true, | ||
imageFileLoader: true, | ||
webpackOptimisations: true | ||
} | ||
@@ -2251,3 +2249,2 @@ }; | ||
webpackOptimiser, | ||
babelOptimiser, | ||
imageOptimiser, | ||
@@ -2254,0 +2251,0 @@ esbuildOptimiser |
{ | ||
"name": "nuxt-build-optimisations", | ||
"version": "1.0.0-8", | ||
"version": "1.0.0-9", | ||
"description": "Automatic optimisations for Nuxt build time.", | ||
@@ -5,0 +5,0 @@ "repository": "loonpwn/nuxt-build-optimisations", |
@@ -20,3 +20,3 @@  | ||
Nuxt 3 will use Vite which will most likely make this package redundant. | ||
Note: Nuxt 3 will use Vite which will most likely make this package redundant in the future. | ||
@@ -30,5 +30,4 @@ ## Features | ||
- webpack benchmarking with [speed-measure-webpack-plugin](https://github.com/stephencookdev/speed-measure-webpack-plugin) | ||
**Experimental** | ||
- Not Dev: Babel transpile for [not-dead browsers](https://github.com/browserslist/browserslist#full-list) | ||
- Replaces [Terser](https://github.com/terser/terser) minification with [esbuild](https://esbuild.github.io/) | ||
@@ -51,2 +50,4 @@ - Enable [Nuxt build cache](https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-build#cache) | ||
:warning: This package is in pre-release. Make sure you test your app before deploying this into production. | ||
--- | ||
@@ -68,5 +69,6 @@ | ||
```js | ||
// nuxt.config.js | ||
buildOptimisations: { | ||
profile: 'risky' | ||
} | ||
}, | ||
``` | ||
@@ -87,5 +89,5 @@ | ||
*Default:* `risky` | ||
*Default:* `experimental` | ||
If you have errors on the `risky` mode you should increment down in profiles until you find one that works. | ||
If you have errors on any mode you should increment down in profiles until you find one that works. | ||
@@ -95,3 +97,2 @@ Setting the profile to false will disable the optimisations, useful when you want to measure your build time without optimisations. | ||
## Measure | ||
@@ -131,2 +132,51 @@ | ||
## Features | ||
*Type:* `object` | ||
*Default:* | ||
```shell | ||
esbuildLoader: true, | ||
esbuildMinifier: true, | ||
imageFileLoader: true, | ||
webpackOptimisations: true | ||
``` | ||
You can disable features if you'd like to skip optimisations. | ||
```shell | ||
buildOptimisations: { | ||
features: { | ||
// use url-loader | ||
imageFileLoader: false | ||
} | ||
} | ||
``` | ||
## esbuildLoaderOptions | ||
*Type:* `object` | ||
*Default:* | ||
```javascript | ||
{ | ||
target: 'es2015' | ||
} | ||
``` | ||
See (esbuild-loader)[https://github.com/privatenumber/esbuild-loader]. | ||
## esbuildMinifyOptions | ||
*Type:* `object` | ||
*Default:* | ||
```javascript | ||
{ | ||
target: 'es2015' | ||
} | ||
``` | ||
See (esbuild-loader)[https://github.com/privatenumber/esbuild-loader]. | ||
## Credits | ||
@@ -133,0 +183,0 @@ |
64416
1.15%182
37.88%1942
-0.15%