Skip to content

Commit

Permalink
feat: move all preset-env options under single directive
Browse files Browse the repository at this point in the history
This gives more control on how the react preset will pass in options
to base.
  • Loading branch information
swashata committed Sep 24, 2018
1 parent cb4d6c2 commit ef5b46f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
10 changes: 6 additions & 4 deletions packages/babel-preset-base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ module.exports = {
'@wpw/base',
{
noDynamicImport: true, // disable @babel/plugin-syntax-dynamic-import
target: 'not dead, > 0.25%', // browserslist query to pass to @babel/preset-env
presetEnv: {
target: 'not dead, > 0.25%', // browserslist query to pass to @babel/preset-env
},
},
],
};
Expand Down Expand Up @@ -111,10 +113,10 @@ Set to `true` to disable [`@babel/plugin-proposal-class-properties`](https://bab

Set to `true` to disable [`@babel/plugin-proposal-json-strings`](https://babeljs.io/docs/en/babel-plugin-proposal-json-strings).

#### Options for `@babel/preset-env`
#### `presetEnv` Options for `@babel/preset-env`

What-ever else you pass to the config, is passed directly to `@babel/preset-env`. This
gives you more control on how to configure the most stable `env` preset.
What-ever you pass to the `presetEnv` directive, is passed directly to `@babel/preset-env`. This
gives you more control on how to configure the `@babel/preset-env` preset.

Please [read the documentation](https://babeljs.io/docs/en/babel-preset-env) for
available options.
Expand Down
12 changes: 11 additions & 1 deletion packages/babel-preset-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"version": "0.0.1",
"description": "Babel preset for @wps/scripts, without react specific transforms.",
"keywords": [
"wordpress", "bundler", "webpack", "browser-sync", "wordpress-bundler"
"wordpress",
"bundler",
"webpack",
"browser-sync",
"wordpress-bundler"
],
"main": "lib/index.js",
"repository": "https://github.com/swashata/wp-webpack-script",
Expand All @@ -19,6 +23,9 @@
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/preset-env": "^7.1.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"engines": {
"node": ">=8.9.0"
},
Expand All @@ -32,5 +39,8 @@
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@babel/core": "^7.1.0"
}
}
14 changes: 8 additions & 6 deletions packages/babel-preset-base/src/__tests__/preset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ describe('@wpw/babel-preset-base/preset', () => {
expect(typeof configWithNull).toBe('object');
});

test('passes all options to @babel/preset-env', () => {
test('passes all options from presetEnv to @babel/preset-env', () => {
const envOptions = {
targets: 'not-dead, > 25%',
modules: 'umd',
debug: true,
presetEnv: {
targets: 'not-dead, > 25%',
modules: 'umd',
debug: true,
},
};
const config = preset(envOptions);
expect(config).toHaveProperty('presets');
Expand All @@ -26,8 +28,8 @@ describe('@wpw/babel-preset-base/preset', () => {
p => Array.isArray(p) && p[0] === '@babel/preset-env'
);
expect(presetEnv).toHaveLength(2);
Object.keys(envOptions).forEach(key => {
expect(presetEnv[1][key]).toBe(envOptions[key]);
Object.keys(envOptions.presetEnv).forEach(key => {
expect(presetEnv[1][key]).toBe(envOptions.presetEnv[key]);
});
});

Expand Down
4 changes: 2 additions & 2 deletions packages/babel-preset-base/src/preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export default (opts = {}) => {
noImportMeta = false,
noClassProperties = false,
noJsonStrings = false,
...envOptions
presetEnv = {},
} = opts || {};

// Create the presets
const presets = [['@babel/preset-env', { ...envOptions }]];
const presets = [['@babel/preset-env', { ...presetEnv }]];

// Create the plugins
const plugins = [];
Expand Down

0 comments on commit ef5b46f

Please sign in to comment.