I've got a simple app working with Angular 2 and Webpack 2, using sass for templates and angular2-template-loader so I can use templateUrl
and styleUrls
instead of using require
in my components.
Now I want to have a separate css file I can link to directly on my page. This will use sass and include bootstrap and bootswatch. I want that to be separate so my page can display something in the same styles before angular bootstraps. Here are my loaders:
{ test: /\.ts$/, loaders: ['awesome-typescript-loader', 'angular2-template-loader'] },
{ test: /\.html$/, loader: 'raw' }, // for templates, need 'raw'
{ test: /\.css$/, loader: 'raw', exclude: /node_modules/ }, // for templates, need 'raw'
{ test: /\.scss$/, loaders: ['raw', "sass"] }, // for templates, need 'raw'
I need the 'raw' for the templates to load correctly using angular2-template-loader. I thought I could use a separate 'sass' extension for the files I want to separate and use the 'extract-text-webpack-plugin', but I can't get it to work:
var extractSASS = new ExtractTextWebpackPlugin('[name].css');
// in loaders:
{ test: /\.sass$/, loader: extractSASS.extract(['style', 'css', 'sass']) }
// in plugins:
extractSASS
I've also tried the 'extract' loader. The closest I've come to success is by adding the entry "./src/main.sass" and using this for the loader:
{ test: /\.sass$/, loaders: [
{
loader: 'file',
query: {
name: '[name].css'
}
},
'extract',
'raw',
'css',
'sass'
]
}
But that generates a javascript file (comments omitted):
exports = module.exports = require("./../node_modules/css-loader/lib/css-base.js")();
exports.push([module.id, "h1 {\n background-color: #333; }\n", ""]);
Ok, updating I got it to work (I think) by removing the 'raw' loader from the list above, and requiring the sass file in javascript like this:
var x = require('./main.sass');
Is that the right way to do this? How could I use scss
as the extension and not have it mess up my angular templates that just use 'raw' and 'sass' as the loaders?