File tree Expand file tree Collapse file tree 4 files changed +17
-4
lines changed Expand file tree Collapse file tree 4 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,9 @@ module.exports = class SpikeWebpackPlugin {
6666 : JSON . parse ( dep . _source . _value . replace ( / ^ m o d u l e \. e x p o r t s = / , '' ) )
6767
6868 // calculate the output path
69- let outputPath = this . util . getOutputPath ( f . path ) . relative
69+ // this will use the special prop f.outPath as an override, which can
70+ // be set by plugins to create a custom output path
71+ let outputPath = this . util . getOutputPath ( f . outPath || f . path ) . relative
7072
7173 // set the file's extension if necessary
7274 if ( f . extension ) {
Original file line number Diff line number Diff line change 1+ < p > my output path was rewritten by a plugin : (</ p >
Original file line number Diff line number Diff line change @@ -4,11 +4,19 @@ module.exports = class JadeWebpackPlugin {
44 }
55
66 apply ( compiler ) {
7- compiler . plugin ( 'run' , function ( compilation , done ) {
8- setTimeout ( function ( ) {
7+ compiler . plugin ( 'run' , ( compilation , done ) => {
8+ setTimeout ( ( ) => {
99 compiler . options . test = 'bar'
1010 done ( )
1111 } , 300 )
1212 } )
13+
14+ compiler . plugin ( 'emit' , ( compilation , done ) => {
15+ const file = compiler . options . spike . files . process . find ( ( f ) => {
16+ if ( f . path . match ( / c u s t o m _ o u t p u t / ) ) { return f }
17+ } )
18+ file . outPath = file . path . replace ( / c u s t o m _ o u t p u t / , 'changed_output' )
19+ done ( )
20+ } )
1321 }
1422}
Original file line number Diff line number Diff line change @@ -2,11 +2,13 @@ const test = require('ava')
22const path = require ( 'path' )
33const { compileFixture, fs} = require ( './_helpers' )
44
5- test ( 'compiles a project with a custom plugin' , ( t ) => {
5+ test ( 'compiles a project with a custom plugin, plugins can change output path ' , ( t ) => {
66 return compileFixture ( t , 'plugins' )
77 . then ( ( { res, publicPath} ) => {
88 const index = path . join ( publicPath , 'index.html' )
9+ const outputChanged = path . join ( publicPath , 'changed_output.html' )
910 fs . statSync ( index )
11+ fs . statSync ( outputChanged )
1012 t . truthy ( res . stats . compilation . options . test === 'bar' )
1113 } )
1214} )
You can’t perform that action at this time.
0 commit comments