Skip to content

Commit ccfaa65

Browse files
committed
Optimize could for production usage
1 parent ca3722f commit ccfaa65

File tree

8 files changed

+583
-472
lines changed

8 files changed

+583
-472
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
],
66
"plugins": [
77
"transform-object-rest-spread",
8-
"transform-class-properties"
8+
"transform-class-properties",
9+
["transform-react-remove-prop-types", { "mode": "wrap" }]
910
]
1011
}

dist/react-tabs.js

Lines changed: 546 additions & 468 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-tabs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-tabs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-tabs.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"babel-loader": "^6.2.4",
4848
"babel-plugin-transform-class-properties": "^6.11.5",
4949
"babel-plugin-transform-object-rest-spread": "^6.8.0",
50+
"babel-plugin-transform-react-remove-prop-types": "^0.4.0",
5051
"babel-preset-env": "^1.3.3",
5152
"babel-preset-react": "^6.5.0",
5253
"cross-env": "^4.0.0",

webpack.build.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,36 @@ const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
66

77
let COMPONENT_FILE = 'react-tabs';
88
const plugins = [];
9+
const babelOptions = {};
910

1011
if (process.env.MINIFY) {
1112
plugins.push(new UglifyJsPlugin({ sourceMap: true }));
13+
plugins.push(new webpack.DefinePlugin({
14+
'process.env.NODE_ENV': JSON.stringify('production')
15+
}));
1216
COMPONENT_FILE += '.min';
17+
18+
babelOptions.plugins = [
19+
function(babel) {
20+
return {
21+
visitor: {
22+
ImportDeclaration(path) {
23+
// Remove all propType imports in min bundle
24+
if (
25+
path.node.source.value.indexOf('helpers/propTypes') > -1 ||
26+
path.node.source.value === 'prop-types'
27+
) {
28+
path.remove();
29+
}
30+
}
31+
}
32+
};
33+
}
34+
];
35+
} else {
36+
plugins.push(new webpack.DefinePlugin({
37+
'process.env.NODE_ENV': JSON.stringify('development')
38+
}));
1339
}
1440

1541
module.exports = {
@@ -46,6 +72,7 @@ module.exports = {
4672
test: /\.js$/,
4773
exclude: /node_modules/,
4874
loader: 'babel-loader',
75+
options: babelOptions,
4976
},
5077
],
5178
},

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,10 @@ babel-plugin-transform-react-jsx@^6.24.1:
734734
babel-plugin-syntax-jsx "^6.8.0"
735735
babel-runtime "^6.22.0"
736736

737+
babel-plugin-transform-react-remove-prop-types@^0.4.0:
738+
version "0.4.0"
739+
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-remove-prop-types/-/babel-plugin-transform-react-remove-prop-types-0.4.0.tgz#f63840e7953563d661be8c647b094d74d7363f17"
740+
737741
babel-plugin-transform-regenerator@^6.22.0:
738742
version "6.24.1"
739743
resolved "https://registry.yarnpkg.com/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.24.1.tgz#b8da305ad43c3c99b4848e4fe4037b770d23c418"

0 commit comments

Comments
 (0)