Skip to content

Commit

Permalink
Merge pull request #13 from andrepolischuk/external-dependencies
Browse files Browse the repository at this point in the history
remove external deps from esm/cjs bundles
  • Loading branch information
andrepolischuk authored Apr 5, 2021
2 parents dc9a785 + 129b024 commit 74becbb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 32 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"prettier --write"
]
},
"dependencies": {
"babel-runtime": "^6.26.0",
"lodash.debounce": "^4.0.8",
"sane-domparser-error": "^0.2.0"
},
"devDependencies": {
"@commitlint/cli": "^7.0.0",
"@commitlint/travis-cli": "^7.0.0",
Expand All @@ -84,7 +89,6 @@
"jest-environment-jsdom": "^23.4.0",
"jsdoc": "^3.5.5",
"lint-staged": "^10.5.4",
"lodash.debounce": "^4.0.8",
"mini-css-extract-plugin": "^0.4.5",
"mockdate": "^2.0.2",
"mol-commitlint-config": "^1.1.0",
Expand All @@ -98,12 +102,10 @@
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-terser": "^1.0.1",
"sane-domparser-error": "^0.2.0",
"semantic-release": "^15.12.1",
"terser-webpack-plugin": "^1.1.0",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5",
"whatwg-fetch": "^2.0.4"
"webpack-dev-server": "^3.1.5"
}
}
27 changes: 13 additions & 14 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,15 @@ const production = process.env.NODE_ENV === 'production';
const plugins = [
sourcemaps(),
babel({
exclude: [
'../../node_modules/**',
'node_modules/**'
],
exclude: ['../../node_modules/**', 'node_modules/**'],
plugins: ['external-helpers']
}),
resolve({
customResolveOptions: {
moduleDirectory: [
'node_modules',
'../../node_modules'
]
}
}),
commonjs()
];

// NOTE: don't include external dependencies into esm/cjm bundles
const external = ['babel-runtime/regenerator', 'lodash.debounce', 'sane-domparser-error'];

// NOTE: see https://github.com/rollup/rollup/issues/408 to understand why we silences `THIS_IS_UNDEFINED` warnings
const onwarn = (warning, warn) => {
if (warning.code === 'THIS_IS_UNDEFINED') {
Expand All @@ -49,6 +41,11 @@ const config = [
},
plugins: [
...plugins,
resolve({
customResolveOptions: {
moduleDirectory: ['node_modules', '../../node_modules']
}
}),
production && terser()
]
},
Expand All @@ -60,7 +57,8 @@ const config = [
file: pkg.module,
format: 'es'
},
plugins
plugins,
external
},
{
input: 'src/index.js',
Expand All @@ -70,7 +68,8 @@ const config = [
file: pkg.main,
format: 'cjs'
},
plugins
plugins,
external
}
];

Expand Down
8 changes: 1 addition & 7 deletions src/adUnit/helpers/fetch/fetchHtml.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// eslint-disable-next-line import/no-unassigned-import
import 'whatwg-fetch';

const isValidContentType = (contentType) => {
const normalisedCT = contentType.toLowerCase();

return [
'text/plain',
'text/html'
].some((allowedType) => normalisedCT.includes(allowedType));
return ['text/plain', 'text/html'].some((allowedType) => normalisedCT.includes(allowedType));
};

const fetchHtml = async (endpoint) => {
Expand Down
3 changes: 0 additions & 3 deletions src/vastRequest/helpers/fetch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable filenames/match-exported, import/no-unassigned-import */
import 'whatwg-fetch';

const fetch = async (endpoint, options = {}) => {
const defaults = {
credentials: 'include'
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10344,10 +10344,6 @@ whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.3:
dependencies:
iconv-lite "0.4.24"

whatwg-fetch@^2.0.4:
version "2.0.4"
resolved "http://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"

whatwg-mimetype@^2.1.0, whatwg-mimetype@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
Expand Down

0 comments on commit 74becbb

Please sign in to comment.