Jacinto
Jacinto

Reputation: 180

Webpack use AMD define

I'm trying to convert my company project, from JSPM and systemJS to webpack. So i started a new project from scratch and instaled basic configuration.

I need to include in the project a old package that was build by former collegues. The package was develop in Jquery and use the AMD define method.

So I searched and found imports-loader.

In my webpack configuration I have:

{
      test: path.resolve(__dirname, 'vendor/module/module.js'),
      loader: "imports-loader?this=>window&define=>false"
},

And in my code I have the follow:

import Module from 'module';
new Module.WindowManager(arg1, arg2);

When I run the webpack, I got this error:

Uncaught Error: module/wm/window missing module/core/emitter

In the module that im trying to use the module/core/emitter are use here:

define('module/wm/window', 
    ['module/core/emitter'], function (Emitter) { ... });

Upvotes: 0

Views: 1423

Answers (1)

hendrathings
hendrathings

Reputation: 3765

After reproduce you code, use amd with webpack it's fine.

Your code just miss these id dependency deskum/core/emitter and deskum/core/promise. Make sure check those id have define. I have try remove those dependency and it's work

enter image description here

as you can see the screenshot, I can set Deskum to property class this.deskum from window but this.deskum.Window() have throw error because I removed "deskum/core/emitter","deskum/core/promise" at deskum.min.js.

Just make sure all dependency included, see documentation.

Upvotes: 1

Related Questions