From f25cbe293b330e2e341860da07455903bd2b23b8 Mon Sep 17 00:00:00 2001 From: David Fremont Date: Fri, 16 Feb 2018 12:47:06 +0100 Subject: [PATCH] use of rollup-plugin-inject to avoid expecting three to provide a default export when importing non-module three examples. see issue https://github.com/videojs/videojs-vr/issues/50 --- package-lock.json | 29 +++++++++++++++++++++++++++++ package.json | 1 + scripts/modules.rollup.config.js | 5 +++++ scripts/rollup-replace.js | 6 +++--- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 77fd83a8..7d894503 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6500,6 +6500,35 @@ } } }, + "rollup-plugin-inject": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-inject/-/rollup-plugin-inject-2.0.0.tgz", + "integrity": "sha1-iTTZilsNstBe/O4qwGoXCkxwsEQ=", + "dev": true, + "requires": { + "acorn": "4.0.13", + "estree-walker": "0.2.1", + "magic-string": "0.16.0", + "rollup-pluginutils": "1.5.2" + }, + "dependencies": { + "acorn": { + "version": "4.0.13", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-4.0.13.tgz", + "integrity": "sha1-EFSVrlNh1pe9GVyCUZLhrX8lN4c=", + "dev": true + }, + "magic-string": { + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.16.0.tgz", + "integrity": "sha1-lw67DacZMwEoX7GqZQ85vdgetFo=", + "dev": true, + "requires": { + "vlq": "0.2.3" + } + } + } + }, "rollup-plugin-json": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/rollup-plugin-json/-/rollup-plugin-json-2.3.0.tgz", diff --git a/package.json b/package.json index 496f42d3..fc8b625f 100644 --- a/package.json +++ b/package.json @@ -123,6 +123,7 @@ "rollup": "^0.50", "rollup-plugin-babel": "^2.7.1", "rollup-plugin-commonjs": "^8.0.2", + "rollup-plugin-inject": "^2.0.0", "rollup-plugin-json": "^2.1.1", "rollup-plugin-multi-entry": "^2.0.1", "rollup-plugin-node-resolve": "^3.0.0", diff --git a/scripts/modules.rollup.config.js b/scripts/modules.rollup.config.js index 606d8378..16d373de 100644 --- a/scripts/modules.rollup.config.js +++ b/scripts/modules.rollup.config.js @@ -10,6 +10,7 @@ import json from 'rollup-plugin-json'; import replace from './rollup-replace'; import commonjs from 'rollup-plugin-commonjs'; import resolve from 'rollup-plugin-node-resolve'; +import inject from 'rollup-plugin-inject'; export default { name: 'videojsVr', @@ -58,6 +59,10 @@ export default { 'external-helpers', 'transform-object-assign' ] + }), + inject({ + include: ['node_modules/three/examples/js/**'], + THREE: ['three', '*'] }) ] }; diff --git a/scripts/rollup-replace.js b/scripts/rollup-replace.js index 1b730742..224cdf85 100644 --- a/scripts/rollup-replace.js +++ b/scripts/rollup-replace.js @@ -5,13 +5,13 @@ export default function(options) { return replace(Object.assign({ 'include': ['node_modules/three/examples/js/**'], 'delimiters': ['', ''], - 'THREE.VRControls =': "var THREE = require('three');var VRControls;\nmodule.exports = VRControls =", + 'THREE.VRControls =': 'var VRControls;\nmodule.exports = VRControls =', 'THREE.VRControls': 'VRControls', - 'THREE.VREffect =': "var THREE = require('three');var VREffect;\nmodule.exports = VREffect =", + 'THREE.VREffect =': 'var VREffect;\nmodule.exports = VREffect =', 'THREE.VREffect': 'VREffect', - 'THREE.OrbitControls =': "var THREE = require('three');var OrbitControls;\nmodule.exports = OrbitControls =", + 'THREE.OrbitControls =': 'var OrbitControls;\nmodule.exports = OrbitControls =', 'THREE.OrbitControls': 'OrbitControls' }, options || {})); }