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/postcss-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bcc9ccf8b6dbe6143484853da4cac442ecf8aa58
Choose a base ref
...
head repository: webpack-contrib/postcss-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7647ac9051a17a3a6add7364828bf7bd9955b968
Choose a head ref

Commits on Nov 5, 2017

  1. docs(README): fix broken link (importLoaders) (#310)

    Jay Sherby authored and michael-ciniawsky committed Nov 5, 2017
    Copy the full SHA
    31a25e8 View commit details

Commits on Nov 24, 2017

  1. Unverified

    No user is associated with the committer email.
    Copy the full SHA
    f33131c View commit details
  2. Copy the full SHA
    3e1c7fa View commit details
  3. Copy the full SHA
    b9c1add View commit details

Commits on Jan 3, 2018

  1. Copy the full SHA
    61ff03c View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    08c063a View commit details

Commits on Feb 2, 2018

  1. Copy the full SHA
    a8921cc 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
    8242689 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    4e8e20c View commit details
  4. feat(index): pass AST (result.root) && Messages (result.messages)…

    … as metadata to other loaders (#322)
    michael-ciniawsky authored Feb 2, 2018
    Copy the full SHA
    56232e7 View commit details
  5. Copy the full SHA
    410bbf9 View commit details
  6. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    6ddc2bb View commit details

Commits on Feb 18, 2018

  1. Copy the full SHA
    0a643de View commit details

Commits on Feb 26, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    cdbb8b6 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    e2f4498 View commit details

Commits on Mar 16, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    1e0cade View commit details

Commits on Mar 17, 2018

  1. 1

    Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    82ef553 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    0c2259b View commit details

Commits on Mar 20, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    bd7fc38 View commit details
  2. chore(release): 2.1.3

    ai committed Mar 20, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    ce2adca View commit details

Commits on Apr 16, 2018

  1. fix: restore loader object in postcss config context (#355)

    * fix: restore loader object in postcss config context
    
    * test: add testcase which checking webpack object exists in config context
    kisenka authored and ai committed Apr 16, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    2ff1735 View commit details
  2. chore(release): 2.1.4

    ai committed Apr 16, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    2484275 View commit details

Commits on May 4, 2018

  1. Copy the full SHA
    4416791 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
    928d5c4 View commit details

Commits on Jul 10, 2018

  1. Copy the full SHA
    22846d3 View commit details
  2. fix(package): config memory leak, updates postcss-load-config v1.2.…

    …0...2.0.0 (`dependencies`)
    michael-ciniawsky committed Jul 10, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    0547b12 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
    4955792 View commit details

Commits on Jul 16, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    5c1c108 View commit details

Commits on Jul 27, 2018

  1. Copy the full SHA
    060e3cb View commit details

Commits on Aug 1, 2018

  1. Copy the full SHA
    e44fed6 View commit details

Commits on Aug 3, 2018

  1. Copy the full SHA
    5e2bca9 View commit details

Commits on Aug 4, 2018

  1. Copy the full SHA
    0bb835c View commit details
  2. Copy the full SHA
    6f10898 View commit details
  3. Copy the full SHA
    8ef443f View commit details
  4. Copy the full SHA
    8772814 View commit details
  5. Copy the full SHA
    114db12 View commit details

Commits on Aug 8, 2018

  1. chore(package): update postcss v6.0.0...7.0.0 (dependencies) (#375)

    BREAKING CHANGE: requires `node >= v6.0.0`
    damanwiththeplan authored and michael-ciniawsky committed Aug 8, 2018
    Copy the full SHA
    daa0da8 View commit details
  2. Copy the full SHA
    fbf05de View commit details
  3. Copy the full SHA
    549ea08 View commit details
  4. Copy the full SHA
    2c6033b View commit details
  5. Copy the full SHA
    8ac6fb5 View commit details
  6. Copy the full SHA
    f34954f View commit details
  7. Copy the full SHA
    bdcbef0 View commit details
  8. Copy the full SHA
    319d1f7 View commit details
  9. Copy the full SHA
    4a0328e View commit details
  10. Copy the full SHA
    70f4426 View commit details
  11. Copy the full SHA
    73a8c66 View commit details
  12. Copy the full SHA
    ea68a42 View commit details
  13. Copy the full SHA
    95de4c1 View commit details
  14. Copy the full SHA
    1f98aee View commit details
39 changes: 0 additions & 39 deletions .github/ISSUE_TEMPLATE.md

This file was deleted.

34 changes: 34 additions & 0 deletions .github/ISSUE_TEMPLATE/BUG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: 🐛 Bug
about: Report a Bug
---

<!-- ✏️ Briefly describe the issue you are experiencing. Tell us what you were trying to do and what happened instead. Remember, this is *not* the right place to ask general support questions. For that, please go to http://gitter.im/postcss/postcss -->

### Details

<!-- ✏️ Describe in more detail the problem you have been experiencing (if necessary) -->

### Error (Logs|Stacks)

<!-- 👉 Create a [gist](https://gist.github.com) which is a paste of your **full** logs, and link them here -->

<!-- ⚠️ Do **not** paste your full logs here (or at least fold them by using a `<details>{{ logs }}</details>` block), as it will make this issue long and hard to read! If you are reporting a bug, **always** include logs! -->

### Reproduction (Code)

<!-- ⚠️ Please remember that, with sample code; it's easier to reproduce a bug and much faster to fix it -->

<!-- 🔗 Please refer to a simple code example -->

```bash
$ git clone https://github.com/<user>/<sample>
```

### Environment

<!-- 👉 Please provide information about your current environment -->

|OS|node|npm/yarn|package|
|:-:|:--:|:-:|:------:|
|[name][version]|[version]|[version]|[version]|
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: 📖 Docs
about: Report documentation related issues
---

### Type

<!-- 👉 Specify the type of issue by checking one of the provided checkboxes below and please deleted all others -->

- [ ] Other
- [ ] Wrong
- [ ] Unclear
- [ ] Missing

### Details

<!-- ✏️ Briefly describe the issue you are experiencing. Tell us what you were trying to do (how you understood the documentation) and what happened instead -->

### Location

<!-- 👉 Select the area where the aforementioned issue is currently located -->

- [ ] README
- [ ] LICENSE
- [ ] CHANGELOG
- [ ] ISSUE_TEMPLATE
- [ ] BUG
- [ ] DOCS
- [ ] FEATURE
- [ ] PULL_REQUEST_TEMPLATE
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/FEATURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: 🌟 Feature
about: Request a feature
---

### Proposal

<!-- ✏️ Briefly describe the feature you want to be added -->

### Use Case

<!-- ✏️ Describe in more detail the specific use case this feature addresses -->

### Implementation

<!-- 👉 Select one of the provided options -->

- [ ] I'm open to work on this
- [ ] I need help/mentorship
- [ ] I'm unable to work on this

<!-- ✏️ Briefly describe the feature implementation -->
59 changes: 36 additions & 23 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,63 @@
> ℹ️ Describe the big picture of your changes here to communicate to the maintainers
why we should accept this pull request. If it fixes a bug or resolves a feature
request, be sure to link to that issue.
### Notable Changes

### `Type`
---
<!-- ✏️ Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue(s) down below -->

> ℹ️ What types of changes does your code introduce?
#### `Commit Message Summary (CHANGELOG)`

> _Put an `x` in the boxes that apply_
<!-- ⚠️ All commits will be squashed into a single commit when merging the PR, so if there is any additional information needed to describe your changes (e.g BREAKING CHANGES), please list them here so the maintainers are able to include them as the commit message body of the final commit. I case your unsure what might be relevant don't hesitate to ask -->

<!-- 👉 Replace the example with your changes or otherwise delete the code block in case no additional information is needed -->

```bash
# Commit Message Body
#
# Example
BREAKING CHANGE: requires `node >= v8.0.0`
BREAKING CHANGE: `options.x` requires to be a `{Function}` now
```

### Type

> ℹ️ What type of changes does your code introduce?
<!-- 👉 Put an `x` in the boxes that apply and delete all others -->

- [ ] CI
- [ ] Fix
- [ ] Perf
- [ ] Docs
- [ ] Test
- [ ] Style
- [ ] Build
- [ ] Chore
- [ ] Feature
- [ ] Refactor

### `SemVer`
---
### Issues

> ℹ️ What changes to the current `semver` range does your PR introduce?
> ℹ️ What issue(s) (if any) are closed by your PR?
> _Put an `x` in the boxes that apply_
<!-- 👉 Replace `#1` with the issue number that applies and remove the ``` ` ``` (`#1` => #1) -->

- [ ] Bug (:label: Patch)
- [ ] Feature (:label: Minor)
- [ ] Breaking Change (:label: Major)
- Fixes `#1`

### `Issues`
---
### SemVer

> ℹ️ What issue (if any) are closed by your PR?
> ℹ️ What changes to the current `semver` range does your PR introduce?
> _Replace `#1` with the error number that applies_
<!-- 👉 Put an `x` in the boxes that apply and delete all others -->

- Fixes `#1`
- [ ] Fix (:label: Patch)
- [ ] Feature (:label: Minor)
- [ ] Breaking Change (:label: Major)

### `Checklist`
---
### Checklist

> ℹ️ You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. This is a reminder of what we are going to look for before merging your code.
> _Put an `x` in the boxes that apply._
<!-- 👉 Put an `x` in the boxes that apply and delete all others -->

- [ ] Lint and unit tests pass with my changes
- [ ] I have added tests that prove my fix is effective/works
- [ ] I have added tests that prove my fix is effective/works (if needed)
- [ ] I have added necessary documentation (if appropriate)
- [ ] Any dependent changes are merged and published in downstream modules
21 changes: 17 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
language: node_js

node_js:
- "node"
- 6
jobs:
fast_finish: true
include:
- stage: Lint
env: SCRIPT=lint
node_js: 'stable'
- &test
stage: 'Test'
env: SCRIPT=test
node_js: 'stable'
- <<: *test
node_js: 'lts/*'
- <<: *test
node_js: 6

script: npm run $SCRIPT

after_success:
- npm i coveralls
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
- cat ./coverage/lcov.info | $(npm bin)/coveralls

notifications:
email: false
117 changes: 117 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,123 @@

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.

<a name="3.0.0"></a>
# [3.0.0](https://github.com/postcss/postcss-loader/compare/v2.1.6...v3.0.0) (2018-08-08)


### Bug Fixes

* **index:** add ast version (`meta.ast`) ([f34954f](https://github.com/postcss/postcss-loader/commit/f34954f))
* **index:** emit `warnings` as an instance of `{Error}` ([8ac6fb5](https://github.com/postcss/postcss-loader/commit/8ac6fb5))
* **options:** improved `ValidationError` messages ([549ea08](https://github.com/postcss/postcss-loader/commit/549ea08))


### Chores

* **package:** update `postcss` v6.0.0...7.0.0 (`dependencies`) ([#375](https://github.com/postcss/postcss-loader/issues/375)) ([daa0da8](https://github.com/postcss/postcss-loader/commit/daa0da8))


### BREAKING CHANGES

* **package:** requires `node >= v6.0.0`



<a name="2.1.6"></a>
## [2.1.6](https://github.com/postcss/postcss-loader/compare/v2.1.5...v2.1.6) (2018-07-10)


### Bug Fixes

* **package:** config memory leak, updates `postcss-load-config` v1.2.0...2.0.0 (`dependencies`) ([0547b12](https://github.com/postcss/postcss-loader/commit/0547b12))



<a name="2.1.5"></a>
## [2.1.5](https://github.com/postcss/postcss-loader/compare/v2.1.4...v2.1.5) (2018-05-04)


### Bug Fixes

* **index:** remove `sourceMap` warning ([#361](https://github.com/postcss/postcss-loader/issues/361)) ([4416791](https://github.com/postcss/postcss-loader/commit/4416791))



<a name="2.1.4"></a>
## [2.1.4](https://github.com/postcss/postcss-loader/compare/v2.1.3...v2.1.4) (2018-04-16)


### Bug Fixes

* restore loader object in postcss config context ([#355](https://github.com/postcss/postcss-loader/issues/355)) ([2ff1735](https://github.com/postcss/postcss-loader/commit/2ff1735))



<a name="2.1.3"></a>
## [2.1.3](https://github.com/postcss/postcss-loader/compare/v2.1.2...v2.1.3) (2018-03-20)


### Bug Fixes

* **options:** revert additionalProperties changes to keep SemVer ([bd7fc38](https://github.com/postcss/postcss-loader/commit/bd7fc38))



<a name="2.1.2"></a>
## [2.1.2](https://github.com/postcss/postcss-loader/compare/v2.1.1...v2.1.2) (2018-03-17)


### Bug Fixes

* **options:** disallow additional properties and add `ident` to validation ([#346](https://github.com/postcss/postcss-loader/issues/346)) ([82ef553](https://github.com/postcss/postcss-loader/commit/82ef553))



<a name="2.1.1"></a>
## [2.1.1](https://github.com/postcss/postcss-loader/compare/v2.1.0...v2.1.1) (2018-02-26)


### Bug Fixes

* **index:** don't set `to` value (`options`) ([#339](https://github.com/postcss/postcss-loader/issues/339)) ([cdbb8b6](https://github.com/postcss/postcss-loader/commit/cdbb8b6))



<a name="2.1.0"></a>
# [2.1.0](https://github.com/postcss/postcss-loader/compare/v2.0.10...v2.1.0) (2018-02-02)


### Bug Fixes

* **index:** continue watching after dependency `{Error}` ([#332](https://github.com/postcss/postcss-loader/issues/332)) ([a8921cc](https://github.com/postcss/postcss-loader/commit/a8921cc))


### Features

* **index:** pass AST (`result.root`) && Messages (`result.messages`) as metadata to other loaders ([#322](https://github.com/postcss/postcss-loader/issues/322)) ([56232e7](https://github.com/postcss/postcss-loader/commit/56232e7))



<a name="2.0.10"></a>
## [2.0.10](https://github.com/postcss/postcss-loader/compare/v2.0.9...v2.0.10) (2018-01-03)


### Bug Fixes

* **index:** copy loader `options` before modifying ([#326](https://github.com/postcss/postcss-loader/issues/326)) ([61ff03c](https://github.com/postcss/postcss-loader/commit/61ff03c))



<a name="2.0.9"></a>
## [2.0.9](https://github.com/postcss/postcss-loader/compare/v2.0.8...v2.0.9) (2017-11-24)


### Bug Fixes

* **index:** filter `ident` (`options.ident`) ([#315](https://github.com/postcss/postcss-loader/issues/315)) ([3e1c7fa](https://github.com/postcss/postcss-loader/commit/3e1c7fa))



<a name="2.0.8"></a>
## [2.0.8](https://github.com/postcss/postcss-loader/compare/v2.0.6...v2.0.8) (2017-10-14)

46 changes: 0 additions & 46 deletions LOADER.md

This file was deleted.

113 changes: 71 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
<div align="center">
<img width="180" height="180" hspace="10"
alt="PostCSS Logo"
src="http://postcss.github.io/postcss/logo.svg">
src="https://api.postcss.org/logo.svg">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200" hspace="10"
src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg">
@@ -20,7 +20,7 @@
</a>
</div>
<h1>PostCSS Loader</h1>
<p>Loader for <a href="http://webpack.js.org/">webpack</a> to process CSS with <a href="http://postcss.org/">PostCSS</a></p>
<p>Loader for <a href="https://webpack.js.org/">webpack</a> to process CSS with <a href="https://postcss.org/">PostCSS</a></p>
</div>

<h2 align="center">Install</h2>
@@ -33,13 +33,13 @@ npm i -D postcss-loader

### `Configuration`

**postcss.config.js**
**`postcss.config.js`**
```js
module.exports = {
parser: 'sugarss',
plugins: {
'postcss-import': {},
'postcss-cssnext': {},
'postcss-preset-env': {},
'cssnano': {}
}
}
@@ -72,7 +72,7 @@ Config lookup starts from `path.dirname(file)` and walks the file tree upwards u

After setting up your `postcss.config.js`, add `postcss-loader` to your `webpack.config.js`. You can use it standalone or in conjunction with `css-loader` (recommended). Use it **after** `css-loader` and `style-loader`, but **before** other preprocessor loaders like e.g `sass|less|stylus-loader`, if you use any.

**webpack.config.js**
**`webpack.config.js`**
```js
module.exports = {
module: {
@@ -88,7 +88,7 @@ module.exports = {

> ⚠️ When `postcss-loader` is used standalone (without `css-loader`) don't use `@import` in your CSS, since this can lead to quite bloated bundles
**webpack.config.js (recommended)**
**`webpack.config.js` (recommended)**
```js
module.exports = {
module: {
@@ -116,12 +116,13 @@ module.exports = {
|[`stringifier`](#syntaxes)|`{String\|Object}`|`undefined`|Set PostCSS Stringifier|
|[`config`](#config)|`{Object}`|`undefined`|Set `postcss.config.js` config path && `ctx`|
|[`plugins`](#plugins)|`{Array\|Function}`|`[]`|Set PostCSS Plugins|
|[`sourceMap`](#sourceMap)|`{String\|Boolean}`|`false`|Enable Source Maps|
|[`sourceMap`](#sourcemap)|`{String\|Boolean}`|`false`|Enable Source Maps|

### `Exec`

If you use JS styles without the [`postcss-js`][postcss-js] parser, add the `exec` option.

**`webpack.config.js`**
```js
{
test: /\.style.js$/,
@@ -137,7 +138,7 @@ If you use JS styles without the [`postcss-js`][postcss-js] parser, add the `exe

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|[`path`](#path)|`{String}`|`undefined`|PostCSS Config Path|
|[`path`](#path)|`{String}`|`undefined`|PostCSS Config Directory|
|[`context`](#context)|`{Object}`|`undefined`|PostCSS Config Context|

#### `Path`
@@ -146,18 +147,23 @@ You can manually specify the path to search for your config (`postcss.config.js`

> ⚠️ Otherwise it is **unnecessary** to set this option and is **not** recommended
**webpack.config.js**
> ⚠️ Note that you **can't** use a **filename** other than the [supported config formats] (e.g `.postcssrc.js`, `postcss.config.js`), this option only allows you to manually specify the **directory** where config lookup should **start** from
**`webpack.config.js`**
```js
{
loader: 'postcss-loader',
options: {
config: {
path: 'path/to/postcss.config.js'
path: 'path/to/.config/'
path: 'path/to/.config/css.config.js'
}
}
}
```

[supported config formats]: https://github.com/michael-ciniawsky/postcss-load-config#usage

#### `Context (ctx)`

|Name|Type|Default|Description|
@@ -168,29 +174,27 @@ You can manually specify the path to search for your config (`postcss.config.js`

`postcss-loader` exposes context `ctx` to the config file, making your `postcss.config.js` dynamic, so can use it to do some real magic ✨

**postcss.config.js**
**`postcss.config.js`**
```js
module.exports = ({ file, options, env }) => ({
parser: file.extname === '.sss' ? 'sugarss' : false,
plugins: {
'postcss-import': { root: file.dirname },
'postcss-cssnext': options.cssnext ? options.cssnext : false,
'autoprefixer': env == 'production' ? options.autoprefixer : false,
'postcss-preset-env': options['postcss-preset-env'] ? options['postcss-preset-env'] : false,
'cssnano': env === 'production' ? options.cssnano : false
}
})
```

**webpack.config.js**
**`webpack.config.js`**
```js
{
loader: 'postcss-loader',
options: {
config: {
ctx: {
cssnext: {...options},
'postcss-preset-env': {...options},
cssnano: {...options},
autoprefixer: {...options}
}
}
}
@@ -199,16 +203,15 @@ module.exports = ({ file, options, env }) => ({

### `Plugins`

**webpack.config.js**
**`webpack.config.js`**
```js
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: (loader) => [
require('postcss-import')({ root: loader.resourcePath }),
require('postcss-cssnext')(),
require('autoprefixer')(),
require('postcss-preset-env')(),
require('cssnano')()
]
}
@@ -227,7 +230,7 @@ module.exports = ({ file, options, env }) => ({

#### `Parser`

**webpack.config.js**
**`webpack.config.js`**
```js
{
test: /\.sss$/,
@@ -240,7 +243,7 @@ module.exports = ({ file, options, env }) => ({

#### `Syntax`

**webpack.config.js**
**`webpack.config.js`**
```js
{
test: /\.css$/,
@@ -253,7 +256,7 @@ module.exports = ({ file, options, env }) => ({

#### `Stringifier`

**webpack.config.js**
**`webpack.config.js`**
```js
{
test: /\.css$/,
@@ -268,9 +271,7 @@ module.exports = ({ file, options, env }) => ({

Enables source map support, `postcss-loader` will use the previous source map given by other loaders and update it accordingly, if no previous loader is applied before `postcss-loader`, the loader will generate a source map for you.

> :warning: If a previous loader like e.g `sass-loader` is applied and it's `sourceMap` option is set, but the `sourceMap` option in `postcss-loader` is omitted, previous source maps will be discarded by `postcss-loader` **entirely**.
**webpack.config.js**
**`webpack.config.js`**
```js
{
test: /\.css/,
@@ -288,7 +289,7 @@ Enables source map support, `postcss-loader` will use the previous source map gi
You can set the `sourceMap: 'inline'` option to inline the source map
within the CSS directly as an annotation comment.

**webpack.config.js**
**`webpack.config.js`**
```js
{
loader: 'postcss-loader',
@@ -308,7 +309,7 @@ within the CSS directly as an annotation comment.

### `Stylelint`

**webpack.config.js**
**`webpack.config.js`**
```js
{
test: /\.css$/,
@@ -330,13 +331,38 @@ within the CSS directly as an annotation comment.
}
```

### `Autoprefixing`

**`webpack.config.js`**
```js
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
require('autoprefixer')({...options}),
...,
]
}
}
]
}
```

> :warning: [`postcss-preset-env`](https://github.com/csstools/postcss-preset-env) includes [`autoprefixer`](https://github.com/postcss/autoprefixer), so adding it separately is not necessary if you already use the preset.
### `CSS Modules`

This loader [cannot be used] with [CSS Modules] out of the box due
to the way `css-loader` processes file imports. To make them work properly,
either add the css-loader’s [`importLoaders`] option.

**webpack.config.js**
**`webpack.config.js`**
```js
{
test: /\.css$/,
@@ -350,17 +376,18 @@ either add the css-loader’s [`importLoaders`] option.

or use [postcss-modules] instead of `css-loader`.

[`importLoaders`]: https://github.com/webpack-contrib/css-loader#importing-and-chained-loaders
[`importLoaders`]: https://github.com/webpack-contrib/css-loader#importloaders
[cannot be used]: https://github.com/webpack/css-loader/issues/137
[CSS Modules]: https://github.com/webpack/css-loader#css-modules
[postcss-modules]: https://github.com/outpunk/postcss-modules
[postcss-modules]: https://github.com/css-modules/postcss-modules

### `CSS-in-JS`

If you want to process styles written in JavaScript, use the [postcss-js] parser.

[postcss-js]: https://github.com/postcss/postcss-js

**`webpack.config.js`**
```js
{
test: /\.style.js$/,
@@ -398,29 +425,31 @@ export default {

### [Extract CSS][ExtractPlugin]

[ExtractPlugin]: https://github.com/webpack-contrib/extract-text-webpack-plugin
[ExtractPlugin]: https://github.com/webpack-contrib/mini-css-extract-plugin

**webpack.config.js**
**`webpack.config.js`**
```js
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const devMode = process.env.NODE_ENV !== 'production'

const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{ loader: 'css-loader', options: { importLoaders: 1 } },
'postcss-loader'
]
})
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader'
]
}
]
},
plugins: [
new ExtractTextPlugin('[name].css')
new MiniCssExtractPlugin({
filename: devMode ? '[name].css' : '[name].[hash].css'
})
]
}
```
@@ -458,7 +487,7 @@ module.exports = {
[deps]: https://david-dm.org/postcss/postcss-loader.svg
[deps-url]: https://david-dm.org/postcss/postcss-loader

[tests]: http://img.shields.io/travis/postcss/postcss-loader.svg
[tests]: https://img.shields.io/travis/postcss/postcss-loader.svg
[tests-url]: https://travis-ci.org/postcss/postcss-loader

[cover]: https://coveralls.io/repos/github/postcss/postcss-loader/badge.svg
21 changes: 21 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
init:
- git config --global core.autocrlf input

build: 'off'

matrix:
fast_finish: true

environment:
matrix:
- nodejs_version: '10'
- nodejs_version: '8'
- nodejs_version: '6'

install:
- ps: Install-Product node $env:nodejs_version x64
- npm i -g npm
- npm i

test_script:
- npm t
130 changes: 130 additions & 0 deletions docs/LOADER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
## Modules

<dl>
<dt><a href="#module_postcss-loader">postcss-loader</a></dt>
<dd></dd>
</dl>

## Classes

<dl>
<dt><a href="#SyntaxError">SyntaxError</a> ⇐ <code>Error</code></dt>
<dd></dd>
<dt><a href="#Warning">Warning</a> ⇐ <code>Error</code></dt>
<dd></dd>
</dl>

## Functions

<dl>
<dt><a href="#loader">loader(css, map)</a> ⇒ <code>cb</code></dt>
<dd><p><strong>PostCSS Loader</strong></p>
<p>Loads &amp;&amp; processes CSS with <a href="https://github.com/postcss/postcss">PostCSS</a></p>
</dd>
<dt><a href="#parseOptions">parseOptions(exec, parser, syntax, stringifier, plugins)</a> ⇒ <code>Promise</code></dt>
<dd><p><strong>PostCSS Options Parser</strong></p>
<p>Transforms the loader options into a valid postcss config <code>{Object}</code></p>
</dd>
</dl>

<a name="module_postcss-loader"></a>

## postcss-loader
**Requires**: <code>module:path</code>, <code>module:loader-utils</code>, <code>module:schema-utils</code>, <code>module:postcss</code>, <code>module:postcss-load-config</code>, <code>module:./options.js</code>, <code>module:./Warning.js</code>, <code>module:./SyntaxError.js</code>
**Version**: 3.0.0
**Author**: Andrey Sitnik (@ai) <andrey@sitnik.ru>
**License**: MIT
<a name="SyntaxError"></a>

## SyntaxError ⇐ <code>Error</code>
**Kind**: global class
**Extends**: <code>Error</code>
<a name="new_SyntaxError_new"></a>

### new SyntaxError(err)
**PostCSS Syntax Error**

Loader wrapper for postcss syntax errors


| Param | Type | Description |
| --- | --- | --- |
| err | <code>Object</code> | CssSyntaxError |

<a name="Warning"></a>

## Warning ⇐ <code>Error</code>
**Kind**: global class
**Extends**: <code>Error</code>
<a name="new_Warning_new"></a>

### new Warning(warning)
**PostCSS Plugin Warning**

Loader wrapper for postcss plugin warnings (`root.messages`)


| Param | Type | Description |
| --- | --- | --- |
| warning | <code>Object</code> | PostCSS Warning |

<a name="loader"></a>

## loader(css, map) ⇒ <code>cb</code>
**PostCSS Loader**

Loads && processes CSS with [PostCSS](https://github.com/postcss/postcss)

**Kind**: global function
**Returns**: <code>cb</code> - cb Result

| Param | Type | Description |
| --- | --- | --- |
| css | <code>String</code> | Source |
| map | <code>Object</code> | Source Map |


* [loader(css, map)](#loader) ⇒ <code>cb</code>
* [.cb](#loader.cb) : <code>function</code>
* [.cb](#loader.cb) : <code>function</code>

<a name="loader.cb"></a>

### loader.cb : <code>function</code>
**Kind**: static typedef of [<code>loader</code>](#loader)

| Param | Type | Description |
| --- | --- | --- |
| null | <code>Object</code> | Error |
| css | <code>String</code> | Result (JS Module) |
| map | <code>Object</code> | Source Map |

<a name="loader.cb"></a>

### loader.cb : <code>function</code>
**Kind**: static typedef of [<code>loader</code>](#loader)

| Param | Type | Description |
| --- | --- | --- |
| null | <code>Object</code> | Error |
| css | <code>String</code> | Result (Raw Module) |
| map | <code>Object</code> | Source Map |

<a name="parseOptions"></a>

## parseOptions(exec, parser, syntax, stringifier, plugins) ⇒ <code>Promise</code>
**PostCSS Options Parser**

Transforms the loader options into a valid postcss config `{Object}`

**Kind**: global function
**Returns**: <code>Promise</code> - PostCSS Config

| Param | Type | Description |
| --- | --- | --- |
| exec | <code>Boolean</code> | Execute CSS-in-JS |
| parser | <code>String</code> \| <code>Object</code> | PostCSS Parser |
| syntax | <code>String</code> \| <code>Object</code> | PostCSS Syntax |
| stringifier | <code>String</code> \| <code>Object</code> | PostCSS Stringifier |
| plugins | <code>Array</code> \| <code>Object</code> \| <code>function</code> | PostCSS Plugins |

17 changes: 0 additions & 17 deletions lib/Error.js

This file was deleted.

25 changes: 0 additions & 25 deletions lib/options.js

This file was deleted.

40 changes: 0 additions & 40 deletions lib/options.json

This file was deleted.

55 changes: 20 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,38 @@
{
"name": "postcss-loader",
"version": "2.0.8",
"version": "3.0.0",
"description": "PostCSS loader for webpack",
"main": "lib/index.js",
"engines": {
"node": ">= 4"
},
"main": "src/index.js",
"files": [
"lib"
"src"
],
"engines": {
"node": ">= 6"
},
"dependencies": {
"loader-utils": "^1.1.0",
"postcss": "^6.0.0",
"postcss-load-config": "^1.2.0",
"schema-utils": "^0.3.0"
"postcss": "^7.0.0",
"postcss-load-config": "^2.0.0",
"schema-utils": "^1.0.0"
},
"devDependencies": {
"coveralls": "^2.0.0",
"jest": "^21.0.0",
"jsdoc-to-markdown": "^3.0.0",
"memory-fs": "^0.4.0",
"postcss-js": "^1.0.0",
"standard": "^10.0.0",
"@webpack-utilities/test": "^1.0.0-alpha.0",
"jest": "^23.0.0",
"jsdoc-to-markdown": "^4.0.0",
"postcss-import": "^11.0.0",
"postcss-js": "^2.0.0",
"standard": "^11.0.0",
"standard-version": "^4.0.0",
"sugarss": "^1.0.0",
"webpack": "^3.0.0"
"webpack": "^4.0.0"
},
"scripts": {
"clean": "rm -rf dmd jest* coverage jsdoc-api test/results",
"lint": "standard",
"docs": "jsdoc2md lib/index.js > LOADER.md",
"postdocs": "npm run clean",
"pretest": "npm run clean",
"test": "jest --verbose --coverage",
"lint": "standard --env jest",
"test": "jest --env node --verbose --coverage",
"docs": "jsdoc2md src/*.js > docs/LOADER.md",
"clean": "rm -rf coverage test/outputs",
"release": "standard-version"
},
"jest": {
"collectCoverageFrom": [
"lib/*.js"
]
},
"standard": {
"env": {
"jest": true
},
"ignore": [
"*.test.js"
]
},
"keywords": [
"css",
"postcss",
37 changes: 37 additions & 0 deletions src/Error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* **PostCSS Syntax Error**
*
* Loader wrapper for postcss syntax errors
*
* @class SyntaxError
* @extends Error
*
* @param {Object} err CssSyntaxError
*/
class SyntaxError extends Error {
constructor (error) {
super(error)

const { line, column, reason } = error

this.name = 'SyntaxError'

this.message = `${this.name}\n\n`

if (typeof line !== 'undefined') {
this.message += `(${line}:${column}) `
}

this.message += `${reason}`

const code = error.showSourceCode()

if (code) {
this.message += `\n\n${code}\n`
}

this.stack = false
}
}

module.exports = SyntaxError
31 changes: 31 additions & 0 deletions src/Warning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* **PostCSS Plugin Warning**
*
* Loader wrapper for postcss plugin warnings (`root.messages`)
*
* @class Warning
* @extends Error
*
* @param {Object} warning PostCSS Warning
*/
class Warning extends Error {
constructor (warning) {
super(warning)

const { text, line, column } = warning

this.name = 'Warning'

this.message = `${this.name}\n\n`

if (typeof line !== 'undefined') {
this.message += `(${line}:${column}) `
}

this.message += `${text}`

this.stack = false
}
}

module.exports = Warning
151 changes: 98 additions & 53 deletions lib/index.js → src/index.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,29 @@
'use strict'

const path = require('path')

const loaderUtils = require('loader-utils')

const parseOptions = require('./options')
const { getOptions } = require('loader-utils')
const validateOptions = require('schema-utils')

const postcss = require('postcss')
const postcssrc = require('postcss-load-config')

const SyntaxError = require('./Error')
const Warning = require('./Warning.js')
const SyntaxError = require('./Error.js')
const parseOptions = require('./options.js')

/**
* PostCSS Loader
* **PostCSS Loader**
*
* > Loads && processes CSS with [PostCSS](https://github.com/postcss/postcss)
*
* @author Andrey Sitnik (@ai) <andrey@sitnik.ru>
*
* @license MIT
* @version 2.0.0
*
* @requires path
*
* @requires loader-utils
* @requires schema-utils
*
* @requires postcss
* @requires postcss-load-config
*
* @requires Error
* Loads && processes CSS with [PostCSS](https://github.com/postcss/postcss)
*
* @method loader
*
* @param {String} css Source
* @param {Object} map Source Map
* @param {String} css Source
* @param {Object} map Source Map
*
* @return {cb} cb Result
* @return {cb} cb Result
*/
module.exports = function loader (css, map) {
const options = loaderUtils.getOptions(this) || {}
function loader (css, map, meta) {
const options = Object.assign({}, getOptions(this))

validateOptions(require('./options.json'), options, 'PostCSS Loader')

@@ -52,11 +35,15 @@ module.exports = function loader (css, map) {
Promise.resolve().then(() => {
const length = Object.keys(options)
.filter((option) => {
// if (option === 'exec') return
if (option === 'config') return
if (option === 'sourceMap') return

return option
switch (option) {
// case 'exec':
case 'ident':
case 'config':
case 'sourceMap':
return
default:
return option
}
})
.length

@@ -86,20 +73,30 @@ module.exports = function loader (css, map) {
}
}

return postcssrc(rc.ctx, rc.path, { argv: false })
rc.ctx.webpack = this

return postcssrc(rc.ctx, rc.path)
}).then((config) => {
if (!config) config = {}
if (!config) {
config = {}
}

if (config.file) this.addDependency(config.file)
if (config.file) {
this.addDependency(config.file)
}

// Disable override `to` option from `postcss.config.js`
if (config.options.to) delete config.options.to
if (config.options.to) {
delete config.options.to
}
// Disable override `from` option from `postcss.config.js`
if (config.options.from) delete config.options.from
if (config.options.from) {
delete config.options.from
}

let plugins = config.plugins || []

let options = Object.assign({
to: file,
from: file,
map: sourceMap
? sourceMap === 'inline'
@@ -132,43 +129,63 @@ module.exports = function loader (css, map) {
css = this.exec(css, this.resource)
}

if (!sourceMap && map) {
this.emitWarning(`\n\n ⚠️ PostCSS Loader\n\nPrevious source map found, but options.sourceMap isn't set.\nIn this case the loader will discard the source map entirely for performance reasons.\nSee https://github.com/postcss/postcss-loader#sourcemap for more information.\n\n`)
if (sourceMap && typeof map === 'string') {
map = JSON.parse(map)
}

if (sourceMap && typeof map === 'string') map = JSON.parse(map)
if (sourceMap && map) options.map.prev = map
if (sourceMap && map) {
options.map.prev = map
}

return postcss(plugins)
.process(css, options)
.then((result) => {
result.warnings().forEach((msg) => this.emitWarning(msg.toString()))
let { css, map, root, processor, messages } = result

result.warnings().forEach((warning) => {
this.emitWarning(new Warning(warning))
})

result.messages.forEach((msg) => {
if (msg.type === 'dependency') this.addDependency(msg.file)
messages.forEach((msg) => {
if (msg.type === 'dependency') {
this.addDependency(msg.file)
}
})

css = result.css
map = result.map ? result.map.toJSON() : null
map = map ? map.toJSON() : null

if (map) {
map.file = path.resolve(map.file)
map.sources = map.sources.map((src) => path.resolve(src))
}

if (!meta) {
meta = {}
}

const ast = {
type: 'postcss',
version: processor.version,
root
}

meta.ast = ast
meta.messages = messages

if (this.loaderIndex === 0) {
/**
* @memberof loader
* @callback cb
*
* @param {Object} null Error
* @param {String} result Result (JS Module)
* @param {Object} map Source Map
* @param {Object} null Error
* @param {String} css Result (JS Module)
* @param {Object} map Source Map
*/
cb(null, `module.exports = ${JSON.stringify(css)}`, map)

return null
}

/**
* @memberof loader
* @callback cb
@@ -177,11 +194,39 @@ module.exports = function loader (css, map) {
* @param {String} css Result (Raw Module)
* @param {Object} map Source Map
*/
cb(null, css, map)
cb(null, css, map, meta)

return null
})
}).catch((err) => {
return err.name === 'CssSyntaxError' ? cb(new SyntaxError(err)) : cb(err)
if (err.file) {
this.addDependency(err.file)
}

return err.name === 'CssSyntaxError'
? cb(new SyntaxError(err))
: cb(err)
})
}

/**
* @author Andrey Sitnik (@ai) <andrey@sitnik.ru>
*
* @license MIT
* @version 3.0.0
*
* @module postcss-loader
*
* @requires path
*
* @requires loader-utils
* @requires schema-utils
*
* @requires postcss
* @requires postcss-load-config
*
* @requires ./options.js
* @requires ./Warning.js
* @requires ./SyntaxError.js
*/
module.exports = loader
36 changes: 36 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* **PostCSS Options Parser**
*
* Transforms the loader options into a valid postcss config `{Object}`
*
* @method parseOptions
*
* @param {Boolean} exec Execute CSS-in-JS
* @param {String|Object} parser PostCSS Parser
* @param {String|Object} syntax PostCSS Syntax
* @param {String|Object} stringifier PostCSS Stringifier
* @param {Array|Object|Function} plugins PostCSS Plugins
*
* @return {Promise} PostCSS Config
*/
function parseOptions ({ exec, parser, syntax, stringifier, plugins }) {
if (typeof plugins === 'function') {
plugins = plugins.call(this, this)
}

if (typeof plugins === 'undefined') {
plugins = []
} else if (!Array.isArray(plugins)) {
plugins = [ plugins ]
}

const options = {}

options.parser = parser
options.syntax = syntax
options.stringifier = stringifier

return Promise.resolve({ options, plugins, exec })
}

module.exports = parseOptions
57 changes: 57 additions & 0 deletions src/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"type": "object",
"properties": {
"config": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"ctx": {
"type": "object"
}
},
"errorMessage": {
"properties": {
"ctx": "should be {Object} (https://github.com/postcss/postcss-loader#context-ctx)",
"path": "should be {String} (https://github.com/postcss/postcss-loader#path)"
}
},
"additionalProperties": false
},
"exec": {
"type": "boolean"
},
"parser": {
"type": [ "string", "object" ]
},
"syntax": {
"type": [ "string", "object" ]
},
"stringifier": {
"type": [ "string", "object" ]
},
"plugins": {
"anyOf": [
{ "type": "array" },
{ "type": "object" },
{ "instanceof": "Function" }
]
},
"sourceMap": {
"type": [ "string", "boolean" ]
}
},
"errorMessage": {
"properties": {
"exec": "should be {Boolean} (https://github.com/postcss/postcss-loader#exec)",
"config": "should be {Object} (https://github.com/postcss/postcss-loader#config)",
"parser": "should be {String|Object} (https://github.com/postcss/postcss-loader#parser)",
"syntax": "should be {String|Object} (https://github.com/postcss/postcss-loader#syntax)",
"stringifier": "should be {String|Object} (https://github.com/postcss/postcss-loader#stringifier)",
"plugins": "should be {Array|Object|Function} (https://github.com/postcss/postcss-loader#plugins)",
"sourceMap": "should be {String|Boolean} (https://github.com/postcss/postcss-loader#sourcemap)"
}
},
"additionalProperties": true
}
54 changes: 44 additions & 10 deletions test/Errors.test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,65 @@
'use strict'

const webpack = require('./helpers/compiler')
const { loader } = require('./helpers/compilation')
const { webpack } = require('@webpack-utilities/test')

describe('Errors', () => {
test('Validation Error', () => {
const loader = require('../lib')
const config = {
loader: {
test: /\.css$/,
options: {
sourceMap: 1
}
}
}

return webpack('css/index.js', config).then((stats) => {
const { source } = stats.toJson().modules[1]

const error = () => loader.call({ query: { sourceMap: 1 } })
// eslint-disable-next-line
const error = () => eval(source)

expect(error).toThrow()
expect(error).toThrowErrorMatchingSnapshot()
expect(error).toThrow()

try {
error()
} catch (err) {
const message = err.message
.split('\n\n')
.slice(1, -1)
.join('\n\n')

expect(message).toMatchSnapshot()
}
})
})

test('Syntax Error', () => {
const config = {
loader: {
test: /\.css$/,
options: {
parser: 'sugarss'
}
}
}

return webpack('css/index.js', config).then((stats) => {
const error = loader(stats).err
const { source } = stats.toJson().modules[1]

expect(error[0]).toMatchSnapshot()
// eslint-disable-next-line
const error = () => eval(source)

expect(error).toThrow()

try {
error()
} catch (err) {
const message = err.message
.split('\n')
.slice(1)
.join('\n')

expect(message).toMatchSnapshot()
}
})
})
})
33 changes: 33 additions & 0 deletions test/Warnings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { webpack } = require('@webpack-utilities/test')

const plugin = (options = {}) => (css, result) => {
css.walkDecls((node) => {
node.warn(result, '<Message>')
})
}

describe('Warnings', () => {
test('Plugins', () => {
const config = {
loader: {
test: /\.css$/,
options: {
plugins: [
plugin()
]
}
}
}

return webpack('css/index.js', config).then((stats) => {
const warning = stats.compilation.warnings[0]

const message = warning.message
.split('\n')
.slice(1)
.join('\n')

expect(message).toMatchSnapshot()
})
})
})
13 changes: 3 additions & 10 deletions test/__snapshots__/Errors.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Errors Syntax Error 1`] = `
[ModuleBuildError: Module build failed: Syntax Error
"SyntaxError
(1:3) Unexpected separator in property
> 1 | a { color: black }
 |  ^
 2 | 
]
`;
exports[`Errors Validation Error 1`] = `
"Validation Error
PostCSS Loader Invalid Options
options.sourceMap should be string,boolean
"
`;
exports[`Errors Validation Error 1`] = `"options.sourceMap should be {String|Boolean} (https://github.com/postcss/postcss-loader#sourcemap)"`;
7 changes: 7 additions & 0 deletions test/__snapshots__/Warnings.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Warnings Plugins 1`] = `
"Warning
(1:5) <Message>"
`;
15 changes: 15 additions & 0 deletions test/fixtures/config/context/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

const postcss = require('postcss')

// This plugin creates asset file in webpack compilation
module.exports = postcss.plugin('plugin', (ctx) => {
ctx.webpack._compilation.assets['asset.txt'] = {
source () {
return '123'
},
size () {
return 0
}
}
})
5 changes: 5 additions & 0 deletions test/fixtures/config/context/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = (ctx) => ({
plugins: [
require('./plugin')(ctx)
]
})
66 changes: 0 additions & 66 deletions test/helpers/compilation.js

This file was deleted.

53 changes: 0 additions & 53 deletions test/helpers/compiler.js

This file was deleted.

14 changes: 6 additions & 8 deletions test/loader.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
'use strict'

const webpack = require('./helpers/compiler')
const { loader } = require('./helpers/compilation')
const { webpack } = require('@webpack-utilities/test')

describe('Loader', () => {
test('Default', () => {
const config = {
loader: {
test: /\.css$/,
options: {
plugins: []
}
}
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toEqual("module.exports = \"a { color: black }\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toEqual('module.exports = "a { color: black }\\n"')
expect(source).toMatchSnapshot()
})
})
})
2 changes: 2 additions & 0 deletions test/options/__snapshots__/config.test.js.snap
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

exports[`Options Config - {Object} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;

exports[`Options Config - Context - {Object} - with ident 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;

exports[`Options Config - Context - {Object} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;

exports[`Options Config - Path - {String} 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`;
6 changes: 3 additions & 3 deletions test/options/__snapshots__/sourceMap.test.js.snap
Original file line number Diff line number Diff line change
@@ -4,11 +4,11 @@ exports[`Options Sourcemap - {Boolean} 1`] = `"module.exports = \\"a { color: rg

exports[`Options Sourcemap - {Boolean} 2`] = `
Object {
"file": "../../style.css",
"file": "../fixtures/css/style.css",
"mappings": "AAAA,IAAI,2BAAY,EAAE",
"names": Array [],
"sources": Array [
"../../style.css",
"../fixtures/css/style.css",
],
"sourcesContent": Array [
"a { color: black }
@@ -18,4 +18,4 @@ Object {
}
`;

exports[`Options Sourcemap - {String} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\\\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxJQUFJLDJCQUFZLEVBQUUiLCJmaWxlIjoic3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYSB7IGNvbG9yOiBibGFjayB9XG4iXX0= */\\""`;
exports[`Options Sourcemap - {String} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\\\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvZml4dHVyZXMvY3NzL3N0eWxlLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxJQUFJLDJCQUFZLEVBQUUiLCJmaWxlIjoidGVzdC9maXh0dXJlcy9jc3Mvc3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYSB7IGNvbG9yOiBibGFjayB9XG4iXX0= */\\""`;
88 changes: 71 additions & 17 deletions test/options/config.test.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
'use strict'

const webpack = require('../helpers/compiler')
const { loader } = require('../helpers/compilation')
const { webpack } = require('@webpack-utilities/test')

describe('Options', () => {
test('Config - {Object}', () => {
const config = {
loader: {}
loader: {
test: /\.css$/
}
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toEqual(
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
)

expect(source).toMatchSnapshot()
})
})

test('Config - Path - {String}', () => {
const config = {
loader: {
test: /\.css$/,
options: {
config: { path: 'test/fixtures/config/postcss.config.js' }
}
}
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toEqual("module.exports = \"a { color: black }\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toEqual('module.exports = "a { color: black }\\n"')
expect(source).toMatchSnapshot()
})
})

test('Config - Context - {Object}', () => {
const config = {
loader: {
test: /\.css$/,
options: {
config: {
path: 'test/fixtures/config/postcss.config.js',
@@ -47,10 +51,60 @@ describe('Options', () => {
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(source).toEqual(
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
)

expect(source).toMatchSnapshot()
})
})

test('Config - Context - {Object} - with ident', () => {
const config = {
loader: {
test: /\.css$/,
options: {
ident: 'postcss',
config: {
path: 'test/fixtures/config/postcss.config.js',
ctx: { plugin: true }
}
}
}
}

return webpack('css/index.js', config).then((stats) => {
const { source } = stats.toJson().modules[1]

expect(source).toEqual(
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
)

expect(source).toMatchSnapshot()
})
})

test('Config – Context – Loader {Object}', () => {
const config = {
loader: {
test: /\.css$/,
options: {
config: {
path: 'test/fixtures/config/context/postcss.config.js'
}
}
}
}

return webpack('css/index.js', config).then((stats) => {
const { assets } = stats.compilation

const asset = 'asset.txt'

expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
expect(src).toMatchSnapshot()
})
expect(asset in assets).toBeTruthy()
expect(assets[asset].source()).toBe('123')
})
})
})
22 changes: 11 additions & 11 deletions test/options/exec.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
'use strict'

const webpack = require('../helpers/compiler')
const { loader } = require('../helpers/compilation')
const { webpack } = require('@webpack-utilities/test')

describe('Options', () => {
test('Exec - {Boolean}', () => {
@@ -15,11 +12,14 @@ describe('Options', () => {
}

return webpack('jss/exec/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(source).toEqual(
'module.exports = "a {\\n color: green\\n}"'
)

expect(src).toEqual("module.exports = \"a {\\n color: green\\n}\"")
expect(src).toMatchSnapshot()
})
expect(source).toMatchSnapshot()
})
})

test('JSS - {String}', () => {
@@ -32,9 +32,9 @@ describe('Options', () => {
}

return webpack('jss/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toMatchSnapshot()
})
expect(source).toMatchSnapshot()
})
})
})
23 changes: 11 additions & 12 deletions test/options/parser.test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
'use strict'

const webpack = require('../helpers/compiler')
const { loader } = require('../helpers/compilation')
const { webpack } = require('@webpack-utilities/test')

describe('Options', () => {
test('Parser - {String}', () => {
const config = {
loader: {
test: /\.sss$/,
options: {
parser: 'sugarss'
}
}
}

return webpack('sss/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toEqual("module.exports = \"a {\\n color: black\\n}\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toEqual('module.exports = "a {\\n color: black\\n}\\n"')
expect(source).toMatchSnapshot()
})
})

test('Parser - {Object}', () => {
const config = {
loader: {
test: /\.sss$/,
options: {
ident: 'postcss',
parser: require('sugarss')
@@ -32,10 +31,10 @@ describe('Options', () => {
}

return webpack('sss/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toEqual("module.exports = \"a {\\n color: black\\n}\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toEqual('module.exports = "a {\\n color: black\\n}\\n"')
expect(source).toMatchSnapshot()
})
})
})
53 changes: 33 additions & 20 deletions test/options/plugins.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict'

const webpack = require('../helpers/compiler')
const { loader } = require('../helpers/compilation')
const { webpack } = require('@webpack-utilities/test')

describe('Options', () => {
test('Plugins - {Array}', () => {
const config = {
loader: {
test: /\.css$/,
options: {
ident: 'postcss',
plugins: [ require('../fixtures/config/plugin')() ]
@@ -15,16 +13,20 @@ describe('Options', () => {
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(source).toEqual(
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
)

expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toMatchSnapshot()
})
})

test('Plugins - {Object}', () => {
const config = {
loader: {
test: /\.css$/,
options: {
ident: 'postcss',
plugins: require('../fixtures/config/plugin')
@@ -33,16 +35,20 @@ describe('Options', () => {
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(source).toEqual(
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
)

expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toMatchSnapshot()
})
})

test('Plugins - {Function} - {Array}', () => {
const config = {
loader: {
test: /\.css$/,
options: {
ident: 'postcss',
plugins: () => [ require('../fixtures/config/plugin')() ]
@@ -51,16 +57,20 @@ describe('Options', () => {
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toEqual(
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
)

expect(source).toMatchSnapshot()
})
})

test('Plugins - {Function} - {Object}', () => {
const config = {
loader: {
test: /\.css$/,
options: {
ident: 'postcss',
plugins: () => require('../fixtures/config/plugin')()
@@ -69,10 +79,13 @@ describe('Options', () => {
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(source).toEqual(
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
)

expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toMatchSnapshot()
})
})
})
40 changes: 24 additions & 16 deletions test/options/sourceMap.test.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,56 @@
'use strict'

const path = require('path')
const webpack = require('../helpers/compiler')
const { loader } = require('../helpers/compilation')
const { webpack } = require('@webpack-utilities/test')

describe('Options', () => {
test('Sourcemap - {Boolean}', () => {
const config = {
devtool: 'sourcemap',
loader: {
test: /\.css$/,
options: {
sourceMap: true
}
}
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(source).toEqual(
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
)

expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
expect(src).toMatchSnapshot()
expect(source).toMatchSnapshot()

const map = loader(stats).map
const map = stats.compilation.modules[1]._source._sourceMap

map.file = path.relative(__dirname, map.file)
map.sources = map.sources.map((src) => path.relative(__dirname, src))
map.file = path.posix.relative(__dirname, map.file)
map.sources = map.sources.map(
(src) => path.posix.relative(__dirname, src)
)

expect(map).toMatchSnapshot()
})
expect(map).toMatchSnapshot()
})
})

test('Sourcemap - {String}', () => {
const config = {
loader: {
test: /\.css$/,
options: {
sourceMap: 'inline'
}
}
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(source).toEqual(
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n\\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvZml4dHVyZXMvY3NzL3N0eWxlLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxJQUFJLDJCQUFZLEVBQUUiLCJmaWxlIjoidGVzdC9maXh0dXJlcy9jc3Mvc3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYSB7IGNvbG9yOiBibGFjayB9XG4iXX0= */"'
)

expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxJQUFJLDJCQUFZLEVBQUUiLCJmaWxlIjoic3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYSB7IGNvbG9yOiBibGFjayB9XG4iXX0= */\"")
expect(src).toMatchSnapshot()
})
expect(source).toMatchSnapshot()
})
})
})
23 changes: 11 additions & 12 deletions test/options/stringifier.test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
'use strict'

const webpack = require('../helpers/compiler')
const { loader } = require('../helpers/compilation')
const { webpack } = require('@webpack-utilities/test')

describe('Options', () => {
test('Stringifier - {String}', () => {
const config = {
loader: {
test: /\.css$/,
options: {
stringifier: 'sugarss'
}
}
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toEqual("module.exports = \"a color: black\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toEqual('module.exports = "a color: black\\n"')
expect(source).toMatchSnapshot()
})
})

test('Stringifier - {Object}', () => {
const config = {
loader: {
test: /\.css$/,
options: {
ident: 'postcss',
stringifier: require('sugarss')
@@ -32,10 +31,10 @@ describe('Options', () => {
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toEqual("module.exports = \"a color: black\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toEqual('module.exports = "a color: black\\n"')
expect(source).toMatchSnapshot()
})
})
})
23 changes: 11 additions & 12 deletions test/options/syntax.test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
'use strict'

const webpack = require('../helpers/compiler')
const { loader } = require('../helpers/compilation')
const { webpack } = require('@webpack-utilities/test')

describe('Options', () => {
test('Syntax - {String}', () => {
const config = {
loader: {
test: /\.sss$/,
options: {
syntax: 'sugarss'
}
}
}

return webpack('sss/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toEqual("module.exports = \"a\\n color: black\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toEqual('module.exports = "a\\n color: black\\n"')
expect(source).toMatchSnapshot()
})
})

test('Syntax - {Object}', () => {
const config = {
loader: {
test: /\.sss$/,
options: {
ident: 'postcss',
syntax: require('sugarss')
@@ -32,10 +31,10 @@ describe('Options', () => {
}

return webpack('sss/index.js', config).then((stats) => {
const src = loader(stats).src
const { source } = stats.toJson().modules[1]

expect(src).toEqual("module.exports = \"a\\n color: black\\n\"")
expect(src).toMatchSnapshot()
})
expect(source).toEqual('module.exports = "a\\n color: black\\n"')
expect(source).toMatchSnapshot()
})
})
})