Skip to content

Commit

Permalink
fix: should not alias define XXX to process.env.XXX (#1526)
Browse files Browse the repository at this point in the history
* fix: should not assign define XXX to process.env.XXX

* fix: process.env.SOCKER_SERVER
  • Loading branch information
xusd320 authored Aug 23, 2024
1 parent e1e4c77 commit 193b7dd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
3 changes: 1 addition & 2 deletions e2e/fixtures.umi/config.define/.umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default {
DDD: true,
EEE: false,
FFF: null,
GGG: ["a", 1],
"process.env.HHH": false,
GGG: ["a", 1]
},
};
1 change: 0 additions & 1 deletion e2e/fixtures.umi/config.define/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ assert(content.includes("console.log(1);"), "support Number");
assert(content.includes("console.log(true);"), "support Boolean");
assert(content.includes("console.log(false);"), "support Boolean");
assert(content.includes("console.log(null);"), "support Null");
assert(content.includes("console.log('process.env',false);"), "support normalize process.env.XXX");

/**
"production";
Expand Down
1 change: 0 additions & 1 deletion e2e/fixtures.umi/config.define/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ console.log(DDD);
console.log(EEE);
console.log(FFF);
console.log(GGG);
console.log('process.env', HHH);
export default () => <div>1</div>;
15 changes: 4 additions & 11 deletions packages/bundler-mako/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,21 +509,14 @@ async function getMakoConfig(opts) {
const define = {};
if (opts.config.define) {
for (const key of Object.keys(opts.config.define)) {
// mako 的 define 会先去判断 process.env.xxx,再去判断 xxx
// 这里传 process.env.xxx 反而不会生效
// TODO: 待 mako 改成和 umi/webpack 的方式一致之后,可以把这段去掉
if (key.startsWith('process.env.')) {
define[key.replace(/^process\.env\./, '')] = normalizeDefineValue(
opts.config.define[key],
);
} else {
define[key] = normalizeDefineValue(opts.config.define[key]);
}
define[key] = normalizeDefineValue(opts.config.define[key]);
}
}

if (process.env.SOCKET_SERVER) {
define.SOCKET_SERVER = normalizeDefineValue(process.env.SOCKET_SERVER);
define['process.env.SOCKET_SERVER'] = normalizeDefineValue(
process.env.SOCKET_SERVER,
);
}

let minify = jsMinifier === 'none' ? false : true;
Expand Down

0 comments on commit 193b7dd

Please sign in to comment.