-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugin-webpack): fix incorrect PRELOAD_WEBPACK_ENTRY. (#635)
* fix(plugin-webpack): fix incorrect PRELOAD_WEBPACK_ENTRY. BrowserWindow preload parameter should be an absolute path. Remove prepending 'file://' from prod value of PRELOAD_WEBPACK_ENTRY. Properly escape backslashes in the dev value of PRELOAD_WEBPACK_ENTRY to prevent failure on Windows. * Use String.raw, keep isProd private
- Loading branch information
1 parent
91c3586
commit 6eae1b5
Showing
3 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { expect } from 'chai'; | ||
|
||
import WebpackPlugin from '../src/WebpackPlugin'; | ||
|
||
describe('WebpackPlugin', () => { | ||
describe('PRELOAD_WEBPACK_ENTRY', () => { | ||
it('should assign absolute preload script path in development', () => { | ||
const p = new WebpackPlugin({ | ||
mainConfig: {}, | ||
renderer: { | ||
config: {}, | ||
entryPoints: [ | ||
{ | ||
js: 'window.js', | ||
name: 'window', | ||
preload: { | ||
js: 'preload.js', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
p.init(process.platform === 'win32' ? 'C:\\baseDir' : '/baseDir'); | ||
const defines = p.getDefines(); | ||
|
||
if (process.platform === 'win32') { | ||
expect(defines.WINDOW_PRELOAD_WEBPACK_ENTRY).to.be.eq(String.raw`'C:\\baseDir\\.webpack\\renderer\\window\\preload.js'`); | ||
} else { | ||
expect(defines.WINDOW_PRELOAD_WEBPACK_ENTRY).to.be.eq("'/baseDir/.webpack/renderer/window/preload.js'"); | ||
} | ||
}); | ||
|
||
it('should assign an expression to resolve the preload script in production', () => { | ||
const p = new WebpackPlugin({ | ||
mainConfig: {}, | ||
renderer: { | ||
config: {}, | ||
entryPoints: [ | ||
{ | ||
js: 'window.js', | ||
name: 'window', | ||
preload: { | ||
js: 'preload.js', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
p.init(process.platform === 'win32' ? 'C:\\baseDir' : '/baseDir'); | ||
(p as any).isProd = true; | ||
const defines = p.getDefines(); | ||
expect(defines.WINDOW_PRELOAD_WEBPACK_ENTRY).to.be.eq("require('path').resolve(__dirname, '../renderer', 'window', 'preload.js')"); | ||
}); | ||
}); | ||
}); |