A
A
Andrey2016-11-02 17:07:23
JavaScript
Andrey, 2016-11-02 17:07:23

Why does the Babel loader break another loader?

I use 2 loaders in Webpack:

loaders: [
      {
        test: /\.js$/,
        loader: 'babel?presets[]=es2015'
      },
      {
        test: /\.(nunj|nunjucks)$/,
        loader: 'nunjucks-loader'
      }
    ]

With the first, I think everything is clear. The second one handles nunjucks templates.
Without the first one, Webpack generates code like this:
(function webpackUniversalModuleDefinition(root, factory) {
    if(true)
      module.exports = factory();
    else if(typeof define === 'function' && define.amd)
      define([], factory);
    else if(typeof exports === 'object')
      exports["nunjucks"] = factory();
    else
      root["nunjucks"] = factory();
  })(this, function() {

If you include babel-loader, then the same block of code becomes this:
(function webpackUniversalModuleDefinition(root, factory) {
    if (( false ? 'undefined' : _typeof(exports)) === 'object' && ( false ? 'undefined' : _typeof(module)) === 'object') module.exports = factory();else if (true) !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));else if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') exports["nunjucks"] = factory();else root["nunjucks"] = factory();
  })(undefined, function () {

Some variables appear instead of "...this, function..." in the last line "...undefined, function..". In general, everything breaks down, nunjucks does not work.
Why is this happening? How to deal with it?
I'll be blogging for any suggestions.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question