Webpack:无法在javascript文件中要求pug

时间:2017-07-19 18:05:01

标签: javascript webpack pug webpack-2 html-webpack-plugin

我们在项目和Webpack 1中使用Jade模板进行捆绑。最近我们被要求更新Webpack和Jade(现在是Pug)。 .pug文件已成功转换为HTML,但每当我们在Javascript中尝试require .pug文件时,它会抛出以下错误:

控制台中

错误

ERROR in ./src/commerce/components/myComponent/myTemplate.pug
Module build failed: /Applications/MAMP/htdocs/demo-app/src/commerce/components/myComponent/myTemplate.pug:1
module.exports = "<div class=\"container-fluid\"><div class=\"row\"><div class=\"col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-1 col-md-10 col-md-offset-1 col-lg-10 col-lg-offset-1\"><h3 class=\"heading-text\">FORGOT SOMETHING?</h3><h2 class=\"text\">
                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid or unexpected token
    at Object.extractLoader (/Applications/MAMP/htdocs/demo-app/node_modules/extract-loader/lib/extractLoader.js:49:18) 

Angular JS文件

var template =require('./myTemplate.pug');
var myComponent =  {
    templateUrl : template,
    controller: controller,
    controllerAs: 'recentctrl',
};

webpack.config.js

{
  test: /\.pug$/,
  use: [
    'file-loader?name=[path]/[name].html',
    'extract-loader',
    'html-loader',
    'pug-html-loader?' + {
      "pretty": true,
      "exports": false
    }
  ]
}

我尝试在http://html2jade.org/上格式化PUG文件,但我仍然遇到同样的错误。

提前致谢!

0 个答案:

没有答案
相关问题