Extends default nuxt config with some useful optimisations
npm install dn-nuxt-configThis package adds a number of common optimisations to the nuxt default config:
* Changes babel config to use .browserlistrc or browserlists from package.json
* Adds babel-plugin-lodash plugin to babel plugins
* Adds an eslint-loader to webpack config so eslint errors are shown during development
* Adds a stylelint-loader to webpack config so sylelint errors are shown during development
* Adds imagemin to optimize static nuxt assets:
* Adds an object-fit polyfill:
* Allows for debugging build times:
* Optionally improve your development build times by enabling the experimental boost mode
* Optionally disable the webpack error overlay by setting an environment variable (NUXT_DISABLE_OVERLAY=true)
* Replaces Nuxt PostCSS version 7 with version 8
yarn add dn-nuxt-config --devAdd dn-nuxt-config to buildModules section of nuxt.config.js
``javascript`
{
buildModules: [
'dn-nuxt-config'
]
}
The settings are documented below with their _default_ values. If you do not define any settings, the default will always apply.
`javascriptfalse
{
buildModules: [
['dn-nuxt-config', {
eslint: true, // Set to to disable stylelint checks and output in webpackfalse
stylelint: true, // Set to to disable stylelint checks and output in webpack.babelrc
objectFitPolyfill: false, // Enable to add a javscript/css object-fit polyfill for older browsers: https://github.com/bfred-it/object-fit-images
measure: false, // Enabling outputs build time from https://github.com/stephencookdev/speed-measure-webpack-plugin
boost: false, // Enabling sets experimental nuxt performance-improvements (dev-only)
useBabelRc: false, // Loads a file with config, rather than using only what's defined in your nuxt.config.js and the default nuxt preset.true
skipLodashPlugin: false // Set to to disable lodash bundle size optimisation. Only disable this if you're NOT using lodash in your project`
babelBrowserListsForLegacy: true // Enabling overrides the nuxt default browser support for your "legacy" client bundle (ie: 9) with a list of browsers from a browserslist-compatible config in your project: https://browsersl.ist/
babelBrowserListsForLegacy: true // Enabling overrides the default browser support for your "modern" client bundle (esmodule: true) with a list of browsers esmodule-compatible browsers from a browserslist-compatible config: https://browsersl.ist/
}]
]
}
Some modules are loaded with a default config, refer to their README for customisation:
* Imagemin:
* Stylelint:
* Eslint:
If you set this globally on your system (eg ~/.profile or ~/.bashrc) it will disable the overlay across all your projects
which apply this module.
Usage;
NUXT_DISABLE_OVERLAY=true yarn dev.
If you want to disable the overlay for everyone in your project (not recommended) you can use the vanilla nuxt option;
nuxt.config.js`javascript`
export default {
[...]
build: {
friendlyErrors: false
}
}
or modern: client is set in your nuxt.config.js)If enabled, modern browsers with module support will always load the modern bundle.
You can override any of these settings by defining an override for
build.babel.presets in your config.
This module attempts to make some of the workarounds to use browserslist configs easier, but you can still override with your custom presets or browser targets.
_Any custom presets config in your nuxt.config.js will always override any settings changed by this module_$3
When enabled with the default config, this module replaces some of the babel config outlined above to use a browserslist configured in your project.> A "client" (legacy) bundle optimized for IE9 and later
With a config which will load a list of browsers to support from a "browserslist"-config in your project.
This config will usually live inside your
package.json or a dedicated .browserslistrc file in your root folder.> A "client" modern bundle, with support for any browser with esmodule support
The modern bundle will be build for a subset of your browserslist: Only browsers in your browserslist which support esmodules.
#### When to change the babel-browserslist overrides
> Note: Your own config will _always_ take priority over the browserslist defaults. You can mix-and-match or override the targets with custom config even if you use
babelBrowsersListForXXX: true
1. If your application _only_ targets "evergreen" or otherwise recent browsers which all support javascript modules:
- Set your browserslist config to those browsers
- Set babelBrowserListsForLegacy: false: This will give you a larger "legacy" bundle, which will not however be loaded into any of your supported browsers
- Set babelBrowserListsForModern: true: This will give you a smaller "modern" bundle for your supported browsers, since you are only supporting a subset of the default target for this build2. If your application targets both "evergreen" browsers and a subset of some older browsers without esmodules support:
- Set your browserslist config to those browsers
- You can use the defaults as set by this package, explained below:
- Use the default
babelBrowserListsForLegacy: true: This will give you a smaller "legacy" bundle, since you are likely working with more recent browsers than the default ie: 9
- Set babelBrowserListsForModern: true: This will support a subset of the browsers in your browserslist which have esmodule support and make this bundle smaller for them3. If you don't have a browserslist or don't want to use the same list for both css and javscript:
- Set
babelBrowserListsForLegacy: false and babelBrowserListsForModern: false
- You can set your own targets in your nuxt.config.js or use the nuxt defaultsUsing the object-fit polyfill
You can add a polyfill to support the CSS object-fit rule in older browsers. It is disabled by default.Install the polyfill:
yarn add object-fit-imagesEnable it in your
nuxt.config.js
`javascript
{
buildModules: [
['dn-nuxt-config', { objectFitPolyfill: true }]
]
}
`Changelog
See CHANGELOG.mdContributing
Please submit contributions through a merge request.All commits on this repository MUST comply with the Conventional Commits Standard.
Running
yarn install on your local machine should enforce all local commits to adhere to this standard.
If you're new to conventional commits you're encouraged to use Comittizen to learn the ropes.Releasing
Only package maintainers should release new versions.
A changelog is automatically maintained using standard-version.
Run yarn run release to bump/tag the version, generate the changelog and immediately publish the next release> note: Don't fill out the version number in the prompt. Just immediatly press "enter".
> This is because
yarn run release is a combination of standard-version and vanilla yarn publish, where the latter will prompt you for a new version which standard-version` has already incremeted automatically.