I am currently developing an application which uses different frontend-themes. These themes are simply CSS-Files which can be selected by the user.
Technically these themes are .scss-files which are compiled by webpack and loaded via standard link-tag in angular:
<link rel="stylesheet", ng-href="themes/{{theme}}.css">
My stripped webpack config looks like this:
theme1CssExtractor = new ExtractTextPlugin('themes/theme-1.css'),
theme2CssExtractor = new ExtractTextPlugin('themes/theme-2.css'),
module.exports = new WebpackConfig().merge({
entry: {
app: [
'./app/main.ts',
'./assets/sass/themes/theme-1.scss',
'./assets/sass/themes/theme-2.scss'
],
},
output: {
path: "build/",
filename: "[name].bundle.js",
publicPath: "/build/"
},
plugins: [
theme1CssExtractor,
theme2CssExtractor,
],
module: {
loaders: [
{
test: /\.ts$/,
loaders: ['awesome-typescript-loader']
},
[
{
test: /theme-1\.scss$/,
include: path.resolve(__dirname, "assets/sass/themes"),
loader: theme1CssExtractor.extract(
"style",
"css!sass?includePaths[]=" + path.resolve(__dirname, './node_modules/compass-mixins/lib')
)
},
{
test: /theme-2\.scss$/,
include: path.resolve(__dirname, "assets/sass/themes"),
loader: theme2CssExtractor.extract(
"style",
"css!sass?includePaths[]=" + path.resolve(__dirname, './node_modules/compass-mixins/lib')
)
}
]
]
}
This works completly fine until I want to use the webpack-dev-server with hot module replacement (HMR) feature enabled, because extractTextPlugin does not support HMR. When I simply disable extractTextPlugin (options.disable) or remove them, all themes are compiled into main module and this - of cource - breaks the themes because all are applied together.
How can I generate these CSS-Files directly with webpack without using the extractTextPlugin? I tried various attempts with different enntries/chunks, file-loaders, ... but nothing really works.
It should be simple: Generate static CSS-Files from SCSS-Files without transforming them into JS-Files without using ExtractTextPlugin.
It would be great, if someone could point me in the right direction.