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
4 changes: 3 additions & 1 deletion lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ module.exports = class SpikeWebpackPlugin {
: JSON.parse(dep._source._value.replace(/^module\.exports = /, ''))

// calculate the output path
let outputPath = this.util.getOutputPath(f.path).relative
// this will use the special prop f.outPath as an override, which can
// be set by plugins to create a custom output path
let outputPath = this.util.getOutputPath(f.outPath || f.path).relative

// set the file's extension if necessary
if (f.extension) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/plugins/custom_output.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>my output path was rewritten by a plugin : (</p>
12 changes: 10 additions & 2 deletions test/fixtures/plugins/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ module.exports = class JadeWebpackPlugin {
}

apply (compiler) {
compiler.plugin('run', function (compilation, done) {
setTimeout(function () {
compiler.plugin('run', (compilation, done) => {
setTimeout(() => {
compiler.options.test = 'bar'
done()
}, 300)
})

compiler.plugin('emit', (compilation, done) => {
const file = compiler.options.spike.files.process.find((f) => {
if (f.path.match(/custom_output/)) { return f }
})
file.outPath = file.path.replace(/custom_output/, 'changed_output')
done()
})
}
}
4 changes: 3 additions & 1 deletion test/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ const test = require('ava')
const path = require('path')
const {compileFixture, fs} = require('./_helpers')

test('compiles a project with a custom plugin', (t) => {
test('compiles a project with a custom plugin, plugins can change output path', (t) => {
return compileFixture(t, 'plugins')
.then(({res, publicPath}) => {
const index = path.join(publicPath, 'index.html')
const outputChanged = path.join(publicPath, 'changed_output.html')
fs.statSync(index)
fs.statSync(outputChanged)
t.truthy(res.stats.compilation.options.test === 'bar')
})
})