Transforms import.meta for nodejs environments. This plugin supports transforming the following apis:
import.meta.dirnameimport.meta.filenameimport.meta.resolve(specifier)import.meta.urlimport.meta.dirnameconsole.log(import.meta.dirname);
Is replaced with
console.log(__dirname);
import.meta.filenameconsole.log(import.meta.filename);
Is replaced with
console.log(__filename);
import.meta.resolve(specifier)console.log(import.meta.resolve(myCustomFunction('path', 'file')));
Is replaced with
console.log(require('url').pathToFileURL(require.resolve(myCustomFunction('path', 'file'))).toString());
import.meta.urlconsole.log(import.meta.url);
Is replaced with
console.log(require('url').pathToFileURL(__filename).toString());
Install this package
npm install --save-dev babel-plugin-transform-import-meta
and add it to your babel plugins in babel.config.json
{
"plugins": [
"babel-plugin-transform-import-meta"
]
}
It's possible to use ES6 modules for the output. Useful to delegate module transformation to other plugins.
{
"plugins": [
["babel-plugin-transform-import-meta", { "module": "ES6" }]
]
}
Based on a previous project "babel-plugin-import-meta" by The Polymer Authors
TypeScript
92.8%
JavaScript
7.2%
Transforms import.meta for nodejs environments. This plugin supports transforming the following apis:
import.meta.dirnameimport.meta.filenameimport.meta.resolve(specifier)import.meta.urlimport.meta.dirnameconsole.log(import.meta.dirname);
Is replaced with
console.log(__dirname);
import.meta.filenameconsole.log(import.meta.filename);
Is replaced with
console.log(__filename);
import.meta.resolve(specifier)console.log(import.meta.resolve(myCustomFunction('path', 'file')));
Is replaced with
console.log(require('url').pathToFileURL(require.resolve(myCustomFunction('path', 'file'))).toString());
import.meta.urlconsole.log(import.meta.url);
Is replaced with
console.log(require('url').pathToFileURL(__filename).toString());
Install this package
npm install --save-dev babel-plugin-transform-import-meta
and add it to your babel plugins in babel.config.json
{
"plugins": [
"babel-plugin-transform-import-meta"
]
}
It's possible to use ES6 modules for the output. Useful to delegate module transformation to other plugins.
{
"plugins": [
["babel-plugin-transform-import-meta", { "module": "ES6" }]
]
}
Based on a previous project "babel-plugin-import-meta" by The Polymer Authors
TypeScript
92.8%
JavaScript
7.2%