Skip to content

Commit

Permalink
Improve babel config
Browse files Browse the repository at this point in the history
- enable loose mode for env and class properties
- reuse helpers from babel runtime instead of duplicating them
  • Loading branch information
TrySound committed Aug 11, 2018
1 parent c0897fe commit 1a77838
Show file tree
Hide file tree
Showing 5 changed files with 479 additions and 443 deletions.
4 changes: 2 additions & 2 deletions .babelrc
@@ -1,11 +1,11 @@
{
"presets": [
["@babel/env", { "modules": false }],
["@babel/env", { "modules": false, "loose": true }],
"@babel/flow",
"@babel/react"
],
"plugins": [
"@babel/proposal-class-properties"
["@babel/proposal-class-properties", { "loose": true }]
],
"env": {
"test": {
Expand Down
24 changes: 12 additions & 12 deletions .size-snapshot.json
@@ -1,25 +1,25 @@
{
"dist/react-motion.js": {
"bundled": 83106,
"minified": 24575,
"gzipped": 7184
"bundled": 76899,
"minified": 22572,
"gzipped": 6605
},
"dist/react-motion.min.js": {
"bundled": 59713,
"minified": 17814,
"gzipped": 5188
"bundled": 53506,
"minified": 15814,
"gzipped": 4568
},
"dist/react-motion.esm.js": {
"bundled": 49359,
"minified": 18664,
"gzipped": 4427,
"bundled": 42991,
"minified": 14453,
"gzipped": 3551,
"treeshaked": {
"rollup": {
"code": 14625,
"import_statements": 97
"code": 12421,
"import_statements": 203
},
"webpack": {
"code": 15824
"code": 13744
}
}
}
Expand Down
18 changes: 10 additions & 8 deletions package.json
Expand Up @@ -8,14 +8,15 @@
"react": "^0.14.9 || ^15.3.0 || ^16.0.0"
},
"devDependencies": {
"@babel/cli": "^7.0.0-beta.56",
"@babel/core": "^7.0.0-beta.56",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.56",
"@babel/plugin-transform-modules-commonjs": "^7.0.0-beta.56",
"@babel/polyfill": "^7.0.0-beta.56",
"@babel/preset-env": "^7.0.0-beta.56",
"@babel/preset-flow": "^7.0.0-beta.56",
"@babel/preset-react": "^7.0.0-beta.56",
"@babel/cli": "^7.0.0-rc.1",
"@babel/core": "^7.0.0-rc.1",
"@babel/plugin-proposal-class-properties": "^7.0.0-rc.1",
"@babel/plugin-transform-modules-commonjs": "^7.0.0-rc.1",
"@babel/plugin-transform-runtime": "^7.0.0-rc.1",
"@babel/polyfill": "^7.0.0-rc.1",
"@babel/preset-env": "^7.0.0-rc.1",
"@babel/preset-flow": "^7.0.0-rc.1",
"@babel/preset-react": "^7.0.0-rc.1",
"babel-eslint": "^9.0.0-beta.3",
"babel-loader": "^8.0.0-beta.4",
"codemirror": "^5.5.0",
Expand Down Expand Up @@ -107,6 +108,7 @@
],
"license": "MIT",
"dependencies": {
"@babel/runtime": "7.0.0-rc.1",
"performance-now": "^2.1.0",
"prop-types": "^15.5.8",
"raf": "^3.1.0"
Expand Down
20 changes: 11 additions & 9 deletions rollup.config.js
Expand Up @@ -16,13 +16,15 @@ const globals = {
const external = id =>
!id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/');

const getBabelOptions = () => ({
const getBabelOptions = ({ useESModules }) => ({
exclude: '**/node_modules/**',
runtimeHelpers: true,
plugins: [['@babel/transform-runtime', { useESModules }]],
});

const getCommonjsOptions = () => ({
const commonjsOptions = {
include: '**/node_modules/**',
});
};

export default [
{
Expand All @@ -31,8 +33,8 @@ export default [
external: Object.keys(globals),
plugins: [
nodeResolve(),
babel(getBabelOptions()),
commonjs(getCommonjsOptions()),
babel(getBabelOptions({ useESModules: true })),
commonjs(commonjsOptions),
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
sizeSnapshot(),
],
Expand All @@ -44,8 +46,8 @@ export default [
external: Object.keys(globals),
plugins: [
nodeResolve(),
babel(getBabelOptions()),
commonjs(getCommonjsOptions()),
babel(getBabelOptions({ useESModules: true })),
commonjs(commonjsOptions),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
sizeSnapshot(),
uglify(),
Expand All @@ -56,13 +58,13 @@ export default [
input,
output: { file: pkg.module, format: 'esm' },
external,
plugins: [babel(getBabelOptions()), sizeSnapshot()],
plugins: [babel(getBabelOptions({ useESModules: true })), sizeSnapshot()],
},

{
input,
output: { file: pkg.main, format: 'cjs' },
external,
plugins: [babel(getBabelOptions())],
plugins: [babel(getBabelOptions({ useESModules: false }))],
},
];

0 comments on commit 1a77838

Please sign in to comment.