Skip to content

Commit

Permalink
fix: mark global as global via externalGlobals (#40)
Browse files Browse the repository at this point in the history
Using the built-in globals feature will try and do interop resolution
for requiring `window` which will break if a user has an element with an
id of `default`. This plugin does not do so and will end up removing the
lines from the browser build altogether.
  • Loading branch information
gkatsev authored Sep 21, 2021
1 parent 2dcb6c6 commit d7fda4b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const multiEntry = require('@rollup/plugin-multi-entry');
const resolve = require('@rollup/plugin-node-resolve').default;
const {terser} = require('rollup-plugin-terser');
const istanbul = require('rollup-plugin-istanbul');
const externalGlobals = require('rollup-plugin-external-globals');
const path = require('path');

const babelConfig = require('@videojs/babel-config/es.js');
Expand Down Expand Up @@ -62,10 +63,7 @@ const MINJS_REGEX = /^.+\.min\.js$/;
const ORDERED_DEFAULTS = {
globals: () => ({
browser: {
'video.js': 'videojs',
'global': 'window',
'global/window': 'window',
'global/document': 'document'
'video.js': 'videojs'
},
module: {
'video.js': 'videojs'
Expand All @@ -92,6 +90,7 @@ const ORDERED_DEFAULTS = {
'resolve',
'json',
'commonjs',
'externalGlobals',
'babel'
],
module: [
Expand Down Expand Up @@ -135,6 +134,11 @@ const ORDERED_DEFAULTS = {
commonjs: commonjs({sourceMap: false}),
jsonResolve: resolve({extensions: ['.json']}),
json: json(),
externalGlobals: externalGlobals({
'global': 'window',
'global/window': 'window',
'global/document': 'document'
}),
multiEntry: multiEntry({exports: false}),
resolve: resolve({
mainFields: ['browser', 'module', 'jsnext:main', 'main'],
Expand Down
27 changes: 27 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@rollup/plugin-multi-entry": "^4.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@videojs/babel-config": "^0.2.0",
"rollup-plugin-external-globals": "^0.6.1",
"rollup-plugin-istanbul": "^2.0.1",
"rollup-plugin-terser": "^7.0.2"
},
Expand Down

0 comments on commit d7fda4b

Please sign in to comment.