Browse Source

Adding option-configurable compile targets

v6-dev
Eli Perelman 8 years ago
parent
commit
19d5e641c8
  1. 98
      docs/presets/neutrino-preset-node/README.md
  2. 98
      docs/presets/neutrino-preset-web/README.md
  3. 5
      packages/neutrino-preset-node/index.js
  4. 1
      packages/neutrino-preset-node/package.json
  5. 4
      packages/neutrino-preset-node/yarn.lock
  6. 6
      packages/neutrino-preset-web/index.js

98
docs/presets/neutrino-preset-node/README.md

@ -231,6 +231,46 @@ The following is a list of plugins and their identifiers which can be overridden
By following the [customization guide](../../customization/simple.md) and knowing the rule, loader, and plugin IDs above,
you can override and augment the build directly from package.json.
#### Compile targets
This preset uses babel-preset-env to compile code targeting the Node.js v6.9+. To change
the Node.js target from package.json, specify an object at `neutrino.options.compile.targets` which contains a
[babel-preset-env-compatible](https://github.com/babel/babel-preset-env#targetsnode) Node.js target.
_Example: Replace the preset Node.js target with support for Node.js 4.2:_
```json
{
"neutrino": {
"options": {
"compile": {
"targets": {
"node": 4.2
}
}
}
}
}
```
_Example: Change support to current Node.js version:_
```json
{
"neutrino": {
"options": {
"compile": {
"targets": {
"node": "current"
}
}
}
}
}
```
#### Other customization examples
_Example: Allow importing modules with an `.mjs` extension._
```json
@ -252,6 +292,64 @@ _Example: Allow importing modules with an `.mjs` extension._
By following the [customization guide](../../customization/advanced.md) and knowing the rule, loader, and plugin IDs above,
you can override and augment the build by creating a JS module which overrides the config.
#### Compile targets
This preset uses babel-preset-env to compile code targeting the Node.js v6.9+. To change
the Node.js target from package.json, specify an object at `neutrino.options.compile.targets` which contains a
[babel-preset-env-compatible](https://github.com/babel/babel-preset-env#targetsnode) Node.js target.
**Note: Setting these options via `neutrino.options.compile` must be done prior to loading the Node.js preset or they
will not be picked up by the compile middleware. These examples show changing compile targets with options before
loading the preset and overriding them if loaded afterwards.**
_Example: Replace the preset Node.js target with support for Node.js 4.2:_
```js
module.exports = neutrino => {
// Using neutrino.options prior to loading Node.js preset
neutrino.options.compile = {
targets: {
node: 4.2
}
};
// Using compile options override following loading Node.js preset
neutrino.config.module
.rule('compile')
.use('babel')
.tap(options => {
options.presets[0][1].targets.node = 4.2;
return options;
});
};
```
_Example: Change support to current Node.js version:_
```js
module.exports = neutrino => {
// Using neutrino.options prior to loading Node.js preset
neutrino.options.compile = {
targets: {
node: 4.2
}
};
// Using compile options override following loading Node.js preset
neutrino.config.module
.rule('compile')
.use('babel')
.tap(options => {
options.presets[0][1].targets.node = 'current';
return options;
});
};
```
#### Other customization examples
_Example: Allow importing modules with an `.mjs` extension._
```js

98
docs/presets/neutrino-preset-web/README.md

@ -192,6 +192,48 @@ The following is a list of plugins and their identifiers which can be overridden
By following the [customization guide](../../customization/simple.md) and knowing the rule, loader, and plugin IDs above,
you can override and augment the build directly from package.json.
#### Compile targets
This preset uses babel-preset-env to compile code targeting the last 2 browser versions of major browsers. To change
the browser targets from package.json, specify an object at `neutrino.options.compile.targets` which contains a
[browserlist-compatible](https://github.com/ai/browserslist) array of browser targets.
_Example: Replace the Web preset browser targets with support for browsers with greater than 5% global usage:_
```json
{
"neutrino": {
"options": {
"compile": {
"targets": {
"browsers": [
"> 5%"
]
}
}
}
}
}
```
_Example: Change support to latest version instead of last 2 versions:_
```json
{
"neutrino": {
"options": {
"compile": {
"targets": {
"browsers": [
"last 1 version"
]
}
}
}
}
}
```
#### Vendoring
By defining an entry point in package.json named `vendor` you can split out external dependencies into a chunk separate
@ -241,6 +283,62 @@ _Example: Change the application mount ID from "root" to "app":_
By following the [customization guide](../../customization/advanced.md) and knowing the rule, loader, and plugin IDs above,
you can override and augment the build by creating a JS module which overrides the config.
#### Compile targets
This preset uses babel-preset-env to compile code targeting the last 2 browser versions of major browsers. To change
the browser targets from an override file, specify an object at `neutrino.options.compile.targets` which contains a
[browserlist-compatible](https://github.com/ai/browserslist) array of browser targets.
**Note: Setting these options via `neutrino.options.compile` must be done prior to loading the Web preset or they
will not be picked up by the compile middleware. These examples show changing compile targets with options before
loading the preset and overriding them if loaded afterwards.**
_Example: Replace the Web preset browser targets with support for browsers with greater than 5% global usage:_
```js
module.exports = neutrino => {
// Using neutrino.options prior to loading Web preset
neutrino.options.compile = {
targets: {
browsers: ['> 5%']
}
};
// Using compile options override following loading Web preset
neutrino.config.module
.rule('compile')
.use('babel')
.tap(options => {
options.presets[0][1].targets.browsers = ['> 5%'];
return options;
});
};
```
_Example: Change support to latest version instead of last 2 versions:_
```js
module.exports = neutrino => {
// Using neutrino.options prior to loading Web preset
neutrino.options.compile = {
targets: {
browsers: ['last 1 version']
}
};
// Using compile options override following loading Web preset
neutrino.config.module
.rule('compile')
.use('babel')
.tap(options => {
options.presets[0][1].targets.browsers = ['last 1 version'];
return options;
});
};
```
#### Vendoring
By defining an entry point named `vendor` you can split out external dependencies into a chunk separate

5
packages/neutrino-preset-node/index.js

@ -9,6 +9,7 @@ const hot = require('neutrino-middleware-hot');
const namedModules = require('neutrino-middleware-named-modules');
const nodeExternals = require('webpack-node-externals');
const { join } = require('path');
const { pathOr } = require('ramda');
const MODULES = join(__dirname, 'node_modules');
@ -30,9 +31,7 @@ module.exports = (neutrino) => {
presets: [
[require.resolve('babel-preset-env'), {
modules: false,
targets: {
node: 6.9
}
targets: pathOr({ node: 6.9 }, ['options', 'compile', 'targets'], neutrino)
}]
]
}

1
packages/neutrino-preset-node/package.json

@ -19,6 +19,7 @@
"babel-preset-env": "^1.1.10",
"exports-loader": "^0.6.4",
"imports-loader": "^0.7.1",
"ramda": "^0.23.0",
"webpack-node-externals": "1.5.4",
"neutrino-middleware-banner": "^5.0.0",
"neutrino-middleware-clean": "^5.0.0",

4
packages/neutrino-preset-node/yarn.lock

@ -547,6 +547,10 @@ private@^0.1.6:
version "0.1.7"
resolved "https://registry.yarnpkg.com/private/-/private-0.1.7.tgz#68ce5e8a1ef0a23bb570cc28537b5332aba63ef1"
ramda@^0.23.0:
version "0.23.0"
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.23.0.tgz#ccd13fff73497a93974e3e86327bfd87bd6e8e2b"
regenerate@^1.2.1:
version "1.3.2"
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.2.tgz#d1941c67bad437e1be76433add5b385f95b19260"

6
packages/neutrino-preset-web/index.js

@ -50,7 +50,7 @@ module.exports = (neutrino) => {
neutrino.use(styleLoader);
neutrino.use(fontLoader);
neutrino.use(imageLoader);
neutrino.use(htmlTemplate);
neutrino.use(htmlTemplate, neutrino.options.html);
neutrino.use(namedModules);
neutrino.use(compileLoader, {
include: [neutrino.options.source, neutrino.options.tests],
@ -61,7 +61,7 @@ module.exports = (neutrino) => {
modules: false,
useBuiltIns: true,
include: ['transform-regenerator'],
targets: {
targets: pathOr({
browsers: [
'last 2 Chrome versions',
'last 2 Firefox versions',
@ -70,7 +70,7 @@ module.exports = (neutrino) => {
'last 2 Safari versions',
'last 2 iOS versions'
]
}
}, ['options', 'compile', 'targets'], neutrino)
}]
]
}

Loading…
Cancel
Save