Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Adding option-configurable compile targets #111

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions docs/presets/neutrino-preset-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
98 changes: 98 additions & 0 deletions docs/presets/neutrino-preset-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions packages/neutrino-preset-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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)
}]
]
}
Expand Down
1 change: 1 addition & 0 deletions packages/neutrino-preset-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/neutrino-preset-node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions packages/neutrino-preset-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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',
Expand All @@ -70,7 +70,7 @@ module.exports = (neutrino) => {
'last 2 Safari versions',
'last 2 iOS versions'
]
}
}, ['options', 'compile', 'targets'], neutrino)
}]
]
}
Expand Down