Skip to content

Commit

Permalink
chore: don't set NODE_ENV in webpack process
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanwww committed Dec 23, 2023
1 parent 027c86a commit 006a40c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
1 change: 0 additions & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"build-scripts:dist": "tsc --project tsconfigs/tsconfig.dist.json",
"build-scripts:types": "tsc --project tsconfigs/tsconfig.types.json",
"clean": "rimraf --glob dist tsconfigs/*.tsbuildinfo",
"dev": "pnpm run build-scripts --watch",
"format": "prettier --write \"**/*.{cjs,css,html,js,jsx,mjs,json,less,scss,ts,tsx,yaml,yml}\"",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
Expand Down
8 changes: 1 addition & 7 deletions packages/scripts/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ export function appMain(): void {

const command = genCommand('webpack', '--config', paths.webpackMainConfig, '--mode', compilationMode[flag]);

const env = {
...process.env,
BABEL_ENV: compilationMode[flag],
NODE_ENV: compilationMode[flag],
};

console.info(chalk.yellow(command));
child.execSync(command, { env, stdio: 'inherit' });
child.execSync(command, { stdio: 'inherit' });
}

export async function mkdirWorking(): Promise<void> {
Expand Down
28 changes: 14 additions & 14 deletions packages/scripts/src/webpack/webpack.main.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ type ConfigurationFactory = (
) => Configuration | Promise<Configuration>;

const factory: ConfigurationFactory = (env, argv) => {
const isEnvDevelopment = argv.mode === 'development';
const isEnvProduction = argv.mode === 'production';
const isDevelopment = argv.mode === 'development';
const isProduction = argv.mode === 'production';

const webpack: Configuration = {
target: 'electron-main',
// Webpack noise constrained to errors and warnings
stats: 'errors-warnings',
mode: isEnvProduction ? 'production' : 'development',
mode: isProduction ? 'production' : 'development',
// Stop compilation early in production
bail: isEnvProduction,
devtool: isEnvProduction ? 'source-map' : 'cheap-module-source-map',
bail: isProduction,
devtool: isProduction ? 'source-map' : 'cheap-module-source-map',
entry: {
electron: appMainPaths.mainIndexTs,
preload: appMainPaths.preloadIndexTs,
Expand All @@ -65,14 +65,14 @@ const factory: ConfigurationFactory = (env, argv) => {
output: {
path: appMainPaths.build,
// Add /* filename */ comments to generated require()s in the output.
pathinfo: isEnvDevelopment,
pathinfo: isDevelopment,
filename: '[name].js',
chunkFilename: '[name].[contenthash:8].chunk.js',
},

cache: {
type: 'filesystem',
version: createEnvironmentHash({ NODE_ENV: process.env.NODE_ENV ?? 'development' }),
version: createEnvironmentHash({ NODE_ENV: isDevelopment ? 'development' : 'production' }),
cacheDirectory: appMainPaths.webpackCache,
store: 'pack',
buildDependencies: {
Expand Down Expand Up @@ -122,26 +122,26 @@ const factory: ConfigurationFactory = (env, argv) => {
},

optimization: {
minimize: isEnvProduction,
minimize: isProduction,
minimizer: [new EsbuildPlugin({ target: getElectronNodeTarget() })],
},

plugins: [
new EsbuildPlugin({
define: {
'process.env.NODE_ENV': JSON.stringify(isEnvDevelopment ? 'development' : 'production'),
'process.env.NODE_ENV': JSON.stringify(isDevelopment ? 'development' : 'production'),
},
}),
isEnvDevelopment && new ReloadElectronWebpackPlugin(paths.repository, paths.working),
isDevelopment && new ReloadElectronWebpackPlugin(paths.repository, paths.working),
// TypeScript type checking
isEnvDevelopment &&
isDevelopment &&
new ForkTsCheckerWebpackPlugin({
async: isEnvDevelopment,
async: isDevelopment,
typescript: {
typescriptPath: require.resolve('typescript'),
configOverwrite: {
compilerOptions: {
sourceMap: isEnvProduction || isEnvDevelopment,
sourceMap: isProduction || isDevelopment,
skipLibCheck: true,
inlineSourceMap: false,
declarationMap: false,
Expand All @@ -164,7 +164,7 @@ const factory: ConfigurationFactory = (env, argv) => {
hints: 'warning',
},

watch: isEnvDevelopment,
watch: isDevelopment,
watchOptions: {
aggregateTimeout: 500,
// poll: 10_000,
Expand Down

0 comments on commit 006a40c

Please sign in to comment.