Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-webpack): fix incorrect PRELOAD_WEBPACK_ENTRY. #635

Merged
merged 3 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions packages/plugin/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
"main": "dist/WebpackPlugin.js",
"typings": "dist/WebpackPlugin.d.ts",
"scripts": {
"test": "exit 0"
"test": "mocha --require ts-node/register test/**/*_spec.ts test/**/**/*_spec.ts --opts ../../../mocha.opts"
},
"devDependencies": {
"chai": "4.2.0",
"mocha": "^5.0.0"
},
"devDependencies": {},
"engines": {
"node": ">= 6.0"
},
Expand All @@ -30,4 +33,4 @@
"webpack-hot-middleware": "^2.21.0",
"webpack-merge": "^4.1.1"
}
}
}
6 changes: 3 additions & 3 deletions packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const BASE_PORT = 3000;

export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
name = 'webpack';
private isProd = false;
isProd = false;
MarshallOfSound marked this conversation as resolved.
Show resolved Hide resolved
private projectDir!: string;
private baseDir!: string;
private watchers: webpack.Compiler.Watching[] = [];
Expand Down Expand Up @@ -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;
Expand Down
55 changes: 55 additions & 0 deletions packages/plugin/webpack/test/WebpackPlugin_spec.ts
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');
p.isProd = false;
const defines = p.getDefines();

if (process.platform === 'win32') {
expect(defines.WINDOW_PRELOAD_WEBPACK_ENTRY).to.be.eq("'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.isProd = true;
const defines = p.getDefines();
expect(defines.WINDOW_PRELOAD_WEBPACK_ENTRY).to.be.eq("require('path').resolve(__dirname, '../renderer', 'window', 'preload.js')");
});
});
});