Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ module.exports = function loader (css, map, meta) {
}
}

rc.ctx.webpack = this;

return postcssrc(rc.ctx, rc.path, { argv: false })
}).then((config) => {
if (!config) config = {}
Expand Down
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)
]
})
20 changes: 20 additions & 0 deletions test/options/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,24 @@ describe('Options', () => {
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');
})
})
})