webpack-contrib / imports-loader

Imports Loader
MIT License
520 stars 63 forks source link

imports-loader breaks "use strict" #13

Closed justjake closed 4 years ago

justjake commented 9 years ago

Context

somewhere in my dependency graph, I have a file with a format like this:

if (typeof define === 'function') {
  // do some AMD stuff with `define`
} else {
 var foo = require('etc etc etc');
}

If webpack parses this without imports-loader?define=>false, then it tries to resolve a bunch of AMD modules that I don't have, since I am using npm and commonjs. So I have this in my config file:

module: {
  loaders: [
    // try to totally disable AMD shit since we're just commonjs here
    // this gets "universal" modules to skip trying to use AMD, since we
    // don't have any of the dependecies set up in that case.
    // @see https://github.com/webpack/imports-loader#disable-amd
    {
      test: /./,
      loader: 'imports-loader?define=>false',
    },
    // ... more loaders
  ]
}

Issue

However, I see that imports-loader is inserting variables before any "use strict"; directives in my modules or my dependencies: sadness occurs here

is there a better way to disable AMD in webpack? Is there a way to move "use strict"; above the imports-injected variables?

evoyy commented 9 years ago

+1, same issue. Thanks to jake for finding the problem.

dfguo commented 8 years ago

Having the same issue too. Took some time to figure that this is the issue.

mikeapr4 commented 8 years ago

Use the https://www.npmjs.com/package/strict-loader

module: {
  loaders: [
    {
      test: /./,
      loader: 'strict!imports-loader?define=>false',
    },
  ]
}