Skip to content

Commit

Permalink
feat: 馃幐 Add packageSourceMaps option to WebpackPluginConfig (#2581)
Browse files Browse the repository at this point in the history
Restricts generated source map files from being included in the
packaged application by default. Provides an config option to include
them in again.

Closes: #2573
  • Loading branch information
zac-jacobson committed Apr 29, 2022
1 parent 9fcd08f commit 2bb5e0d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/plugin/webpack/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,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 @@ -214,6 +214,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

0 comments on commit 2bb5e0d

Please sign in to comment.