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

feat: 🎸 Add packageSourceMaps option to WebpackPluginConfig #2581

Merged
merged 3 commits into from
Apr 29, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/plugin/webpack/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ export interface WebpackPluginConfig {
* The webpack config for your main process
*/
mainConfig: WebpackConfiguration | string;
/**
* In the event that webpack has been configured with `devtool: sourcemap` (or any other option
* which results in a `.map` file being generated), this option will cause it to not be
* packaged with your app.
*/
ignoreSourcemap?: boolean;
zac-jacobson marked this conversation as resolved.
Show resolved Hide resolved
/**
* Instructs webpack to emit a JSON file containing statistics about modules, the dependency
* graph, and various other build information for the main process. This file is located in
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ Your packaged app may be larger than expected if you dont ignore everything othe
return true;
}

if (this.config.ignoreSourcemap && /[^/\\]+\.js\.map$/.test(file)) {
zac-jacobson marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

return !/^[/\\]\.webpack($|[/\\]).*$/.test(file);
};
return forgeConfig;
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin/webpack/test/WebpackPlugin_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ describe('WebpackPlugin', () => {
expect(ignore(path.join('foo', 'bar', '.webpack', 'main', 'stats.json'))).to.equal(true);
expect(ignore(path.join('foo', 'bar', '.webpack', 'renderer', 'stats.json'))).to.equal(true);
});

it('ignores sourcemap files', async () => {
const webpackConfig = { ...baseConfig, ignoreSourcemap: true };
plugin = new WebpackPlugin(webpackConfig);
const config = await plugin.resolveForgeConfig({} as ForgeConfig);
const ignore = config.packagerConfig.ignore as IgnoreFunction;

expect(ignore(path.join('/.webpack', 'main', 'index.js'))).to.equal(false);
expect(ignore(path.join('/.webpack', 'main', 'index.js.map'))).to.equal(true);
expect(ignore(path.join('/.webpack', 'renderer', 'main_window', 'index.js'))).to.equal(false);
expect(ignore(path.join('/.webpack', 'renderer', 'main_window', 'index.js.map'))).to.equal(true);
});
});
});

Expand Down