style-loader

Developer Tools

Injects CSS into the DOM from a webpack build.

Latest v4.0.0 · by webpackWebsitewebpack/style-loader

Changelog

v4.0.0

Latest
Changed 4
  • minimum supported webpack version is now 5.27.0
  • minimum supported Node.js version is now 18.12.0
  • the insert option can only be a selector or the path to the module
  • the styleTagTransform option can only be the path to the module
Fixed 1
  • css experiments logic

From style-loader

4.0.0 (2024-04-08)
⚠ BREAKING CHANGES
  • minimum supported webpack version is 5.27.0
  • minimum support Node.js version is 18.12.0
  • the insert option can only be a selector or the path to the module

Migration:

Before:

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: [
          {
            loader: "style-loader",
            options: {
              injectType: "styleTag",
              styleTagTransform: function (css, style) {
                // Do something ...
                style.innerHTML = `${css}.modify{}\n`;

                document.head.appendChild(style);
              },
            },
          },
          "css-loader",
        ],
      },
    ],
  },
};

After:

insert-function.js

function insert(css, style) {
  var parent = options.target || document.head;

  parent.appendChild(element);
}

module.exports = insert;

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: [
          {
            loader: "style-loader",
            options: {
              insert: require.resolve("./insert.js"),
            },
          },
          "css-loader",
        ],
      },
    ],
  },
};
  • the styleTagTransform option can only be the path to the module

Migration:

Before:

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: [
          {
            loader: "style-loader",
            options: {
              injectType: "styleTag",
              styleTagTransform: function (css, style) {
                // Do something ...
                style.innerHTML = `${css}.modify{}\n`;

                document.head.appendChild(style);
              },
            },
          },
          "css-loader",
        ],
      },
    ],
  },
};

After:

style-tag-transform-function.js

function styleTagTransform(css, style) {
  // Do something ...
  style.innerHTML = `${css}.modify{}\n`;

  document.head.appendChild(style);
}

module.exports = styleTagTransform;

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: [
          {
            loader: "style-loader",
            options: {
              styleTagTransform: require.resolve("./style-tag-transform-function.js"),
            },
          },
          "css-loader",
        ],
      },
    ],
  },
};
Bug Fixes
View originalPermalink
How v4.0.0 went

v3.3.4

Fixed 1
  • css experiments logic

From style-loader

3.3.4 (2024-01-09)
Bug Fixes
View originalPermalink
How v3.3.4 went

v3.3.3

Fixed 1
  • compatibility with built-in CSS support

From style-loader

3.3.3 (2023-05-19)
Bug Fixes
  • compatibility with built-in CSS support (#605) (9636f58)
View originalPermalink
How v3.3.3 went

v3.3.2

Fixed 1
  • noop in environment without DOM API

From style-loader

3.3.2 (2023-03-13)
Bug Fixes
View originalPermalink
How v3.3.2 went

v3.3.1

Fixed 1
  • small perf improvement

From style-loader

3.3.1 (2021-10-21)
Bug Fixes
View originalPermalink
How v3.3.1 went

v3.3.0

Added 2
  • Support for `supports()`, `layer()` and `media` from `@import` at-rules
  • Allow passing options to `insert` function through `style.use()`

From style-loader

3.3.0 (2021-09-21)
Features
  • added support for supports(), layer() and media from @import at-rules (b9a600c)
  • allow to pass options to insert function through style.use() (#535) (f8ef63b)
View originalPermalink
How v3.3.0 went

v3.2.1

Fixed 1
  • added the styletagtransform option when it is a module to addBuildDependency

From style-loader

3.2.1 (2021-07-20)
Bug Fixes
  • added the styletagtransform option when it is a module to addBuildDependency (#528) (270513f)
View originalPermalink
How v3.2.1 went

v3.2.0

Added 1
  • Add link field in schema
Fixed 1
  • Add the insert option when it is a module to addBuildDependency

From style-loader

3.2.0 (2021-07-20)
Features
Bug Fixes
  • added the insert option when it is a module to addBuildDependency (#527) (3963c0b)
View originalPermalink
How v3.2.0 went

v3.1.0

Added 2
  • Allow specifying the `insert` option from file to reduce bundle size
  • Allow specifying the `styleTagTransform` option from file to reduce bundle size
Fixed 2
  • Reduce runtime
  • Reduce runtime when using custom options

From style-loader

3.1.0 (2021-07-12)
Features
  • allow to specify the insert option from file, we strongly recommend do it, using the insert option from file will reduce your bundle size, example (#521) (56fc8f0)
  • allow to specify the styleTagTransform option from file, we strongly recommend do it, using the styleTagTransform option from file will reduce your bundle size, example
Bug Fixes
View originalPermalink
How v3.1.0 went

v3.0.0

Added 2
  • add autoStyleTag and lazyAutoStyleTag values for the injectType option for compatibility with modern and IE8-IE9 browsers
  • add styleTagTransform option for custom processing of style tags
Changed 5
  • minimum supported Node.js version is now 12.13.0
  • minimum supported webpack version is now 5.0.0
  • the styleTag value of the injectType option no longer uses singleton style tag by default, instead using standard style tags for modern browsers
  • reduce size of generated code
  • reduce dependencies
Removed 1
  • the modules.namedExport option was removed

From style-loader

3.0.0 (2021-06-24)
⚠ BREAKING CHANGES
  • minimum supported Node.js version is 12.13.0
  • minimum supported webpack version is 5.0.0
  • the modules.namedExport option was removed, you don't need it anymore, because we respect the modules.namedExport option from css-loader (we just reexport all from css-loader), just remove it
  • the styleTag value of the injectType (default value) option earlier uses singleton style tag by default for IE8-IE9 due limitations (more information), in this release we have disabled this behavior, because these versions of IE are outdated, if you don't support these browsers this change does not affect you, if you require to support IE8-IE9, you can return old behaviour by setting autoStyleTag value for the injectType option (do the same for lazyStyleTag, i.e. change it to lazyAutoStyleTag)
Features
  • added autoStyleTag and lazyAutoStyleTag values for the injectType option for compatibility of work modern and IE8-IE9 browsers
  • added styleTagTransform option for custom processing style tags (useful if you need ponyfill CSS custom properties for IE8-IE10)
  • reduce size of generated code
  • reduce deps
View originalPermalink
How v3.0.0 went
View all

Discussion

If you publish style-loader, you can claim this product by proving you administer its repository.