Skip to content

Commit dfb83e2

Browse files
authored
fix(plugins): include removeProps plugin only for production mode
1 parent 827be9a commit dfb83e2

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

__tests__/index.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,14 @@ describe('babel-preset-amex', () => {
5858
it('allows options to be passed to plugins', () => {
5959
expect(preset({}, { 'preset-env': { exclude: ['@babel/plugin-transform-regenerator'] } })).toMatchSnapshot();
6060
});
61+
62+
it('in development mode, includes an array of plugins', () => {
63+
const originalEnv = process.env;
64+
process.env = { NODE_ENV: 'development' };
65+
66+
expect(preset().plugins).toEqual(expect.any(Array));
67+
expect(preset().plugins.length).toEqual(4);
68+
69+
process.env = originalEnv;
70+
});
6171
});

index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ const { browserList, legacyBrowserList } = require('./browserlist');
2525
module.exports = (api = {}, opts = {}) => {
2626
const serverOnly = opts.serverOnly || (api.env && api.env('server'));
2727
const isModern = opts.modern || (api.env && api.env('modern'));
28+
const isProduction = process.env.NODE_ENV === 'production';
29+
const plugins = [
30+
syntaxDynamicImport,
31+
proposalClassProperties,
32+
exportDefaultFrom,
33+
proposalOptionalChaining,
34+
];
35+
if (isProduction) {
36+
plugins.push(removePropTypes);
37+
}
2838

2939
const targets = {
3040
node: 'current',
@@ -53,12 +63,6 @@ module.exports = (api = {}, opts = {}) => {
5363
reactPresetOptions,
5464
],
5565
],
56-
plugins: [
57-
syntaxDynamicImport,
58-
proposalClassProperties,
59-
exportDefaultFrom,
60-
proposalOptionalChaining,
61-
removePropTypes,
62-
],
66+
plugins,
6367
};
6468
};

0 commit comments

Comments
 (0)