【发布时间】:2017-12-25 10:26:16
【问题描述】:
我相信它应该比看起来更容易。我是 webpack 的新手,我花了几个小时试图弄清楚我缺少什么。
我需要的只是将 LESS 预处理器添加到 webpack.config.js。 CSS 规则已经存在并且有效:
module: {
rules: [
{ test: /\.css$/, use: ['to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize'] }
]
}
但是一旦为 less-loader 添加了非常基本的规则,例如 { test: /\.less$/, use: 'less-loader' }(我已经尝试了该规则的多种变体),我的 LESS 样式表上总是会出现错误 You may need an appropriate loader to handle this file type。真的吗?我提供了loader,还需要什么?
我正在尝试在 Angular 组件中使用我的样式表,如下所示:
@Component({
styles: [require('./my.component.less')]
})
确切的错误:
NodeInvocationException: Prerendering failed because of error: Error: Module
parse failed: Unexpected token (1:1)
You may need an appropriate loader to handle this file type.
// few lines of my styleshhet, so it was indeed located properly
// call stack ... at Object.module.exports ... at __webpack_require__...
【问题讨论】:
标签: angular webpack less-loader