survivejs / webpack-book

From apprentice to master (CC BY-NC-ND)
https://survivejs.com/webpack/
2.42k stars 319 forks source link

Dealing with global imports/exports #15

Closed bebraw closed 8 years ago

bebraw commented 9 years ago

Just to quote @jeffijoe at Gitter (sample conf):

Loaders:

    {
      test: /moxie\-plupload/,
      loader: 'imports?mOxie=moxie!exports?window.plupload'
    }, {
      test: /moxie/i,
      loader: 'exports?this.mOxie'
    }

Alias:

      moxie: 'plupload/js/moxie.js',
      'moxie-plupload': 'plupload/js/plupload.dev.js',

ProvidePlugin:

mOxie: 'moxie'
hosain-cse2 commented 9 years ago

Hi, after setting the above configuration I am now getting the following error during the webpack build,

ERROR in ./src/test/upload-file.jsx Module not found: Error: Cannot resolve module 'exports' in /home/hbashar/Projects/DOX/server/src/brainloop/doxweb/client/src/test @ ./src/test/upload-file.jsx 23:0-16

can you please tell me why I am getting this error/

bebraw commented 9 years ago

@hosain-cse2 Can you provide more information? Which module are you trying to use in your project?

hosain-cse2 commented 9 years ago

That error is gone now. I was missing the "exports-loader" module. After installing it with my project it is working now. But I am getting another error now. The page I was trying to introduce the plupload I import is as following,

require('moxie-plupload');

and when I an loading the page in the browser in the console i am getting the following errors,

in Chrome: Uncaught TypeError: Cannot read property 'moxie' of undefined

im FireFox: TypeError: target is undefined ...i=0; fi < fragments.length - 1; ++fi) {if(target[fragments[fi]] === undefined){t...

Can you tell me why I am getting this error? Do I have to import it in another way in my page?

bebraw commented 9 years ago

It's very hard for me to say. Can you set up a minimal demo project to study?

JFusco commented 9 years ago

@hosain-cse2 - Since i saw plupload was being exported to the window object - I got this working by following the sample config at the top and adding this to my file:

import plupload from 'moxie-plupload';

//-- Plupload is available!
console.log(window.plupload);
phinett commented 8 years ago

I too am getting the Uncaught TypeError: Cannot read property 'moxie' of undefined issue, i have followed the example config above but can't get past this.

I think this is related just to the moxie.js script because if i just try to require('moxie') on my page script without require('moxie-plupload') i still get the exact same error.

Did anybody got this to work in the end with webpack?

wadezha commented 8 years ago

thank you, i successed! because moxie-plupload exports is a window object, so your must add the code require("moxie-plupload") in your main page, and in other page your use plupload object direct, Enlish not good , heihei