From f4db9360b726f72d8abb32bc24655282953fa6e3 Mon Sep 17 00:00:00 2001 From: Eli Perelman Date: Wed, 8 Mar 2017 11:49:59 -0600 Subject: [PATCH] Updating for latest v5 changes --- docs/api/README.md | 108 ++++++++++++++ docs/creating-presets.md | 123 ++++++++++++++- docs/customization/README.md | 7 +- docs/customization/advanced.md | 130 +++++++++++++++- docs/customization/simple.md | 140 ++++++++++++++++++ docs/middleware/README.md | 9 +- .../neutrino-middleware-clean/README.md | 2 +- .../README.md | 1 + .../neutrino-middleware-eslint/README.md | 9 +- .../README.md | 7 +- .../README.md | 2 +- .../neutrino-preset-airbnb-base/README.md | 17 ++- docs/presets/neutrino-preset-jest/README.md | 8 - docs/presets/neutrino-preset-karma/README.md | 14 ++ docs/presets/neutrino-preset-mocha/README.md | 27 ++++ docs/presets/neutrino-preset-node/README.md | 8 +- docs/presets/neutrino-preset-react/README.md | 9 +- docs/presets/neutrino-preset-web/README.md | 18 +-- docs/upgrading-neutrino.md | 44 ++++-- 19 files changed, 619 insertions(+), 64 deletions(-) diff --git a/docs/api/README.md b/docs/api/README.md index c816e6e..f8707ab 100644 --- a/docs/api/README.md +++ b/docs/api/README.md @@ -25,6 +25,114 @@ import Neutrino from 'neutrino'; const api = new Neutrino(options); ``` +## API options + +The Neutrino constructor can accept an object for setting a number of useful options: + +### `options.root` + +Set the base directory which Neutrino middleware and presets operate on. Typically this is the project directory where +the package.json would be located. If the option is not set, Neutrino defaults it to `process.cwd()`. If a relative +path is specified, it will be resolved relative to `process.cwd()`; absolute paths will be used as-is. + +```js +new Neutrino({ + // if not specified, defaults to process.cwd() + + // relative, resolves to process.cwd() + ./website + root: './website', + + // absolute + root: '/code/website' +}) +``` + +### `options.source` + +Set the directory which contains the application source code. If the option is not set, Neutrino defaults it to `src`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +new Neutrino({ + // if not specified, defaults to options.root + src + + // relative, resolves to options.root + ./lib + source: './lib', + + // absolute + source: '/code/website/lib' +}) +``` + +### `options.output` + +Set the directory which will be the output of built assets. If the option is not set, Neutrino defaults it to `build`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +new Neutrino({ + // if not specified, defaults to options.root + build + + // relative, resolves to options.root + ./dist + output: './dist', + + // absolute + output: '/code/website/dist' +}) +``` + +### `options.tests` + +Set the directory that contains test files. If the option is not set, Neutrino defaults it to `test`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +new Neutrino({ + // if not specified, defaults to options.root + test + + // relative, resolves to options.root + ./testing + tests: './testing', + + // absolute + tests: '/code/website/testing' +}) +``` + +### `options.entry` + +Set the main entry point for the application. If the option is not set, Neutrino defaults it to `index.js`. +If a relative path is specified, it will be resolved relative to `options.source`; absolute paths will be used as-is. + +```js +new Neutrino({ + // if not specified, defaults to options.source + index.js + + // relative, resolves to options.source + ./entry.js + entry: './entry.js', + + // absolute + entry: '/code/website/lib/entry.js' +}) +``` + +### `options.node_modules` + +Set the directory which contains the Node.js modules of the project. If the option is not set, Neutrino defaults it to +`node_modules`. If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be +used as-is. + +```js +new Neutrino({ + // if not specified, defaults to options.root + node_modules + + // relative, resolves to options.root + ./modules + node_modules: './modules', + + // absolute + node_modules: '/code/website/modules' +}) +``` + ## Loading middleware Using the Neutrino API you can load [middleware](../middleware/README.md) and presets (which are also just middleware) diff --git a/docs/creating-presets.md b/docs/creating-presets.md index 6ef4b82..95035e7 100644 --- a/docs/creating-presets.md +++ b/docs/creating-presets.md @@ -117,10 +117,12 @@ module.exports = neutrino => { .rule('lint') .pre() .test(/\.jsx?$/) - .include(path.join(process.cwd(), 'src')) - .loader('standard', require.resolve('standard-loader'), { - snazzy: false - }); + .include + .add(neutrino.options.source) + .end() + .use('standard') + .loader(require.resolve('standard-loader')) + .options({ snazzy: false }); }; ``` @@ -151,6 +153,119 @@ When working with paths, remember that your preset will be running in the contex to define application paths by referencing the current working directory with `process.cwd()`. For example, if you wanted to work with the project's "src" directory, you would merge the path via `path.join(process.cwd(), 'src')`. +Neutrino provides a number of paths that have been defaulted through `neutrino.options` or configured by the user. +Please consider using these paths for your preset so they play nice with others. + +### `options.root` + +Set the base directory which Neutrino middleware and presets operate on. Typically this is the project directory where +the package.json would be located. If the option is not set, Neutrino defaults it to `process.cwd()`. If a relative +path is specified, it will be resolved relative to `process.cwd()`; absolute paths will be used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to process.cwd() + neutrino.options.root; + + // relative, resolves to process.cwd() + ./website + neutrino.options.root = './website'; + + // absolute + neutrino.options.root = '/code/website'; +}; +``` + +### `options.source` + +Set the directory which contains the application source code. If the option is not set, Neutrino defaults it to `src`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to options.root + src + neutrino.options.source; + + // relative, resolves to options.root + ./lib + neutrino.options.source = './lib'; + + // absolute + neutrino.options.source = '/code/website/lib'; +}; +``` + +### `options.output` + +Set the directory which will be the output of built assets. If the option is not set, Neutrino defaults it to `build`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to options.root + build + neutrino.options.output; + + // relative, resolves to options.root + ./dist + neutrino.options.output = './dist'; + + // absolute + neutrino.options.output = '/code/website/dist'; +}; +``` + +### `options.tests` + +Set the directory that contains test files. If the option is not set, Neutrino defaults it to `test`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to options.root + test + neutrino.options.tests; + + // relative, resolves to options.root + ./testing + neutrino.options.tests = './testing'; + + // absolute + neutrino.options.tests = '/code/website/testing'; +}; +``` + +### `options.entry` + +Set the main entry point for the application. If the option is not set, Neutrino defaults it to `index.js`. +If a relative path is specified, it will be resolved relative to `options.source`; absolute paths will be used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to options.source + index.js + neutrino.options.entry; + + // relative, resolves to options.source + ./entry.js + neutrino.options.entry = './entry.js'; + + // absolute + neutrino.options.entry = '/code/website/lib/entry.js'; +}; +``` + +### `options.node_modules` + +Set the directory which contains the Node.js modules of the project. If the option is not set, Neutrino defaults it to +`node_modules`. If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be +used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to options.root + node_modules + neutrino.options.node_modules; + + // relative, resolves to options.root + ./modules + neutrino.options.node_modules = './modules'; + + // absolute + neutrino.options.node_modules = '/code/website/modules'; +}; +``` + ## Loader and Babel modules Because of package conflicts or unknown layout of a project's `node_modules` directory, it is usually safer to diff --git a/docs/customization/README.md b/docs/customization/README.md index 8ebc481..73ac3b0 100644 --- a/docs/customization/README.md +++ b/docs/customization/README.md @@ -6,12 +6,13 @@ context of a project without resorting to creating and publishing an entirely in ### Simple Customization -By defining a configuration object within your package.json, Neutrino will merge this information with that provided by -your presets, overriding those options with your custom configuration. +By defining an object within your package.json at `neutrino`, Neutrino will merge this information with that provided by +your presets or middleware, overriding the configuration and options with your own preferences. ### Advanced Customization -You can also create a configuration override directly in your project which can extend the presets you are using. +You can also create a configuration override directly in your project which can extend the presets and middleware you +are using. --- diff --git a/docs/customization/advanced.md b/docs/customization/advanced.md index c3dd9c3..9ee870f 100644 --- a/docs/customization/advanced.md +++ b/docs/customization/advanced.md @@ -54,9 +54,135 @@ your project._ } ``` -Other than actually changing the config, that is all the setup necessary for Neutrino to pick up your custom changes. +Other than actually changing the build configuration or Neutrino options, that is all the setup necessary for Neutrino +to pick up your custom changes. -## Configuring +## Overriding Neutrino options + +Neutrino has a number of useful options for customizing its behavior, as well as the behavior of presets and middleware. +You can override these options using an object at `neutrino.options`. + +**Important! Some of these options are used by presets and middleware to determine their path locations for building. +Making changes to these in advanced configuration will usually mean needing to set Neutrino options before other presets +are loaded, and overriding build configuration after the presets have loaded. Consider using +[simple customization](./simple.md) for setting Neutrino options and preset/middleware-specific options.** + +### `options.root` + +Set the base directory which Neutrino middleware and presets operate on. Typically this is the project directory where +the package.json would be located. If the option is not set, Neutrino defaults it to `process.cwd()`. If a relative +path is specified, it will be resolved relative to `process.cwd()`; absolute paths will be used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to process.cwd() + neutrino.options.root; + + // relative, resolves to process.cwd() + ./website + neutrino.options.root = './website'; + + // absolute + neutrino.options.root = '/code/website'; +}; +``` + +### `options.source` + +Set the directory which contains the application source code. If the option is not set, Neutrino defaults it to `src`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to options.root + src + neutrino.options.source; + + // relative, resolves to options.root + ./lib + neutrino.options.source = './lib'; + + // absolute + neutrino.options.source = '/code/website/lib'; +}; +``` + +### `options.output` + +Set the directory which will be the output of built assets. If the option is not set, Neutrino defaults it to `build`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to options.root + build + neutrino.options.output; + + // relative, resolves to options.root + ./dist + neutrino.options.output = './dist'; + + // absolute + neutrino.options.output = '/code/website/dist'; +}; +``` + +### `options.tests` + +Set the directory that contains test files. If the option is not set, Neutrino defaults it to `test`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to options.root + test + neutrino.options.tests; + + // relative, resolves to options.root + ./testing + neutrino.options.tests = './testing'; + + // absolute + neutrino.options.tests = '/code/website/testing'; +}; +``` + +### `options.entry` + +Set the main entry point for the application. If the option is not set, Neutrino defaults it to `index.js`. +If a relative path is specified, it will be resolved relative to `options.source`; absolute paths will be used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to options.source + index.js + neutrino.options.entry; + + // relative, resolves to options.source + ./entry.js + neutrino.options.entry = './entry.js'; + + // absolute + neutrino.options.entry = '/code/website/lib/entry.js'; +}; +``` + +### `options.node_modules` + +Set the directory which contains the Node.js modules of the project. If the option is not set, Neutrino defaults it to +`node_modules`. If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be +used as-is. + +```js +module.exports = neutrino => { + // if not specified, defaults to options.root + node_modules + neutrino.options.node_modules; + + // relative, resolves to options.root + ./modules + neutrino.options.node_modules = './modules'; + + // absolute + neutrino.options.node_modules = '/code/website/modules'; +}; +``` + +### Middleware or preset options + +Some middleware and presets also have their own custom options. Consult the documentation for the package for specific +details on its customization. + +## Overriding build configuration The Neutrino instance provided to your custom configurator has a `config` property that is an instance of [webpack-chain](https://github.com/mozilla-neutrino/webpack-chain). We won't go in-depth of all the configuration diff --git a/docs/customization/simple.md b/docs/customization/simple.md index 0c905ed..32791ce 100644 --- a/docs/customization/simple.md +++ b/docs/customization/simple.md @@ -30,6 +30,146 @@ specified your presets through `neutrino` as opposed to flags through `scripts`: } ``` +## Overriding Neutrino options + +Neutrino has a number of useful options for customizing its behavior, as well as the behavior of presets and middleware. +You can override these options using an object at `neutrino.options`: + +### `options.root` + +Set the base directory which Neutrino middleware and presets operate on. Typically this is the project directory where +the package.json would be located. If the option is not set, Neutrino defaults it to `process.cwd()`. If a relative +path is specified, it will be resolved relative to `process.cwd()`; absolute paths will be used as-is. + +```js +{ + "neutrino": { + "options": { + // if not specified, defaults to process.cwd() + + // relative, resolves to process.cwd() + ./website + "root": "./website", + + // absolute + "root": "/code/website" + } + } +} +``` + +### `options.source` + +Set the directory which contains the application source code. If the option is not set, Neutrino defaults it to `src`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +{ + "neutrino": { + "options": { + // if not specified, defaults to options.root + src + + // relative, resolves to options.root + ./lib + "source": "./lib", + + // absolute + "source": "/code/website/lib" + } + } +} +``` + +### `options.output` + +Set the directory which will be the output of built assets. If the option is not set, Neutrino defaults it to `build`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +{ + "neutrino": { + "options": { + // if not specified, defaults to options.root + build + + // relative, resolves to options.root + ./dist + "output": "./dist", + + // absolute + "output": "/code/website/dist" + } + } +} +``` + +### `options.tests` + +Set the directory that contains test files. If the option is not set, Neutrino defaults it to `test`. +If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be used as-is. + +```js +{ + "neutrino": { + "options": { + // if not specified, defaults to options.root + test + + // relative, resolves to options.root + ./testing + "tests": "./testing", + + // absolute + "tests": "/code/website/testing" + } + } +} +``` + +### `options.entry` + +Set the main entry point for the application. If the option is not set, Neutrino defaults it to `index.js`. +If a relative path is specified, it will be resolved relative to `options.source`; absolute paths will be used as-is. + +```js +{ + "neutrino": { + "options": { + // if not specified, defaults to options.source + index.js + + // relative, resolves to options.source + ./entry.js + "entry": "./entry.js", + + // absolute + "entry": "/code/website/lib/entry.js" + } + } +} +``` + +### `options.node_modules` + +Set the directory which contains the Node.js modules of the project. If the option is not set, Neutrino defaults it to +`node_modules`. If a relative path is specified, it will be resolved relative to `options.root`; absolute paths will be +used as-is. + +```js +{ + "neutrino": { + "options": { + // if not specified, defaults to options.root + node_modules + + // relative, resolves to options.root + ./modules + "node_modules": "./modules" + + // absolute + "node_modules": "/code/website/modules" + } + } +} +``` + +### Middleware or preset options + +Some middleware and presets also have their own custom options. Consult the documentation for the package for specific +details on its customization. + +## Overriding build configuration + Add a new property to `neutrino` named `config`. This will be an object where we can provide configuration data: ```json diff --git a/docs/middleware/README.md b/docs/middleware/README.md index cf27ac1..f222623 100644 --- a/docs/middleware/README.md +++ b/docs/middleware/README.md @@ -41,7 +41,8 @@ const api = new Neutrino(); function env(neutrino, additionalVars = []) { neutrino.config - .plugin('env', EnvironmentPlugin, ['NODE_ENV', ...additionalVars]); + .plugin('env') + .use(EnvironmentPlugin, ['NODE_ENV', ...additionalVars]); } api.use(env); // or: @@ -58,7 +59,8 @@ consumers. const { EnvironmentPlugin } = require('webpack'); module.exports = (neutrino, additionalVars = []) => neutrino.config - .plugin('env', EnvironmentPlugin, ['NODE_ENV', ...additionalVars]); + .plugin('env') + .use(EnvironmentPlugin, ['NODE_ENV', ...additionalVars]); ``` ```js @@ -95,7 +97,8 @@ const { EnvironmentPlugin } = require('webpack'); module.exports = (pluginName = 'env') => (neutrino, additionalVars = []) => { neutrino.config - .plugin(pluginName, EnvironmentPlugin, ['NODE_ENV', ...additionalVars]); + .plugin(pluginName) + .use(EnvironmentPlugin, ['NODE_ENV', ...additionalVars]); }; ``` diff --git a/docs/middleware/neutrino-middleware-clean/README.md b/docs/middleware/neutrino-middleware-clean/README.md index b98c21f..0277a10 100644 --- a/docs/middleware/neutrino-middleware-clean/README.md +++ b/docs/middleware/neutrino-middleware-clean/README.md @@ -39,7 +39,7 @@ neutrino.use(clean); // Usage shows the default values of this middleware: neutrino.use(clean, { paths: [], - root: process.cwd() + root: neutrino.options.root }); ``` diff --git a/docs/middleware/neutrino-middleware-compile-loader/README.md b/docs/middleware/neutrino-middleware-compile-loader/README.md index 772ce60..40b8ddf 100644 --- a/docs/middleware/neutrino-middleware-compile-loader/README.md +++ b/docs/middleware/neutrino-middleware-compile-loader/README.md @@ -35,6 +35,7 @@ const compile = require('neutrino-middleware-compile-loader'); neutrino.use(compile, { include: [], + exclude: [], babel: {} }); ``` diff --git a/docs/middleware/neutrino-middleware-eslint/README.md b/docs/middleware/neutrino-middleware-eslint/README.md index 145a3f9..5b81e0c 100644 --- a/docs/middleware/neutrino-middleware-eslint/README.md +++ b/docs/middleware/neutrino-middleware-eslint/README.md @@ -36,12 +36,13 @@ const eslint = require('neutrino-middleware-eslint'); // Usage shows default values neutrino.use(eslint, { test: /\.(js|jsx)$/, - include, /* REQUIRED */ + include: [], /* Should specify either include or exclude */ + exclude: [], /* Should specify either include or exclude */ eslint: { failOnError: process.env.NODE_ENV !== 'development', emitWarning: process.env.NODE_ENV !== 'development', emitError: process.env.NODE_ENV !== 'development', - cwd: process.cwd(), + cwd: neutrino.options.root, useEslintrc: false, root: true, plugins: ['babel'], @@ -65,8 +66,10 @@ neutrino.use(eslint, { ``` - `test`: Test which files should be linted. -- `include`: **REQUIRED** An array of paths to include in linting. Maps to Webpack's +- `include`: An array of paths to include in linting. Maps to Webpack's [`Rule.include`](https://webpack.js.org/configuration/module/#rule-include) +- `exclude`: An array of paths to exclude from linting. Maps to Webpack's +[`Rule.exclude`](https://webpack.js.org/configuration/module/#rule-exclude) - `eslint`: An ESLint CLIEngine configuration object for configuring ESLint. Use this to configure rules, plugins, and other [ESLint options](http://eslint.org/docs/user-guide/configuring). diff --git a/docs/middleware/neutrino-middleware-loader-merge/README.md b/docs/middleware/neutrino-middleware-loader-merge/README.md index da1c379..b65f20e 100644 --- a/docs/middleware/neutrino-middleware-loader-merge/README.md +++ b/docs/middleware/neutrino-middleware-loader-merge/README.md @@ -41,9 +41,10 @@ neutrino.use(loaderMerge('compile', 'babel'), { // Equivalent to: neutrino.config.module .rule('compile') - .loader('babel', options => require('deepmerge')(options, { - plugins: ['object-rest-spread'] - })); + .use('babel') + .tap(options => require('deepmerge')(options, { + plugins: ['object-rest-spread'] + })); ``` This middleware is a factory intended to be invoked with a rule name and a loader name for which to extend the options. diff --git a/docs/middleware/neutrino-middleware-start-server/README.md b/docs/middleware/neutrino-middleware-start-server/README.md index 266605b..f8687db 100644 --- a/docs/middleware/neutrino-middleware-start-server/README.md +++ b/docs/middleware/neutrino-middleware-start-server/README.md @@ -35,7 +35,7 @@ and plug it into Neutrino: const server = require('neutrino-middleware-start-server'); // Use with default options, starting the server -// for a single-configured entry-point +// for the main entry point, neutrino.options.entry neutrino.use(server); // Usage with custom server file to start diff --git a/docs/presets/neutrino-preset-airbnb-base/README.md b/docs/presets/neutrino-preset-airbnb-base/README.md index b25dc19..f925630 100644 --- a/docs/presets/neutrino-preset-airbnb-base/README.md +++ b/docs/presets/neutrino-preset-airbnb-base/README.md @@ -156,12 +156,12 @@ _Example: Turn off semicolons from being required as defined by the Airbnb rules ```json { - "config": { - "neutrino": { + "neutrino": { + "config": { "module": { "rule": { "lint": { - "loader": { + "use": { "eslint": { "options": { "rules": { @@ -210,11 +210,12 @@ const merge = require('deepmerge'); module.exports = neutrino => { neutrino.config.module .rule('lint') - .loader('eslint', options => merge(options, { - rules: { - semi: 'off' - } - })); + .use('eslint') + .tap(options => merge(options, { + rules: { + semi: 'off' + } + })); }; ``` diff --git a/docs/presets/neutrino-preset-jest/README.md b/docs/presets/neutrino-preset-jest/README.md index 0f3e139..2e0c475 100644 --- a/docs/presets/neutrino-preset-jest/README.md +++ b/docs/presets/neutrino-preset-jest/README.md @@ -204,14 +204,6 @@ the format is defined on the [Jest documentation site](https://facebook.github.i _Example: Turn off bailing on test failures._ -```json -{ - "jest": { - "bail": false - } -} -``` - ```json { "neutrino": { diff --git a/docs/presets/neutrino-preset-karma/README.md b/docs/presets/neutrino-preset-karma/README.md index a5bd5d1..b5d55b2 100644 --- a/docs/presets/neutrino-preset-karma/README.md +++ b/docs/presets/neutrino-preset-karma/README.md @@ -174,6 +174,20 @@ directly from package.json. `neutrino-preset-karma` will import Karma configurat `neutrino.options.karma` object if defined. The format is defined on the [Karma documentation site](http://karma-runner.github.io/1.0/config/configuration-file.html). +_Example: Change the duration Karma waits for a browser to reconnect (in ms)._ + +```js +{ + "neutrino": { + "options": { + "karma": { + "browserDisconnectTimeout": 5000 + } + } + } +} +``` + ### Advanced configuration By following the [customization guide](../../customization/advanced.md) you can override and augment testing by creating a diff --git a/docs/presets/neutrino-preset-mocha/README.md b/docs/presets/neutrino-preset-mocha/README.md index 2c93290..9940cde 100644 --- a/docs/presets/neutrino-preset-mocha/README.md +++ b/docs/presets/neutrino-preset-mocha/README.md @@ -146,6 +146,33 @@ directly from package.json. `neutrino-preset-mocha` will import Mocha configurat [Mocha documentation site](https://mochajs.org/#usage), with command-line flags mapping to camel-cased options in `neutrino.options.mocha`. +_Example: Switch the test reporter from the default `spec` to `nyan`:_ + +```js +{ + "neutrino": { + "options": { + "mocha": { + "reporter": "nyan" + } + } + } +} +``` + +```bash +❯ yarn test + + 1 -__,------, + 0 -__| /\_/\ + 0 -_~|_( ^ .^) + -_ "" "" + + 1 passing (362ms) + +✨ Done in 3.28s. +``` + ### Advanced configuration By following the [customization guide](../../customization/advanced.md) and knowing the rule, and loader IDs above, diff --git a/docs/presets/neutrino-preset-node/README.md b/docs/presets/neutrino-preset-node/README.md index b5c0a23..37e23d5 100644 --- a/docs/presets/neutrino-preset-node/README.md +++ b/docs/presets/neutrino-preset-node/README.md @@ -157,8 +157,8 @@ libraries, and will take a little extra customization to make them suitable for ## Hot Module Replacement -While `neutrino-preset-node` supports hot reloading your app, it does require some application-specific changes in order -to operate. Your application should define split points for which to accept modules to reload using +While `neutrino-preset-node` supports Hot Module Replacement for your app, it does require some application-specific +changes in order to operate. Your application should define split points for which to accept modules to reload using `module.hot`: For example: @@ -235,8 +235,8 @@ _Example: Allow importing modules with an `.mjs` extension._ ```json { - "config": { - "neutrino": { + "neutrino": { + "config": { "resolve": { "extensions": [ ".mjs" diff --git a/docs/presets/neutrino-preset-react/README.md b/docs/presets/neutrino-preset-react/README.md index ccfde15..fa40751 100644 --- a/docs/presets/neutrino-preset-react/README.md +++ b/docs/presets/neutrino-preset-react/README.md @@ -143,8 +143,8 @@ _Example: Put React and React DOM into a separate "vendor" chunk:_ ```json { - "config": { - "neutrino": { + "neutrino": { + "config": { "entry": { "vendor": [ "react", @@ -220,7 +220,7 @@ module.exports = neutrino => { ## Hot Module Replacement -While `neutrino-preset-react` supports hot reloading your app using React Hot Loader, it does require some +While `neutrino-preset-react` supports Hot Module Replacement your app using React Hot Loader, it does require some application-specific changes in order to operate. First, install `react-hot-loader` as a dependency, this **must** be React Hot Loader v3+ (currently in beta): @@ -239,7 +239,8 @@ First, install `react-hot-loader` as a dependency, this **must** be React Hot Lo --- -- From your `index` entry point (`src/index.js`), import an `AppContainer` from `react-hot-loader`. +- From your `index` entry point (defaults to `src/index.js` from `neutrino.options.entry`), import an `AppContainer` +from `react-hot-loader`. - Wrap your top-level React component in the `AppContainer`. - Perform the application render in a reusable function for initial load and subsequent reloads. - Add the `hot` acceptance to call this function. diff --git a/docs/presets/neutrino-preset-web/README.md b/docs/presets/neutrino-preset-web/README.md index 41f90a8..a4d3a6d 100644 --- a/docs/presets/neutrino-preset-web/README.md +++ b/docs/presets/neutrino-preset-web/README.md @@ -6,7 +6,7 @@ ## Features - Zero upfront configuration necessary to start developing and building a web app -- Modern Babel compilation supporting ES modules, last 2 major browser versions, and async functions +- Modern Babel compilation supporting ES modules, last 2 major browser versions, async functions, and dynamic imports - Webpack loaders for importing HTML, CSS, images, icons, and fonts - Webpack Dev Server during development - Automatic creation of HTML pages, no templating necessary @@ -118,8 +118,8 @@ You can either serve or deploy the contents of this `build` directory as a stati ## Hot Module Replacement -While `neutrino-preset-web` supports hot reloading your app, it does require some application-specific changes in order -to operate. Your application should define split points for which to accept modules to reload using +While `neutrino-preset-web` supports Hot Module Replacement your app, it does require some application-specific changes +in order to operate. Your application should define split points for which to accept modules to reload using `module.hot`: For example: @@ -160,8 +160,9 @@ To override the build configuration, start with the documentation on [customizat changes. By default the Web preset creates a single **main** `index` entry point to your application, and this maps to the -`index.js` file in the `src` directory. This means that the Web preset is optimized toward the use case of single-page -applications over multi-page applications. +`index.js` file in the `src` directory. This value is provided by `neutrino.options.entry`. +This means that the Web preset is optimized toward the use case of single-page applications over multi-page +applications. ### Rules @@ -200,8 +201,8 @@ _Example: Put lodash into a separate "vendor" chunk:_ ```json { - "config": { - "neutrino": { + "neutrino": { + "config": { "entry": { "vendor": [ "lodash" @@ -263,8 +264,7 @@ _Example: Change the application mount ID from "root" to "app":_ const merge = require('deepmerge'); module.exports = neutrino => { - neutrino.config - .plugin('html', options => merge(options, { appMountId: 'app' })); + neutrino.options.html.appMountId = 'app'; }; ``` diff --git a/docs/upgrading-neutrino.md b/docs/upgrading-neutrino.md index 42eded5..d4d0c1d 100644 --- a/docs/upgrading-neutrino.md +++ b/docs/upgrading-neutrino.md @@ -3,7 +3,7 @@ Neutrino v5 introduces a number of changes, with some of them being breaking changes. To upgrade from Neutrino v4 to v5, be sure to check this list for tasks you may need to perform to use this latest version: -- Updates to config for creating plugins (from webpack-chain v2 upgrade): +- Updates to config for creating plugins (from webpack-chain v3 upgrade): ```js // Creating plugins in v4 @@ -13,10 +13,11 @@ neutrino.config // Creating plugins in v5 neutrino.config - .plugin(name, WebpackPlugin, ...args) + .plugin(name) + .use(WebpackPlugin, args) ``` -- Updates to config for modifying plugins (from webpack-chain v2 upgrade): +- Updates to config for modifying plugins (from webpack-chain v3 upgrade): ```js // Modifying plugins in v4 @@ -26,10 +27,31 @@ neutrino.config // Modifying plugins in v5 neutrino.config - .plugin(name, args => newArgs); + .plugin(name) + .tap(args => newArgs); ``` -- Updates to config for modifying loaders (from webpack-chain v2 upgrade). The function now gets its options directly +- Updates to config for creating loaders (from webpack-chain v3 upgrade): + +```js +// Creating loaders in v4 +neutrino.config.module + .rule('compile') + .loader('babel', 'babel-loader', { + options: { + plugins: ['object-rest-spread'] + } + }); + +// Creating loaders in v5 +neutrino.config + .rule('compile') + .use('babel') + .loader('babel-loader') + .options({ plugins: ['object-rest-spread'] }); +``` + +- Updates to config for modifying loaders (from webpack-chain v3 upgrade). The function now gets its options directly instead of being nested in an object: ```js @@ -45,9 +67,8 @@ neutrino.config.module // Modifying loaders in v5 neutrino.config.module .rule('compile') - .loader('babel', options => merge(options, { - plugins: ['object-rest-spread'] - })); + .use('babel') + .tap(options => merge(options, { plugins: ['object-rest-spread'] })); ``` - Simple configuration via package.json now done from top-level `neutrino` object. Rename `config` to `neutrino`, and @@ -74,7 +95,7 @@ been renamed to `options`. } ``` -- The Web preset has renamed its styling loader from `css` to `style`: +- The Web preset has renamed its styling rule from `css` to `style`: ```js // v4 API for Web preset @@ -98,7 +119,8 @@ neutrino.config.module.rule('style') } ``` -- Jest upgraded to v19, which changes the option `testPathDirs` to `roots`. +- Jest upgraded to v19, which changes the option `testPathDirs` to `roots`. Jest options set using +package.json can now only be done at `neutrino.options.jest` (no more package.json `jest`); - Linting base is deprecated in favor of `neutrino-middleware-eslint`: ```js @@ -119,7 +141,7 @@ neutrino.use(eslint, { ``` - When using a linting preset or consuming anything with `neutrino-middleware-eslint`, the `eslintrc()` method has been -moved from `neutrino.custom` to `.neutrino`: +moved from `neutrino.custom.eslintrc` to `neutrino.eslintrc`: ```js // v4 API