babel-plugin-transform-imports-with-loader
v1.0.0-rc.1
Published
Babel transform plugin for replacing file imports with js string
Downloads
4
Maintainers
Readme
babel-plugin-transform-imports-with-loader
Transform imports into variable definition scripts by custom loader
Installation
npm install --save-dev babel-plugin-transform-imports-with-loader
Usage
Via .babelrc
:
{
"plugins": [
[
"babel-plugin-transform-imports-with-loader",
{
"rules": {
"test": "\\.txt",
"unserializeFunc": "String" // default is String
// "transform": () => {} // transfom option only support in js
}
}
]
]
}
Or Via .babelrc.js
module.exports = {
plugins: [
[
'babel-plugin-transform-imports-with-loader',
{
rules: {
test: /\.txt/,
unserializeFunc: 'String', // default is string
transform: code => {
// transform will allow you to process code string
console.log(code);
return code;
},
},
},
],
],
};
Will transfer following code
index.js
import testTxt from './test.txt';
console.log(testJS, testTxt);
test.txt
this is demo text
to
const __BABEL_TRANSFORM_IMPORTS__lvytyy8jdmk4hwt0jp = String;
const testTxt = __BABEL_TRANSFORM_IMPORTS__lvytyy8jdmk4hwt0jp(
`this is demo text`
);
console.log(testJS, testTxt);
Both option options.rules
and options.rules[].test
support array configuration