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

Commit

Permalink
fix: 修复直接从 node_modules export 路径出错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Sep 7, 2019
1 parent f5af7aa commit f586ea7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/remax-cli/src/build/plugins/removeSrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ export function getImportSource(node: Node): Node | false {
return node.source;
}

function getExportSource(node: Node): Node | false {
if (
node.type !== NodeType.ExportNamedDeclaration ||
!node.source ||
node.source.type !== NodeType.Literal
) {
return false;
}

return node.source;
}

function isEmpty(array: any[] | undefined) {
return !array || array.length === 0;
}
Expand Down Expand Up @@ -98,7 +110,10 @@ export default function removeSrc(options: Options): Plugin {
});

const extract = (node: Node) => {
const req = getRequireSource(node) || getImportSource(node);
const req =
getRequireSource(node) ||
getImportSource(node) ||
getExportSource(node);
if (req) {
const { start, end } = req;
const distance = req.value
Expand All @@ -125,6 +140,7 @@ export default function removeSrc(options: Options): Plugin {
simple(ast, {
ImportDeclaration: extract,
CallExpression: extract,
ExportNamedDeclaration: extract,
});

if (sourceMaps) {
Expand Down

0 comments on commit f586ea7

Please sign in to comment.