Skip to content

Commit

Permalink
fix(build): update @rollup/plugin-babel usage to fix UMD build (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
wKovacs64 authored Dec 25, 2020
1 parent 18c893a commit 6d90a20
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
15 changes: 3 additions & 12 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
const test = process.env.NODE_ENV === 'test';
// Note: this Babel config file is only used by Jest (babel-jest) when running
// tests. Babel configuration for build outputs is in rollup.config.js.

module.exports = {
plugins: ['babel-plugin-annotate-pure-calls'],
presets: [
[
'@babel/preset-env',
{
modules: test ? 'commonjs' : false,
targets: {
browsers: ['> 1%', 'last 2 versions'],
node: '12.16',
},
},
],
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
};
38 changes: 26 additions & 12 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import typescript from '@rollup/plugin-typescript';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';

const supportedNodeVersion = '12.16';
const inputs = glob.sync('src/**/*.ts', {
ignore: [
'**/__mocks__/**',
Expand All @@ -16,13 +17,8 @@ const inputs = glob.sync('src/**/*.ts', {
'**/*.d.ts',
],
});
const umdName = 'hibp';
const external = (id) => !/^(\.|\/|[a-z]:\\)/i.test(id);
const babelOpts = {
exclude: 'node_modules/**',
extensions: ['.js', '.ts'],
babelHelpers: 'bundled',
};
const umdName = 'hibp';
const typescriptOpts = {
exclude: ['**/*.d.ts'],
declaration: false,
Expand Down Expand Up @@ -53,8 +49,11 @@ export default [
external,
plugins: [
json({ preferConst: true }),
babel(babelOpts),
typescript(typescriptOpts),
getBabelOutputPlugin({
plugins: ['babel-plugin-annotate-pure-calls'],
presets: [['@babel/env', { targets: { node: supportedNodeVersion } }]],
}),
],
},

Expand All @@ -73,8 +72,11 @@ export default [
external,
plugins: [
json({ preferConst: true }),
babel(babelOpts),
typescript(typescriptOpts),
getBabelOutputPlugin({
plugins: ['babel-plugin-annotate-pure-calls'],
presets: [['@babel/env', { targets: { node: supportedNodeVersion } }]],
}),
],
},

Expand Down Expand Up @@ -102,18 +104,30 @@ export default [
input: 'src/hibp.ts',
output: {
file: 'dist/browser/hibp.umd.js',
format: 'umd',
name: umdName,
format: 'esm',
sourcemap: true,
indent: false,
},
plugins: [
json({ preferConst: true }),
babel(babelOpts),
nodeResolve(nodeResolveOpts),
commonjs(),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
typescript(typescriptOpts),
getBabelOutputPlugin({
moduleId: umdName,
presets: [
[
'@babel/env',
{
modules: 'umd',
targets: {
browsers: ['> 1%', 'last 2 versions'],
},
},
],
],
}),
terser(terserOpts),
],
},
Expand Down

0 comments on commit 6d90a20

Please sign in to comment.