Skip to content

Commit 50e66a0

Browse files
committed
feat(platform-loader): add options.memberExpObjName
1 parent a027693 commit 50e66a0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/platform-loader/src/TraverseImport.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ module.exports = function traverseImport(options, inputSource, sourceMapOption)
150150
// don't remove like: var _universalEnv = {isWeex: false}; if(_universalEnv.isWeex){ xxx }
151151
// change _universalEnv.isWeex to false
152152
const { node } = path;
153-
if (hasPlatformSpecified && node.object.name === '_universalEnv') {
153+
if (hasPlatformSpecified && options.memberExpObjName.indexOf(node.object.name) !== -1) {
154154
if (platformMap[options.platform].indexOf(node.property.name) >= 0) {
155155
path.replaceWith(types.Identifier('true'));
156156
} else {

packages/platform-loader/src/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = async function (inputSource, inputSourceMap) {
7777
const { resourcePath } = this;
7878
const sourceMapTarget = path.basename(resourcePath);
7979

80-
const options = Object.assign({ name: 'universal-env' }, loaderOptions);
80+
const options = Object.assign({ name: 'universal-env', memberExpObjName: '_universalEnv' }, loaderOptions);
8181

8282
if (!options.platform) {
8383
callback(null, inputSource);
@@ -88,6 +88,10 @@ module.exports = async function (inputSource, inputSourceMap) {
8888
options.name = [options.name];
8989
}
9090

91+
if (!Array.isArray(options.memberExpObjName)) {
92+
options.memberExpObjName = [options.memberExpObjName];
93+
}
94+
9195
const { code, map } = traverseImport(options, inputSource, {
9296
sourceMaps: true,
9397
sourceMapTarget,

0 commit comments

Comments
 (0)