Skip to content

Commit 40aa07b

Browse files
committed
Export es build that enforces extensions on imports
1 parent c76a078 commit 40aa07b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

.babelrc.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,27 @@ module.exports = {
1515
mjs: {
1616
presets: [['@babel/preset-env', { modules: false }]],
1717
},
18+
esm: {
19+
presets: [['@babel/preset-env', { modules: false }]],
20+
plugins: [
21+
function({ types }) {
22+
return {
23+
visitor: {
24+
ImportDeclaration: function(path, state) {
25+
var source = path.node.source.value;
26+
if (source.match(/^\.{0,2}\//) && !source.endsWith('.es.js')) {
27+
path.replaceWith(
28+
types.importDeclaration(
29+
path.node.specifiers,
30+
types.stringLiteral(source + '.es.js'),
31+
),
32+
);
33+
}
34+
},
35+
},
36+
};
37+
},
38+
],
39+
},
1840
},
1941
};

resources/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function buildJSFile(filepath) {
101101
copyFile(srcPath, destPath + '.flow');
102102
writeFile(destPath, babelBuild(srcPath, 'cjs'));
103103
writeFile(destPath.replace(/\.js$/, '.mjs'), babelBuild(srcPath, 'mjs'));
104+
writeFile(destPath.replace(/\.js$/, '.es.js'), babelBuild(srcPath, 'esm'));
104105
}
105106

106107
function buildPackageJSON() {

0 commit comments

Comments
 (0)