-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
…rtLibToEs (#6)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
export default { | ||
cjs: { type: 'babel' }, | ||
esm: { type: 'babel', importLibToEs: true }, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import foo from "foo/es/foo"; | ||
console.log(foo()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
|
||
var _foo = _interopRequireDefault(require("foo/lib/foo")); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
console.log((0, _foo.default)()); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import foo from 'foo/lib/foo'; | ||
|
||
console.log(foo()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
export default { | ||
cjs: { type: 'rollup' }, | ||
esm: { type: 'rollup', importLibToEs: true }, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function foo () { | ||
return 'es/foo'; | ||
} | ||
|
||
console.log(foo()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
function foo () { | ||
return 'lib/foo'; | ||
} | ||
|
||
console.log(foo()); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import foo from 'foo/lib/foo'; | ||
|
||
console.log(foo()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { join, dirname } from 'path'; | ||
import fs from 'fs'; | ||
|
||
const cwd = process.cwd(); | ||
|
||
function replacePath(path) { | ||
if (path.node.source && /\/lib\//.test(path.node.source.value)) { | ||
const esModule = path.node.source.value.replace('/lib/', '/es/'); | ||
const esPath = dirname(join(cwd, `node_modules/${esModule}`)); | ||
if (fs.existsSync(esPath)) { | ||
console.log(`[es build] replace ${path.node.source.value} with ${esModule}`); | ||
path.node.source.value = esModule; | ||
} | ||
} | ||
} | ||
|
||
function replaceLib() { | ||
return { | ||
visitor: { | ||
ImportDeclaration: replacePath, | ||
ExportNamedDeclaration: replacePath, | ||
}, | ||
}; | ||
} | ||
|
||
export default replaceLib; |