Skip to content

Commit

Permalink
feat(Bundle): Scope ie11 polyfills
Browse files Browse the repository at this point in the history
Don't allow polyfils to affect global scope
  • Loading branch information
cblanc committed Feb 11, 2021
1 parent ec27d24 commit cf03ae9
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 24 deletions.
57 changes: 57 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@
"@open-wc/karma-esm": "~4.0.0",
"@rollup/plugin-babel": "~5.2.2",
"@rollup/plugin-commonjs": "~17.1.0",
"@rollup/plugin-inject": "~4.0.2",
"@rollup/plugin-node-resolve": "~11.1.0",
"@types/mocha": "~8.2.0",
"core-js": "~3.8.2",
"core-js-pure": "~3.8.3",
"cypress": "~6.4.0",
"dotenv": "~8.2.0",
"http-server": "~0.12.3",
Expand All @@ -82,11 +84,12 @@
"karma-typescript": "~5.2.0",
"mocha": "~8.2.1",
"prettier": "~2.2.1",
"promise-polyfill": "~8.2.0",
"puppeteer": "~7.0.4",
"rollup": "~2.38.5",
"rollup-plugin-terser": "~7.0.2",
"semantic-release": "~17.3.1",
"size-limit": "^4.9.2",
"size-limit": "~4.9.2",
"ts-node": "~9.1.1",
"typescript": "~4.1.3"
},
Expand Down
47 changes: 24 additions & 23 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import "core-js";
import babel from "@rollup/plugin-babel";
import { terser } from "rollup-plugin-terser";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import inject from "@rollup/plugin-inject";

export const polyfills = {
Promise: "promise-polyfill",
Set: "core-js-pure/features/set",
"Object.assign": "core-js-pure/features/object/assign",
};

import { version, dependencies, license } from "./package.json";

Expand Down Expand Up @@ -39,7 +45,8 @@ const include = [
"node_modules/@ideal-postcodes/core-interface/esm/**",
"node_modules/@ideal-postcodes/jsutil/esm/**",
"node_modules/capitalise-post-town/dist/**",
"node_modules/lodash-es/debounce.js",
"node_modules/lodash/debounce.js",
"node_modules/core-js-pure/**/*",
];

const context = "window";
Expand All @@ -58,11 +65,16 @@ export default [
exports: "named",
},
plugins: [
resolve({ browser: true }),
resolve({
preferBuiltins: true,
dedupe: ["@ideal-postcodes/jsutil"],
mainFields: ["browser", "module", "main"],
browser: true,
}),
commonjs(),
inject(polyfills),
babel({
babelrc: false,
ignore: [/core-js/],
include,
sourceMap,
babelHelpers,
Expand All @@ -76,10 +88,6 @@ export default [
chrome: "61",
safari: "11",
},
modules: false,
spec: true,
useBuiltIns: "usage",
corejs: 3,
},
],
],
Expand All @@ -102,28 +110,21 @@ export default [
exports: "named",
},
plugins: [
resolve({ browser: true }),
resolve({
preferBuiltins: true,
dedupe: ["@ideal-postcodes/jsutil"],
mainFields: ["browser", "module", "main"],
browser: true,
}),
commonjs(),
inject(polyfills),
babel({
babelrc: false,
ignore: [/core-js/],
include,
babelHelpers,
sourceMap,
presets: [
[
"@babel/preset-env",
{
targets: {
ie: "11",
},
modules: false,
spec: true,
useBuiltIns: "usage",
corejs: 3,
},
],
],
presets: [["@babel/preset-env", { targets: { ie: "11" } }]],
}),
terser(terserConfig),
],
Expand Down

0 comments on commit cf03ae9

Please sign in to comment.