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: 49557925544de7b5ec7f922be29af1cf43a69e20
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: node_js

node_js:
- "node"
- stable
- lts/*
- 6

after_success:
95 changes: 95 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,101 @@

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="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)

8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ 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`

@@ -175,7 +175,7 @@ module.exports = ({ file, options, env }) => ({
plugins: {
'postcss-import': { root: file.dirname },
'postcss-cssnext': options.cssnext ? options.cssnext : false,
'autoprefixer': env == 'production' ? options.autoprefixer : false,
'autoprefixer': env === 'production' ? options.autoprefixer : false,
'cssnano': env === 'production' ? options.cssnano : false
}
})
@@ -268,8 +268,6 @@ 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**
```js
{
@@ -350,7 +348,7 @@ 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
37 changes: 23 additions & 14 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -39,8 +39,8 @@ const SyntaxError = require('./Error')
*
* @return {cb} cb Result
*/
module.exports = function loader (css, map) {
const options = loaderUtils.getOptions(this) || {}
module.exports = function loader (css, map, meta) {
const options = Object.assign({}, loaderUtils.getOptions(this))

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

@@ -52,11 +52,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,7 +90,9 @@ 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 = {}

@@ -99,7 +105,6 @@ module.exports = function loader (css, map) {

let plugins = config.plugins || []
let options = Object.assign({
to: file,
from: file,
map: sourceMap
? sourceMap === 'inline'
@@ -132,10 +137,6 @@ 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 && map) options.map.prev = map

@@ -156,6 +157,11 @@ module.exports = function loader (css, map) {
map.sources = map.sources.map((src) => path.resolve(src))
}

if (!meta) meta = {}

meta.ast = { 'type': 'postcss', root: result.root }
meta.messages = result.messages

if (this.loaderIndex === 0) {
/**
* @memberof loader
@@ -169,6 +175,7 @@ module.exports = function loader (css, map) {

return null
}

/**
* @memberof loader
* @callback cb
@@ -177,11 +184,13 @@ 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) => {
if (err.file) this.addDependency(err.file)

return err.name === 'CssSyntaxError' ? cb(new SyntaxError(err)) : cb(err)
})
}
3 changes: 3 additions & 0 deletions lib/options.json
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@
"exec": {
"type": "boolean"
},
"ident": {
"type": "string"
},
"parser": {
"type": [ "string", "object" ]
},
42 changes: 14 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
{
"name": "postcss-loader",
"version": "2.0.8",
"version": "2.1.6",
"description": "PostCSS loader for webpack",
"main": "lib/index.js",
"engines": {
"node": ">= 4"
},
"files": [
"lib"
],
"engines": {
"node": ">= 4"
},
"dependencies": {
"loader-utils": "^1.1.0",
"postcss": "^6.0.0",
"postcss-load-config": "^1.2.0",
"schema-utils": "^0.3.0"
"postcss-load-config": "^2.0.0",
"schema-utils": "^0.4.0"
},
"devDependencies": {
"coveralls": "^2.0.0",
"jest": "^21.0.0",
"jsdoc-to-markdown": "^3.0.0",
"jest": "^22.0.0",
"jsdoc-to-markdown": "^4.0.0",
"memory-fs": "^0.4.0",
"postcss-import": "^11.0.0",
"postcss-js": "^1.0.0",
"standard": "^10.0.0",
"standard": "^11.0.0",
"standard-version": "^4.0.0",
"sugarss": "^1.0.0",
"util.promisify": "^1.0.0",
"webpack": "^3.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",
"lint": "standard --env jest",
"test": "jest --verbose --coverage",
"docs": "jsdoc2md lib/index.js > 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",
4 changes: 1 addition & 3 deletions test/__snapshots__/Errors.test.js.snap
Original file line number Diff line number Diff line change
@@ -12,9 +12,7 @@ exports[`Errors Syntax Error 1`] = `
`;
exports[`Errors Validation Error 1`] = `
"Validation Error
PostCSS Loader Invalid Options
"PostCSS Loader Invalid Options
options.sourceMap should be string,boolean
"
6 changes: 6 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Loader Default 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`;

exports[`Loader Watching Dependencies Error 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`;

exports[`Loader Watching Dependencies Error 2`] = `"throw new Error(\\"Module build failed: Syntax Error \\\\n\\\\n(1:5) Unknown word\\\\n\\\\n\\\\u001b[31m\\\\u001b[1m>\\\\u001b[22m\\\\u001b[39m\\\\u001b[90m 1 | \\\\u001b[39ma \\\\u001b[33m{\\\\u001b[39m color black \\\\u001b[33m}\\\\u001b[39m\\\\n \\\\u001b[90m | \\\\u001b[39m \\\\u001b[31m\\\\u001b[1m^\\\\u001b[22m\\\\u001b[39m\\\\n \\\\u001b[90m 2 | \\\\u001b[39m\\\\n\\");"`;
exports[`Loader Watching Dependencies Error 3`] = `"module.exports = \\"a { color: black }\\\\n\\""`;
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)
]
})
1 change: 1 addition & 0 deletions test/fixtures/watch/error.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a { color black }
1 change: 1 addition & 0 deletions test/fixtures/watch/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a { color: black }
3 changes: 3 additions & 0 deletions test/fixtures/watch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import style from './style.css'

export default style
1 change: 1 addition & 0 deletions test/fixtures/watch/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "./import";
24 changes: 17 additions & 7 deletions test/helpers/compiler.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ module.exports = function compiler (fixture, config, options) {
output: {
path: path.resolve(
__dirname,
`../results/${config.path ? config.path : ''}`
`../outputs/${config.path ? config.path : ''}`
),
filename: '[name].bundle.js'
},
@@ -31,7 +31,7 @@ module.exports = function compiler (fixture, config, options) {
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['runtime'],
name: [ 'runtime' ],
minChunks: Infinity
})
].concat(config.plugins || [])
@@ -43,11 +43,21 @@ module.exports = function compiler (fixture, config, options) {

if (!options.emit) compiler.outputFileSystem = new MemoryFS()

return new Promise((resolve, reject) => {
return compiler.run((err, stats) => {
if (err) reject(err)
if (options.watch) {
return new Promise((resolve, reject) => {
const watcher = compiler.watch({}, (err, stats) => {
options.watch(err, stats, () => {
watcher.close(resolve)
})
})
})
} else {
return new Promise((resolve, reject) => {
return compiler.run((err, stats) => {
if (err) reject(err)

resolve(stats)
resolve(stats)
})
})
})
}
}
38 changes: 38 additions & 0 deletions test/helpers/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const path = require('path')
const promisify = require('util.promisify')

const {
unlink: _unlink,
readFile: _readFile,
writeFile: _writeFile
} = require('fs')

const fs = {
readFile: promisify(_readFile),
writeFile: promisify(_writeFile),
unlink: promisify(_unlink)
}

function readFile (name) {
const file = path.join(__dirname, '../fixtures', name)

return fs.readFile(file)
.then((data) => data.toString())
}

function writeFile (name, data) {
const file = path.join(__dirname, '../fixtures', name)

return fs.writeFile(file, data)
}

module.exports.copyFile = function copyFile (src, dest) {
return readFile(src)
.then((data) => writeFile(dest, data))
}

module.exports.deleteFile = function deleteFile (name) {
const file = path.join(__dirname, '../fixtures', name)

return fs.unlink(file)
}
67 changes: 67 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

const webpack = require('./helpers/compiler')
const { loader } = require('./helpers/compilation')
const { copyFile, deleteFile } = require('./helpers/fs');

describe('Loader', () => {
test('Default', () => {
@@ -20,4 +21,70 @@ describe('Loader', () => {
expect(src).toMatchSnapshot()
})
})

describe('Watching', () => {
describe('Dependencies', () => {
const files = {
css: 'watch/index.css',
error: 'watch/error.css',
changed: 'watch/import.css'
}

beforeEach(() => copyFile(files.css, files.changed))

afterEach(() => deleteFile(files.changed))

test('Error', () => {
const config = {
loader: {
options: {
plugins: [
require('postcss-import')
],
}
}
}

const steps = [
(stats) => {
const { err, src } = loader(stats)

expect(src).toMatchSnapshot()
expect(err.length).toEqual(0)

return copyFile(files.error, files.changed)
},
(stats) => {
const { err, src } = loader(stats)

expect(src).toMatchSnapshot()
expect(err.length).toEqual(1)

return copyFile(files.css, files.changed)
},
(stats, close) => {
const { err, src } = loader(stats)

expect(src).toMatchSnapshot()
expect(src).toEqual("module.exports = \"a { color: black }\\n\"")
expect(err.length).toEqual(0)

return close()
}
]

let step = 0

const options = {
watch (err, stats, close) {
steps[step](stats, close)

step++
}
}

return webpack('watch/index.js', config, options)
})
})
})
})
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= */\\""`;
42 changes: 42 additions & 0 deletions test/options/config.test.js
Original file line number Diff line number Diff line change
@@ -53,4 +53,46 @@ describe('Options', () => {
expect(src).toMatchSnapshot()
})
})


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

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src

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

test('Pass loader object to config context', () => {
const config = {
loader: {
options: {
config: {
path: 'test/fixtures/config/context/postcss.config.js'
}
}
}
}

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

expect(expectedAssetName in assets).toBeTruthy();
expect(assets[expectedAssetName].source()).toBe('123');
})
})
})
2 changes: 1 addition & 1 deletion test/options/sourceMap.test.js
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ describe('Options', () => {
return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src

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