Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webpack-contrib/style-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2c41858ea4a6a06c691e6f9293d66c63f841bc79
Choose a base ref
...
head repository: webpack-contrib/style-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 171a747acdc7bfd8cbc16391af46c59312733110
Choose a head ref

Commits on Aug 24, 2019

  1. docs: fix typo (#424)

    Change module name to load according to the exemple below.
    Et3rnel authored and evilebottnawi committed Aug 24, 2019

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    1c443e1 View commit details

Commits on Nov 28, 2019

  1. Copy the full SHA
    2cdb9c3 View commit details
  2. chore(release): 1.0.1

    alexander-akait committed Nov 28, 2019
    Copy the full SHA
    c6164d5 View commit details

Commits on Dec 13, 2019

  1. Copy the full SHA
    4c1e3f3 View commit details

Commits on Dec 17, 2019

  1. Copy the full SHA
    d515edc View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    dcbfadb View commit details
  3. chore(release): 1.0.2

    alexander-akait committed Dec 17, 2019
    Copy the full SHA
    7768fce View commit details
  4. test: refactor

    evilebottnawi authored Dec 17, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    609263a View commit details
  5. refactor: cjs (#437)

    evilebottnawi authored Dec 17, 2019
    Copy the full SHA
    5c51b90 View commit details
  6. refactor: code (#438)

    evilebottnawi authored Dec 17, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    28e1628 View commit details

Commits on Dec 18, 2019

  1. test: refactor (#440)

    evilebottnawi authored Dec 18, 2019
    Copy the full SHA
    907aed8 View commit details

Commits on Dec 19, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3415266 View commit details
  2. Copy the full SHA
    a283b30 View commit details

Commits on Dec 20, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c7d6e3a View commit details
  2. chore(release): 1.1.0

    alexander-akait committed Dec 20, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c69ea6c View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7ee8b04 View commit details
  4. chore(release): 1.1.1

    alexander-akait committed Dec 20, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    aa418dd View commit details

Commits on Dec 24, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1138ed7 View commit details

Commits on Dec 25, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    91ceaf2 View commit details
  2. chore(release): 1.1.2

    alexander-akait committed Dec 25, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    de38c39 View commit details

Commits on Dec 29, 2019

  1. docs: fix typos (#453)

    quebits authored and evilebottnawi committed Dec 29, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    36bd8f1 View commit details

Commits on Jan 17, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    236b243 View commit details
  2. chore(release): 1.1.3

    alexander-akait committed Jan 17, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2756e03 View commit details

Commits on Feb 10, 2020

  1. Copy the full SHA
    a003f05 View commit details

Commits on Apr 15, 2020

  1. chore(deps): update

    evilebottnawi authored Apr 15, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    af1b4a9 View commit details
  2. chore(release): 1.1.4

    alexander-akait committed Apr 15, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    171a747 View commit details
Showing with 10,798 additions and 6,069 deletions.
  1. +1 −2 .editorconfig
  2. +1 −0 .eslintrc.js
  3. +91 −0 .github/workflows/nodejs.yml
  4. +1 −5 .prettierrc.js
  5. +57 −1 CHANGELOG.md
  6. +44 −12 README.md
  7. +0 −194 azure-pipelines.yml
  8. +2 −2 lint-staged.config.js
  9. +7,608 −5,032 package-lock.json
  10. +49 −47 package.json
  11. +3 −0 src/cjs.js
  12. +135 −56 src/index.js
  13. +4 −0 src/options.json
  14. +66 −66 src/runtime/injectStylesIntoStyleTag.js
  15. +48 −48 test/__snapshots__/attributes-option.test.js.snap
  16. +3 −3 test/__snapshots__/base-option.test.js.snap
  17. +799 −0 test/__snapshots__/esModule-option.test.js.snap
  18. +16 −16 test/__snapshots__/injectType-option.test.js.snap
  19. +116 −116 test/__snapshots__/insert-option.test.js.snap
  20. +307 −83 test/__snapshots__/loader.test.js.snap
  21. +62 −14 test/__snapshots__/validate-options.test.js.snap
  22. +32 −30 test/attributes-option.test.js
  23. +13 −14 test/base-option.test.js
  24. +8 −0 test/cjs.test.js
  25. +221 −0 test/esModule-option.test.js
  26. +5 −0 test/fixtures/lazy-multiple.js
  27. +2 −0 test/fixtures/multiple.js
  28. +3 −0 test/fixtures/nested/style.css
  29. +3 −0 test/fixtures/other-nested/style.css
  30. +11 −0 test/helpers/compile.js
  31. +0 −89 test/helpers/compiler.js
  32. +22 −0 test/helpers/execute.js
  33. +54 −0 test/helpers/getCompiler.js
  34. +2 −2 test/helpers/{getTestId.js → getEntryByInjectType.js}
  35. +5 −0 test/helpers/getErrors.js
  36. +5 −0 test/helpers/getWarnings.js
  37. +22 −4 test/helpers/index.js
  38. +19 −0 test/helpers/normalizeErrors.js
  39. +23 −0 test/helpers/readAsset.js
  40. +11 −0 test/helpers/readAssets.js
  41. +6 −4 test/helpers/{runTestInJsdom.js → runInJsDom.js}
  42. +15 −9 test/injectType-option.test.js
  43. +91 −97 test/insert-option.test.js
  44. +244 −66 test/loader.test.js
  45. +28 −1 test/manual/index.html
  46. +3 −0 test/manual/src/duplicate.css
  47. +32 −1 test/manual/src/index.js
  48. +3 −0 test/manual/src/modules/common.module.css
  49. +4 −0 test/manual/src/modules/one.module.css
  50. +5 −0 test/manual/src/modules/page.module.css
  51. +5 −0 test/manual/src/modules/toolbar.module.css
  52. +4 −0 test/manual/src/modules/two.module.css
  53. +2 −0 test/manual/src/nested.css
  54. +5 −0 test/manual/src/nested/style.css
  55. +3 −0 test/manual/src/order-1.css
  56. +3 −0 test/manual/src/order-2.css
  57. +13 −0 test/manual/src/order.css
  58. +3 −0 test/manual/src/use-unuse.lazy.css
  59. +34 −11 test/manual/webpack.config.js
  60. +72 −0 test/runtime/__snapshots__/injectStylesIntoStyleTag.test.js.snap
  61. +273 −0 test/runtime/injectStylesIntoStyleTag.test.js
  62. +76 −44 test/validate-options.test.js
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -9,5 +9,4 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = true
trim_trailing_whitespace = false
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ module.exports = {
__webpack_nonce__: 'readonly',
},
rules: {
'no-underscore-dangle': 'off',
'no-plusplus': 'off',
'consistent-return': 'off',
'no-param-reassign': 'off',
91 changes: 91 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: style-loader

on:
push:
branches:
- master
- next
pull_request:
branches:
- master
- next

jobs:
lint:
name: Lint - ${{ matrix.os }} - Node v${{ matrix.node-version }}

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

strategy:
matrix:
os: [ubuntu-latest]
node-version: [12.x]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ env.node-version }}

- name: Use latest NPM
run: sudo npm i -g npm

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

# - name: Security audit
# run: npm run security

- name: Check commit message
uses: wagoid/commitlint-github-action@v1

test:
name: Test - ${{ matrix.os }} - Node v${{ matrix.node-version }}, Webpack ${{ matrix.webpack-version }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [8.x, 10.x, 12.x, 13.x]
webpack-version: [latest, next]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Use latest NPM on ubuntu/macos
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: sudo npm i -g npm

- name: Use latest NPM on windows
if: matrix.os == 'windows-latest'
run: npm i -g npm

- name: Install dependencies
run: npm ci

- name: Install webpack ${{ matrix.webpack-version }}
run: npm i webpack@${{ matrix.webpack-version }}

- name: Run tests for webpack version ${{ matrix.webpack-version }}
run: npm run test:coverage -- --ci

- name: Submit coverage data to codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
6 changes: 1 addition & 5 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
singleQuote: true,
trailingComma: 'es5',
arrowParens: 'always',
};
module.exports = { singleQuote: true };
58 changes: 57 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,62 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.1.4](https://github.com/webpack-contrib/style-loader/compare/v1.1.3...v1.1.4) (2020-04-15)


# Chore

* update deps


### [1.1.3](https://github.com/webpack-contrib/style-loader/compare/v1.1.2...v1.1.3) (2020-01-17)


### Bug Fixes

* injection algorithm ([#456](https://github.com/webpack-contrib/style-loader/issues/456)) ([236b243](https://github.com/webpack-contrib/style-loader/commit/236b2436fb0003eeba5f0aa33e7caf9f35d4fc7a))

### [1.1.2](https://github.com/webpack-contrib/style-loader/compare/v1.1.1...v1.1.2) (2019-12-25)


### Bug Fixes

* algorithm for importing modules ([#449](https://github.com/webpack-contrib/style-loader/issues/449)) ([91ceaf2](https://github.com/webpack-contrib/style-loader/commit/91ceaf2b7e03f065d2a8cace1b733777848d4e86))
* checking that the list of modules is an array ([#448](https://github.com/webpack-contrib/style-loader/issues/448)) ([1138ed7](https://github.com/webpack-contrib/style-loader/commit/1138ed7e04848b570a70e493b410902cfc4a9076))

### [1.1.1](https://github.com/webpack-contrib/style-loader/compare/v1.1.0...v1.1.1) (2019-12-20)


### Bug Fixes

* add empty default export for `linkTag` value ([7ee8b04](https://github.com/webpack-contrib/style-loader/commit/7ee8b04fd519847cef93052c31efa0d0012ed54e))

## [1.1.0](https://github.com/webpack-contrib/style-loader/compare/v1.0.2...v1.1.0) (2019-12-20)


### Features

* `esModule` option ([#441](https://github.com/webpack-contrib/style-loader/issues/441)) ([3415266](https://github.com/webpack-contrib/style-loader/commit/3415266f58f2be00bec1d66ae9e658437e0d0a6c))


### Bug Fixes

* order of imported styles ([#443](https://github.com/webpack-contrib/style-loader/issues/443)) ([c7d6e3a](https://github.com/webpack-contrib/style-loader/commit/c7d6e3a3fba63a76e8f342d84e00b69af92c7ebc))

### [1.0.2](https://github.com/webpack-contrib/style-loader/compare/v1.0.1...v1.0.2) (2019-12-17)


### Bug Fixes

* support ES module syntax ([#435](https://github.com/webpack-contrib/style-loader/issues/435)) ([dcbfadb](https://github.com/webpack-contrib/style-loader/commit/dcbfadb4245e7f0ce888aafc138cbac27d053915))

### [1.0.1](https://github.com/webpack-contrib/style-loader/compare/v1.0.0...v1.0.1) (2019-11-28)


### Bug Fixes

* compatibility `linkTag` with ES module syntax ([#429](https://github.com/webpack-contrib/style-loader/issues/429)) ([2cdb9c3](https://github.com/webpack-contrib/style-loader/commit/2cdb9c3f51edebec69e8b22ff43b520a5e1c679b))

## [1.0.0](https://github.com/webpack-contrib/style-loader/compare/v0.23.1...v1.0.0) (2019-08-06)


@@ -21,7 +77,7 @@ All notable changes to this project will be documented in this file. See [standa
### BREAKING CHANGES

* minimum required Node.js version is `8.9.0`
* minimum require `wepback` version is `4.0.0`
* minimum required `wepback` version is `4.0.0`
* the `convertToAbsoluteUrls` option was removed, you don't need this anymore
* the `attrs` option was renamed to the `attributes` option
* the `transform` option was removed without replacement
56 changes: 44 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ Inject CSS into the DOM.

## Getting Started

To begin, you'll need to install `css-loader`:
To begin, you'll need to install `style-loader`:

```console
npm install --save-dev style-loader
@@ -61,12 +61,13 @@ module.exports = {

## Options

| Name | Type | Default | Description |
| :--------------: | :------------------: | :--------: | :------------------------------------------------------- |
| **`injectType`** | `{String}` | `styleTag` | Allows to setup how styles will be injected into the DOM |
| **`attributes`** | `{Object}` | `{}` | Adds custom attributes to tag |
| **`insert`** | `{String\|Function}` | `head` | Inserts tag at the given position into the DOM |
| **`base`** | `{Number}` | `true` | Sets module ID base (DLLPlugin) |
| Name | Type | Default | Description |
| :-----------------------------: | :------------------: | :--------: | :------------------------------------------------------- |
| [**`injectType`**](#injecttype) | `{String}` | `styleTag` | Allows to setup how styles will be injected into the DOM |
| [**`attributes`**](#attributes) | `{Object}` | `{}` | Adds custom attributes to tag |
| [**`insert`**](#insert) | `{String\|Function}` | `head` | Inserts tag at the given position into the DOM |
| [**`base`**](#base) | `{Number}` | `true` | Sets module ID base (DLLPlugin) |
| [**`esModule`**](#esmodule) | `{Boolean}` | `false` | Use ES modules syntax |

### `injectType`

@@ -93,7 +94,7 @@ Automatically injects styles into the DOM using multiple `<style></style>`. It i
import './styles.css';
```

Example with c Locals (CSS Modules):
Example with Locals (CSS Modules):

**component-with-css-modules.js**

@@ -313,7 +314,10 @@ module.exports = {
{
test: /\.lazy\.css$/i,
use: [
{ loader: 'style-loader', options: { injectType: 'lazyStyleTag' } },
{
loader: 'style-loader',
options: { injectType: 'lazySingletonStyleTag' },
},
'css-loader',
],
},
@@ -450,7 +454,7 @@ A new `<style>`/`<link>` elements will be inserted into at bottom of `body` tag.
Allows to override default behavior and insert styles at any position.

> ⚠ Do not forget that this code will be used in the browser and not all browsers support latest ECMA features like `let`, `const`, `arrow function expression` and etc, we recommend use only ECMA 5 features, but it is depends what browsers you want to support
> ⚠ Do not forget that some doom methods may not be available in older browsers, we recommended use only [DOM core level 2 properties](https://caniuse.com/#search=DOM%20Core), but it is depends what browsers you want to support
> ⚠ Do not forget that some DOM methods may not be available in older browsers, we recommended use only [DOM core level 2 properties](https://caniuse.com/#search=DOM%20Core), but it is depends what browsers you want to support
**webpack.config.js**

@@ -548,6 +552,34 @@ module.exports = {
};
```

### `esModule`

Type: `Boolean`
Default: `false`

By default, `style-loader` generates JS modules that use the CommonJS modules syntax.
There are some cases in which using ES modules is beneficial, like in the case of [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [tree shaking](https://webpack.js.org/guides/tree-shaking/).

You can enable a ES module syntax using:

**webpack.config.js**

```js
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
loader: 'css-loader',
options: {
esModule: true,
},
},
],
},
};
```

## Examples

### Source maps
@@ -775,8 +807,8 @@ Please take a moment to read our contributing guidelines if you haven't yet done
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack-contrib/style-loader.svg
[deps-url]: https://david-dm.org/webpack-contrib/style-loader
[tests]: https://dev.azure.com/webpack-contrib/style-loader/_apis/build/status/webpack-contrib.style-loader?branchName=master
[tests-url]: https://dev.azure.com/webpack-contrib/style-loader/_build/latest?definitionId=18&branchName=master
[tests]: https://github.com/webpack-contrib/style-loader/workflows/style-loader/badge.svg
[tests-url]: https://github.com/webpack-contrib/style-loader/actions
[cover]: https://codecov.io/gh/webpack-contrib/style-loader/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/style-loader
[chat]: https://badges.gitter.im/webpack/webpack.svg
Loading