Skip to content
Permalink
Browse files

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
tgds authored and MarshallOfSound committed Dec 13, 2018
1 parent 91c3586 commit 6eae1b5c35e6b966cff86d6bf2af83a240bd4884
@@ -7,7 +7,13 @@
"license": "MIT",
"main": "dist/WebpackPlugin.js",
"typings": "dist/WebpackPlugin.d.ts",
"devDependencies": {},
"scripts": {
"test": "mocha --require ts-node/register test/**/*_spec.ts test/**/**/*_spec.ts --opts ../../../mocha.opts"
},
"devDependencies": {
"chai": "4.2.0",
"mocha": "^5.0.0"
},
"engines": {
"node": ">= 6.0"
},
@@ -164,8 +164,8 @@ Your packaged app may be larger than expected if you dont ignore everything othe
if (entryPoint.preload) {
defines[`${entryPoint.name.toUpperCase().replace(/ /g, '_')}_PRELOAD_WEBPACK_ENTRY`] =
this.isProd
? `\`file://\$\{require('path').resolve(__dirname, '../renderer', '${entryPoint.name}', 'preload.js')\}\``
: `'${path.resolve(this.baseDir, 'renderer', entryPoint.name, 'preload.js')}'`;
? `require('path').resolve(__dirname, '../renderer', '${entryPoint.name}', 'preload.js')`
: `'${path.resolve(this.baseDir, 'renderer', entryPoint.name, 'preload.js').replace(/\\/g, '\\\\')}'`;
}
}
return defines;
@@ -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')");
});
});
});

0 comments on commit 6eae1b5

Please sign in to comment.
You can’t perform that action at this time.