capiono
capiono

Reputation: 2997

extracting css from scss file with webpack

I'm trying to use webpack with my asp.net mvc core project. I'm able to bundle js files. But I can't extract my 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']
    }
};

when I build my project, the css files are not created

my command:

npm run build --color=always
> [email protected] build C:\project\src\test
> webpack
clean-webpack-plugin: C:\project\src\project\wwwroot\dist has been removed.
ts-loader: Using [email protected] 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]
   [2] ./scripts/main.ts 0 bytes {2} [built]
   [3] multi jquery 28 bytes {1} [built]

it looks like it skips pass extract text plugin.

Is anything missing from my configuration file?

my current project structure:

└── Project
    ├── wwwroot
    │   └── scss
    │     └── main.scss
    └── scripts
    │   └── main.ts
    │
    └── webpack.config.js

Upvotes: 0

Views: 136

Answers (1)

Maxim Shvetsov
Maxim Shvetsov

Reputation: 41

Check that you are refering to the styling files somewhere (importing it in main.ts, etc). Otherwise the plugin won't work because it won't find any files to extract.

https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/354

Upvotes: 1

Related Questions