diff --git a/packages/babel-preset-base/README.md b/packages/babel-preset-base/README.md index c83a766d9..00e92f39e 100644 --- a/packages/babel-preset-base/README.md +++ b/packages/babel-preset-base/README.md @@ -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 + }, }, ], }; @@ -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. diff --git a/packages/babel-preset-base/package.json b/packages/babel-preset-base/package.json index f4c8f9a0f..aff2d42ef 100644 --- a/packages/babel-preset-base/package.json +++ b/packages/babel-preset-base/package.json @@ -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", @@ -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" }, @@ -32,5 +39,8 @@ }, "publishConfig": { "access": "public" + }, + "devDependencies": { + "@babel/core": "^7.1.0" } } diff --git a/packages/babel-preset-base/src/__tests__/preset.spec.js b/packages/babel-preset-base/src/__tests__/preset.spec.js index 328e7723a..b02ee2178 100644 --- a/packages/babel-preset-base/src/__tests__/preset.spec.js +++ b/packages/babel-preset-base/src/__tests__/preset.spec.js @@ -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'); @@ -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]); }); }); diff --git a/packages/babel-preset-base/src/preset.js b/packages/babel-preset-base/src/preset.js index 4343874f0..f447f2254 100644 --- a/packages/babel-preset-base/src/preset.js +++ b/packages/babel-preset-base/src/preset.js @@ -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 = [];