3

Below is my webpack configuration

const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
    entry: {
        app: './src/index.js',
        style: './src/style.less',
        bootstrap: './node_modules/bootstrap/dist/css/bootstrap.min.css'        
    },
    plugins: [
        new CleanWebpackPlugin(['dist']),
        new HtmlWebpackPlugin({
            title: 'Test Application',
            template: './src/index.html'
        }),
        new MiniCssExtractPlugin({
            filename: this.mode == "development" ? '[name].css' : '[name].[hash].css',
            chunkFilename: this.mode == "development" ? '[id].css' : '[id].[hash].css',
        })
],
output: {
    filename: '[name].[hash].js',
    path: path.resolve(__dirname, 'dist'),
},
module: {
    rules: [
        {
            test: /\.css$/,
            use: [
                { loader: "style-loader" },
                { loader: "css-loader" },
              ],
        },
        {
            test: /\.less$/,
            use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader']
        },
        {
            test: /\.(png|svg|jpg|gif)$/,
            use: [
                'file-loader'
            ]
        }
    ]
}

};

It generates style.js along with style.css, I don't understand why it generates the style.js.

Also for bootstrap: './node_modules/bootstrap/dist/css/bootstrap.min.css'; it generates bootstrap.js instead of bootstrap.css. again, I don't understand this.

Note: I wanted an application should be loaded with css in the beginning itself, thus, the web page should not wait/render different css one after another. So I haven't used an import statement and gave css file path inside entry.

The application is working as expected, am I missing some concept or is there any fix in the code?

1 Answer 1

2

Looks like a known issue in webpack. You can simply ignore the file generated and you don't need to refer the same on your page.

You can see the issue discussions here

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I have gone through the thread. Hopefully, they will fix it in upcoming release :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.