pugjs / pug-loader

Pug loader module for Webpack
MIT License
425 stars 119 forks source link

Webpack 4 issue with babel-loader as post loader #114

Open ljqx opened 6 years ago

ljqx commented 6 years ago

Hi, I'm using this loader with babel-loader as post loader of this one. But it would break for the included .pug files after upgraded to Webpack 4.

The Webpack config I'm using:

rules: {
  { test: /\.pug$/, loader: 'pug-loader' },
  { test: /\.pug$/, loader: 'babel-loader', enforce: 'post' },
}

And the pug code:

//- the included one
mixin sharedMixin()
  .blabla
//- the including one
include ./shared-mixin
+sharedMixin()

The problem behind this is this part of code assumes the loaded content is exactly string, but babel-loader would add "use strict";\n ${theString}; around it. So this part of code cannot parse it anymore.

In Webpack 3, babel-loader is not included as post loader somehow. Though this it seems to be a bug of Webpack 3 instead of feature.

Maybe we can have some more reliable way to load the file content?

If it's OK I can send a PR for this.

ljqx commented 6 years ago

Temporally I disable babel-loader as post loader issued from a .pug file.

rules: {
  { test: /\.pug$/, loader: 'pug-loader' },
  { test: /\.pug$/, issuer: /\.((?!pug).)+$/, use: 'babel-loader', enforce: 'post' },
}