Skip to content

Commit

Permalink
fix(dev-scripts): Restore packageJson for setting PACKAGE_NAME
Browse files Browse the repository at this point in the history
The commit which removed support for git:// URLS by completing
the revert of PR google#335 removed the initialisation of packageJson
(from the package.json of the plugin being built) which turns
out to still be needed by a DefinePlugin call added later.
  • Loading branch information
cpcallen committed Feb 29, 2024
1 parent e14c67f commit 3938745
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion plugins/dev-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const webpack = require('webpack');
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);

const packageJson = require(resolveApp('package.json'));

module.exports = (env) => {
const mode = env.mode;
const isDevelopment = mode === 'development';
Expand Down Expand Up @@ -100,7 +102,12 @@ module.exports = (env) => {
// It can't find source maps for some Closure modules and that is expected
ignoreWarnings: [/Failed to parse source map/],
plugins: [
// Add package name.
// Use DefinePlugin (https://webpack.js.org/plugins/define-plugin/)
// to pass the name of the package being built to the dev-tools
// playground (via plugins/dev-tools/src/playground/id.js). The
// "process.env." prefix is arbitrary: the stringified value
// gets substituted directly into the source code of that file
// at build time.
new webpack.DefinePlugin({
'process.env.PACKAGE_NAME': JSON.stringify(packageJson.name),
}),
Expand Down

0 comments on commit 3938745

Please sign in to comment.