Merge pull request #8781 from Rob--W/systemjs-__non_webpack_require__
__non_webpack_require__ -> require in SystemJS
This commit is contained in:
commit
81172b571f
@ -39,6 +39,23 @@
|
|||||||
typeof crypto !== 'undefined' &&
|
typeof crypto !== 'undefined' &&
|
||||||
typeof crypto.subtle !== 'undefined';
|
typeof crypto.subtle !== 'undefined';
|
||||||
|
|
||||||
|
// When we create a bundle, webpack is run on the source and it will replace
|
||||||
|
// require with __webpack_require__. When we want to use the real require,
|
||||||
|
// __non_webpack_require__ has to be used.
|
||||||
|
// In this target, we don't create a bundle, so we have to replace the
|
||||||
|
// occurences of __non_webpack_require__ ourselves.
|
||||||
|
function babelPluginReplaceNonWebPackRequire(babel) {
|
||||||
|
return {
|
||||||
|
visitor: {
|
||||||
|
Identifier(path, state) {
|
||||||
|
if (path.node.name === '__non_webpack_require__') {
|
||||||
|
path.replaceWith(babel.types.identifier('require'));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
SystemJS.config({
|
SystemJS.config({
|
||||||
packages: {
|
packages: {
|
||||||
'': {
|
'': {
|
||||||
@ -58,6 +75,7 @@
|
|||||||
esModule: true,
|
esModule: true,
|
||||||
babelOptions: {
|
babelOptions: {
|
||||||
es2015: false,
|
es2015: false,
|
||||||
|
plugins: [babelPluginReplaceNonWebPackRequire],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -108,6 +108,21 @@ describe('SVGGraphics', function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it('should fail require("zlib") unless in Node.js', function() {
|
||||||
|
function testFunc() {
|
||||||
|
__non_webpack_require__('zlib');
|
||||||
|
}
|
||||||
|
// Verifies that the script loader replaces __non_webpack_require__ with
|
||||||
|
// require.
|
||||||
|
expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
|
||||||
|
if (isNodeJS()) {
|
||||||
|
expect(testFunc).not.toThrow();
|
||||||
|
} else {
|
||||||
|
// require not defined, require('zlib') not a module, etc.
|
||||||
|
expect(testFunc).toThrow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('should produce a reasonably small svg:image', function(done) {
|
it('should produce a reasonably small svg:image', function(done) {
|
||||||
if (!isNodeJS()) {
|
if (!isNodeJS()) {
|
||||||
pending('zlib.deflateSync is not supported in non-Node environments.');
|
pending('zlib.deflateSync is not supported in non-Node environments.');
|
||||||
|
Loading…
Reference in New Issue
Block a user