Skip to content

Commit

Permalink
fix(bundling): set NODE_ENV correctly to avoid warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored and Jack Hsu committed Sep 30, 2022
1 parent c57f16c commit e6ad5d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions e2e/webpack/src/webpack.test.ts
Expand Up @@ -27,6 +27,8 @@ describe('Webpack Plugin', () => {
runCLI(`build ${myPkg}`);
let output = runCommand(`node dist/libs/${myPkg}/main.js`);
expect(output).toMatch(/Hello/);
expect(output).not.toMatch(/Conflicting/);
expect(output).not.toMatch(/process.env.NODE_ENV/);

updateProjectConfig(myPkg, (config) => {
delete config.targets.build;
Expand Down
9 changes: 6 additions & 3 deletions packages/webpack/src/utils/config.ts
Expand Up @@ -50,9 +50,10 @@ export function getBaseWebpackPartial(
const chunkFilename = internalOptions.isScriptOptimizeOn
? `[name]${hashFormat.chunk}${suffixFormat}.js`
: '[name].js';
const mode = internalOptions.isScriptOptimizeOn
? 'production'
: 'development';
const mode =
process.env.NODE_ENV ?? internalOptions.isScriptOptimizeOn
? 'production'
: 'development';

let mainEntry = 'main';
if (options.outputFileName) {
Expand Down Expand Up @@ -189,6 +190,8 @@ export function getBaseWebpackPartial(
runtimeChunk: true,
};
}
webpackConfig.optimization ??= {};
webpackConfig.optimization.nodeEnv = process.env.NODE_ENV ?? mode;
}

const extraPlugins: WebpackPluginInstance[] = [];
Expand Down
2 changes: 0 additions & 2 deletions packages/webpack/src/utils/webpack/partials/common.ts
Expand Up @@ -193,8 +193,6 @@ export function getCommonConfig(
} catch {}

return {
mode:
scriptsOptimization || stylesOptimization ? 'production' : 'development',
profile: buildOptions.statsJson,
resolve: {
extensions: ['.ts', '.tsx', '.mjs', '.js'],
Expand Down

0 comments on commit e6ad5d7

Please sign in to comment.