I have a working configuration for webpack with Angular, so that the scss files are inserted into the bundle.js
{
test: /\.scss$/,
use: ['raw-loader', 'resolve-url-loader', 'sass-loader?sourceMap']
}
but then I want instead to get a single css file with all the scss in the app, so I'm using ExtractTextPlugin like this
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: ['raw-loader', 'resolve-url-loader', 'sass-loader?sourceMap'],
use: ['resolve-url-loader', 'sass-loader?sourceMap']
})
}
Now, I'm not using 'raw-loader' because I understand the files don´t have to be inserted into the bundle.js, but the I get an error in compilation.
ERROR in ./~/resolve-url-loader!./~/sass-loader/lib/loader.js?sourceMap!./app/app.component.scss
Module parse failed: /Users/david/Documents/work/my-angular-seed/node_modules/resolve-url-loader/index.js!/Users/david/Documents/work/my-angular-seed/node_
modules/sass-loader/lib/loader.js?sourceMap!/Users/david/Documents/work/my-angular-seed/app/app.component.scss Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| .app {
| border: 1px solid red;
| }
If I use raw-loader, build goes fine but then I get an error when loading index.html
Uncaught Error: Expected 'styles' to be an array of strings.
Does anyone know how to fix this and why it's happening? Thanks!
EDIT
I've been checking a bit more and I think I know what the issue is, but I don´t know how to fix it.
If I use this configuration
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
the app.css is generated, so all good. But then if I check the bundle.js the component has been transformed into this
AppComponent = __decorate([
core_1.Component({
selector: 'app-root',
styles: [__webpack_require__(23)],
template: "\n <div class=\"app\">\n Hello!\n </div>\n "
})
], AppComponent);
And if I check the module 23 I see that it's empty
/* 23 */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
So I'm guessing this is what angular complains about, styles is an empty array. What should be done here I think is remove completely the styles tag, as the css are used as an external separated file, right? is there a way to fix this?