Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修复跨平台开发时引入了不相关平台代码的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Darmody committed Jan 15, 2020
1 parent 7ca0962 commit 4b0cba4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
27 changes: 11 additions & 16 deletions packages/remax-cli/src/build/plugins/stub.ts
Expand Up @@ -26,42 +26,37 @@ export default function stub(options: Options = {}): Plugin {
sourceType: 'module',
});

const magicString = new MagicString(code);
const exports: string[] = [];

ast.body.forEach((node: any) => {
if (node.type === 'ExportDefaultDeclaration') {
magicString.overwrite(node.start, node.end, `\nexport default {};`);
exports.push(`\nexport default function() {};`);
} else if (node.type === 'ExportNamedDeclaration') {
if (node.declaration == null) {
let content = '';
node.specifiers.forEach((specifier: any) => {
content += `\nexport var ${specifier.exported.name} = undefined;`;
content += `\nexport var ${specifier.exported.name} = function() {};`;
});
magicString.overwrite(node.start, node.end, content);
exports.push(content);
} else if (node.declaration.type === 'VariableDeclaration') {
node.declaration.declarations.forEach((declaration: any) => {
magicString.overwrite(
node.start,
node.end,
`\nexport var ${declaration.id.name} = undefined;`
exports.push(
`\nexport var ${declaration.id.name} = function() {};`
);
});
} else if (node.declaration.type === 'FunctionDeclaration') {
magicString.overwrite(
node.start,
node.end,
`\nexport var ${node.declaration.id.name} = undefined;`
exports.push(
`\nexport var ${node.declaration.id.name} = function() {};`
);
} else if (node.declaration.type === 'ClassDeclaration') {
magicString.overwrite(
node.start,
node.end,
`\nexport var ${node.declaration.id.name} = undefined;`
exports.push(
`\nexport var ${node.declaration.id.name} = function() {};`
);
}
}
});

const magicString = new MagicString(exports.join(''));
code = magicString.toString();
const map = options.sourceMap ? magicString.generateMap() : null;
ast = this.parse(code, {
Expand Down
6 changes: 2 additions & 4 deletions packages/remax-cli/src/build/rollupConfig.ts
Expand Up @@ -44,10 +44,8 @@ export default function rollupConfig(

['wechat', 'alipay', 'toutiao'].forEach(name => {
if (API.adapter.name !== name) {
const esmPackage = `${name}/esm`;
const cjsPackage = `${name}/cjs`;
stubModules.push(esmPackage);
stubModules.push(cjsPackage);
stubModules.push(`${name}/esm/api`);
stubModules.push(`${name}/esm/hostComponents`);
}
});

Expand Down

0 comments on commit 4b0cba4

Please sign in to comment.