Skip to content

Commit

Permalink
fix(plugins): include removeProps plugin only for production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
algbeta committed Jun 17, 2021
1 parent 827be9a commit dfb83e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
10 changes: 10 additions & 0 deletions __tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ describe('babel-preset-amex', () => {
it('allows options to be passed to plugins', () => {
expect(preset({}, { 'preset-env': { exclude: ['@babel/plugin-transform-regenerator'] } })).toMatchSnapshot();
});

it('in development mode, includes an array of plugins', () => {
const originalEnv = process.env;
process.env = { NODE_ENV: 'development' };

expect(preset().plugins).toEqual(expect.any(Array));
expect(preset().plugins.length).toEqual(4);

process.env = originalEnv;
});
});
18 changes: 11 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ const { browserList, legacyBrowserList } = require('./browserlist');
module.exports = (api = {}, opts = {}) => {
const serverOnly = opts.serverOnly || (api.env && api.env('server'));
const isModern = opts.modern || (api.env && api.env('modern'));
const isProduction = process.env.NODE_ENV === 'production';
const plugins = [
syntaxDynamicImport,
proposalClassProperties,
exportDefaultFrom,
proposalOptionalChaining,
];
if (isProduction) {
plugins.push(removePropTypes);
}

const targets = {
node: 'current',
Expand Down Expand Up @@ -53,12 +63,6 @@ module.exports = (api = {}, opts = {}) => {
reactPresetOptions,
],
],
plugins: [
syntaxDynamicImport,
proposalClassProperties,
exportDefaultFrom,
proposalOptionalChaining,
removePropTypes,
],
plugins,
};
};

0 comments on commit dfb83e2

Please sign in to comment.