mirror of
https://github.com/Didericis/bare-bundle-transform-plugin-babel.git
synced 2026-06-26 01:55:17 -04:00
feat: initial commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
const babel = require("@babel/core");
|
||||
|
||||
async function plugin(bundle, { name, data, mode }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// only transform javascript files
|
||||
if (name.match(/\.js$|\.cjs$|\.mjs$/)) {
|
||||
babel.transform(data.toString(), (err, result) => {
|
||||
if (err) reject(err);
|
||||
// overwrite the old code with the transpiled code in the bundle
|
||||
bundle.write(name, result.code, { mode });
|
||||
resolve();
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = plugin;
|
||||
Reference in New Issue
Block a user