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 all commits
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
6 changes: 6 additions & 0 deletions packages/plugin/webpack/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ export interface WebpackPluginConfig {
* The TCP port for web-multi-logger. Defaults to 9000.
*/
loggerPort?: number;
/**
* In the event that webpack has been configured with `devtool: sourcemap` (or any other option
* which results in `.map` files being generated), this option will cause the source map files be
* packaged with your app. By default they are not included.
*/
packageSourceMaps?: boolean;
/**
* Sets the [`Content-Security-Policy` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy)
* for the Webpack development server.
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.packageSourceMaps && /[^/\\]+\.js\.map$/.test(file)) {
return true;
}

return !/^[/\\]\.webpack($|[/\\]).*$/.test(file);
};
return forgeConfig;
Expand Down
24 changes: 24 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,30 @@ 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 source map files by default', async () => {
const webpackConfig = { ...baseConfig };
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);
});

it('includes source map files when specified by config', async () => {
const webpackConfig = { ...baseConfig, packageSourceMaps: 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(false);
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(false);
});
});
});

Expand Down