Skip to content
Permalink
Browse files

feat: auto-ignore everything that is not webpack output during the we…

…bpack build. Fixes #593
  • Loading branch information
MarshallOfSound committed Oct 16, 2018
1 parent a4fbc0a commit 51a22f74e7981e848d4eff58a16211038795aa95
Showing with 46 additions and 0 deletions.
  1. +1 −0 package.json
  2. +1 −0 packages/plugin/webpack/package.json
  3. +44 −0 packages/plugin/webpack/src/WebpackPlugin.ts
@@ -25,6 +25,7 @@
"clean": "bolt ws exec -- rimraf dist",
"prebuild": "bolt clean && ts-node tools/link-ts.ts && ts-node tools/copy-shared-types.ts && bolt ws exec -- node_modules/.bin/tsc --emitDeclarationOnly",
"build": "bolt ws exec -- node_modules/.bin/babel src -d dist --quiet --extensions \".ts\"",
"build:quick": "bolt ws exec -- node_modules/.bin/babel src -d dist --quiet --extensions \".ts\"",
"postbuild": "ts-node tools/test-dist",
"commit": "git-cz",
"docs": "bolt docs:generate && bolt docs:position",
@@ -17,6 +17,7 @@
"dependencies": {
"@electron-forge/async-ora": "6.0.0-beta.28",
"@electron-forge/plugin-base": "6.0.0-beta.28",
"@electron-forge/shared-types": "^6.0.0-beta.28",
"@electron-forge/web-multi-logger": "6.0.0-beta.28",
"cross-spawn-promise": "^0.10.1",
"debug": "^3.0.0",
@@ -1,5 +1,6 @@
import { asyncOra } from '@electron-forge/async-ora';
import PluginBase from '@electron-forge/plugin-base';
import { ForgeConfig } from '@electron-forge/shared-types';
import Logger from '@electron-forge/web-multi-logger';
import Tab from '@electron-forge/web-multi-logger/dist/Tab';
import { ChildProcess } from 'child_process';
@@ -25,6 +26,7 @@ const BASE_PORT = 3000;
export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
name = 'webpack';
private isProd = false;
private projectDir!: string;
private baseDir!: string;
private watchers: webpack.Compiler.Watching[] = [];
private servers: http.Server[] = [];
@@ -66,6 +68,7 @@ export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
}

init = (dir: string) => {
this.projectDir = dir;
this.baseDir = path.resolve(dir, '.webpack');

d('hooking process events');
@@ -95,10 +98,51 @@ export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
this.exitHandler({ cleanup: true, exit: true });
});
};
case 'resolveForgeConfig':
return this.resolveForgeConfig;
case 'packageAfterCopy':
return this.packageAfterCopy;
}
return null;
}

resolveForgeConfig = async (forgeConfig: ForgeConfig) => {
if (!forgeConfig.packagerConfig) {
forgeConfig.packagerConfig = {};
}
if (forgeConfig.packagerConfig.ignore) {
console.error('You have set packagerConfig.ignore, the electron forge webpack plugin normally sets this automatically.\n\
\
Your packaged app may be larger than expected if you dont ignore everything other than the `.webpack` folder'.red);
return forgeConfig;
}
forgeConfig.packagerConfig.ignore = (file: string) => {
if (!file) return false;

return !/^[\/\\]\.webpack($|[\/\\]).*$/.test(file);
};
return forgeConfig;
}

packageAfterCopy = async (_: any, buildPath: string) => {
const pj = await fs.readJson(path.resolve(this.projectDir, 'package.json'));
delete pj.config.forge;
pj.devDependencies = {};
pj.dependencies = {};
pj.optionalDependencies = {};
pj.peerDependencies = {};

await fs.writeJson(
path.resolve(buildPath, 'package.json'),
pj,
{
spaces: 2,
},
);

await fs.mkdirp(path.resolve(buildPath, 'node_modules'));
}

getDefines = (upOneMore = false) => {
const defines: { [key: string]: string; } = {};
if (!this.config.renderer.entryPoints || !Array.isArray(this.config.renderer.entryPoints)) {

0 comments on commit 51a22f7

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