Skip to content

Commit

Permalink
Update babel build to transform modeules to commonjs
Browse files Browse the repository at this point in the history
  • Loading branch information
nkbt committed Nov 15, 2019
1 parent a45d160 commit 6f886ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["@babel/env", { "modules": false, "loose": true }],
["@babel/env", { "modules": "commonjs", "loose": true }],
"@babel/flow",
"@babel/react"
],
Expand Down
20 changes: 15 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ const globals = {
const external = id =>
!id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/');

const getBabelOptions = ({ useESModules }) => ({
const getBabelOptions = () => ({
babelrc: false,
exclude: '**/node_modules/**',
runtimeHelpers: true,
plugins: [['@babel/transform-runtime', { useESModules }]],
plugins: [
['@babel/proposal-class-properties', { loose: true }],
['transform-react-remove-prop-types', { mode: 'unsafe-wrap' }],
['@babel/transform-runtime', { useESModules: true }],
],
presets: [
['@babel/env', { modules: false, loose: true }],
'@babel/flow',
'@babel/react',
],
});

const commonjsOptions = {
Expand All @@ -33,7 +43,7 @@ export default [
external: Object.keys(globals),
plugins: [
nodeResolve(),
babel(getBabelOptions({ useESModules: true })),
babel(getBabelOptions()),
commonjs(commonjsOptions),
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
sizeSnapshot(),
Expand All @@ -46,7 +56,7 @@ export default [
external: Object.keys(globals),
plugins: [
nodeResolve(),
babel(getBabelOptions({ useESModules: true })),
babel(getBabelOptions()),
commonjs(commonjsOptions),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
sizeSnapshot(),
Expand All @@ -58,6 +68,6 @@ export default [
input,
output: { file: pkg.module, format: 'esm' },
external,
plugins: [babel(getBabelOptions({ useESModules: true })), sizeSnapshot()],
plugins: [babel(getBabelOptions()), sizeSnapshot()],
},
];

0 comments on commit 6f886ea

Please sign in to comment.