I've been working on integrating webpack into my asp.net mvc core project. While I've successfully bundled js files, I'm facing an issue with extracting css from scss files.
var path = require('path');
var extractTextPlugin = require("extract-text-webpack-plugin");
var cleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
entry: {
'role/role': './scripts/role/roleVM.ts',
main: './scripts/main.ts',
vendor: ["jquery"],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'wwwroot/dist/js/')
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.scss$/,
use: extractTextPlugin.extract({
use: [{
loader: "css-loader", options: {
sourceMap: true
}
}, {
loader: "sass-loader", options: {
sourceMap: true
}
}],
fallback: 'style-loader'
}),
exclude: /node_modules/,
},
]
},
plugins: [
new cleanWebpackPlugin(['dist'], {
root: path.resolve(__dirname, 'wwwroot'),
verbose: true,
dry: false
}),
new extractTextPlugin("./css/main.css")
],
resolve: {
extensions: [".tsx", ".ts", ".js", '.scss']
}
};
Despite following the configuration above, when I build my project, the css files are not being created.
This is the command I am using:
npm run build --color=always
> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d3d3f2227282e390d">[email protected]</a> build C:\project\src\test
> webpack
clean-webpack-plugin: C:\project\src\project\wwwroot\dist has been removed.
ts-loader: Using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="691d10190c1b0c1919295b47">[email protected]</a> and C:\project\src\project\tsconfig.json
Hash: 2cdaff8d8177eedec094
Version: webpack 3.5.3
Time: 2203ms
Asset Size Chunks Chunk Names
role/role.js 293 kB 0 [emitted] [big] role/role
vendor.js 271 kB 1 [emitted] [big] vendor
main.js 2.48 kB 2 [emitted] main
[0] ./scripts/role/roleVM.ts 400 bytes {0} [built]
...
It seems like the extract text plugin is being skipped. Is there anything missing in my configuration file?
Here is the current structure of my project:
└── Project
├── wwwroot
│ └── scss
│ └── main.scss
└── scripts
│ └── main.ts
│
└── webpack.config.js