0

I'm in the process of migrating from SystemJS to Webpack2 and today with SystemJS we have some modules that imported at runtime from the server and the names of the modules are only known at runtime.

We have SystemJS mapping that indicates any import "extension/" maps to "api/extension/" on the server.

I'm attempting to get this to work with Webpack2 but appears that any "import()" will only get resolved to relative to the bundled files.

Is there a way of accomplishing this with webpack2?

milbrath
  • 19
  • 2
  • I think you should either use a specific [loader](https://webpack.github.io/docs/loaders.html), or use different syntax to make Webpack omit it on build time and not resolve as a static import. It's impossible, from Webpack's point, to distinguish between static and dynamic dependency if both are invoked with "import" (or "require") syntax. – rishat Sep 29 '17 at 16:39
  • Not aware of any existing webpack loaders that make an HTTP request to server to resolve the module reference but conceptually what you are proposing is something like "import("my-module-loader!" + moduleName)" in which the the loader would make a request to a URL to resolve the module reference? In regards to comment about different syntax you mean to use something other than an "import" or "require"? – milbrath Sep 29 '17 at 19:05
  • Actually, did you maybe try [babel-plugin-async-import](https://www.npmjs.com/package/babel-plugin-async-import)? – rishat Sep 29 '17 at 21:12
  • This appears to rely on webpack knowing and creating separate chunks from the existing files even if dynamic imports. The problem I have is that after the main app is deployed, previously unknown javascript module extensions could be uploaded to server. Without re-running the application bundle, I don't believe webpack imports would resolve correctly. I suspect https://stackoverflow.com/questions/43163909/solution-load-independently-compiled-webpack-2-bundles-dynamically may be closer to what I need although appears a bit more involved than SystemJS solution. – milbrath Oct 02 '17 at 11:11

0 Answers0