Skip to content

SystemJS import from Webpack bundle #2092

@davispuh

Description

@davispuh

I can't figure out how to import modules from Webpack bundle.

Basically I have several libraries using AMD.
If I use import map

{
    "imports": {
        "jquery": "./jquery.js",
        "somelib": "./somelib.js",
    }
}

Then System.import("somelib") works fine.

But if I bundle it with Webpack

module.exports = {
    entry: [ "jquery.js", "somelib.js" ],
    output: {
        libraryTarget: "system",
        filename: "bundle.js"
    },
    module: {
        rules: [{
                parser: {
                    amd: true,
                    commonjs: true,
                    system: false
               }
        }]
    },
    resolve: {
        alias: {
			"jquery": "jquery.js"
			"somelib": "somelib.js"
		}
    }
};

Then System.import("somelib") doesn't load it from Webpack bundle.
In generated bundle.js there is

System.register([], function(__WEBPACK_DYNAMIC_EXPORT__) {
	return {
		execute: function() {
			__WEBPACK_DYNAMIC_EXPORT__(
/******/ (function(modules) {
[...]

But looks like names aren't registered.
Note that I don't want to System.import("bundle") but individual library, because whole bundle is already loaded by regular <script> and I don't want to load that dynamically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions