Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

webpack-fix-style-only-entries

fqborges178.4kISC0.6.1

Package to fix style (css/sass/less/stylus) only entries generating a extra js file.

webpack, fix, css, js, style

readme

npm version

webpack-fix-style-only-entries

This is a small plugin developed to solve the problem of having a style only entry (css/sass/less/stylus) generating an extra js file.

You can find more info by reading the following issues:

View on: Github - npm

How it works

It just find js files from chunks of css only entries and remove the js file from the compilation.

How to use

install using your package manager of choice:

  • npm: npm install -D webpack-fix-style-only-entries
  • yarn: yarn add -D webpack-fix-style-only-entries

Require and add to webpack.config plugins.

Warning: this plugin does not load styles or split your bundles, it just fix chunks of css only entries by removing the (almost) empty js file.

// ... other plugins
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");

module.exports = {
    entry: {
        "main" : "./app/main.js"
        "styles": ["./common/styles.css", "./app/styles.css"]
    },
    module: {
            {
                test: /\.css$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                ]
            },
        ]
    },
    plugins: [
        new FixStyleOnlyEntriesPlugin(),
        new MiniCssExtractPlugin({
            filename: "[name].[chunkhash:8].css",
        }),
    ],
};

Options

Name Type Default Description
extensions Array[string] ["less", "scss", "css", "styl","sass"] file extensions for styles
silent boolean false supress logs to console
ignore string or RegExp undefined match resource to be ignored

Example config:

// to identify only 'foo' and 'bar' extensions as styles
new FixStyleOnlyEntriesPlugin({ extensions:['foo', 'bar'] }),

Recipes

I use a javascript entry to styles:

Give an especial extension to your file (.css.js for example) and configure new FixStyleOnlyEntriesPlugin({ extensions:['css.js'] }). See: https://github.com/fqborges/webpack-fix-style-only-entries/issues/8.

I use webpack-hot-middleware:

Configure this plugin as new FixStyleOnlyEntriesPlugin({ ignore: 'webpack-hot-middleware' }). See: https://github.com/fqborges/webpack-fix-style-only-entries/issues/12 and https://github.com/fqborges/webpack-fix-style-only-entries/blob/master/test/cases/css-entry-with-ignored-hmr/webpack.config.js.

changelog

0.6.1 (Jan 18, 2021)

  • fix: [DEP_WEBPACK_DEPRECATION_ARRAY_TO_SET] webpack5 compatibility (PR #43)

0.6.0 (Oct 13, 2020)

Being overly careful here, this version is not breaking for almost all the existing users. It could possibly break in some edge cases, since it changes how modules are collected (from global to one each compilation) or if you have a workaround for a working webpack multi configuration.

  • BREAKING (POSSIBLY): Use a dedicated cache for every compilation (Prevent arbitrary files deletion when using Webpack with multi configurations) (PR #39)

0.5.2 (Oct 07, 2020)

  • Webpack 5 support using ModuleGraph API (PR #38)
  • npm audit fix: (ea9dd7)

0.5.1 (Jun 13, 2020)

  • Fix Maximum call stack size exceeded (PR #34)
  • Added CHANGELOG (3e3767)

0.5.0 (May 18, 2020)

0.4.0 (Sep 8, 2019)

  • feat: add support for module js files (PR #21)