0.4.0 • Published 8 years ago
babel-plugin-webpack-loaders-inline-exports v0.4.0
babel-plugin-webpack-loaders-inline-exports
Make webpack-loaders inline exports
webpack-loaders is cool, but it did some transforms from loader compiled result.
For each matched loader, they could transform as a commonjs module
module.exports = webpackBootstrap([
function (module, exports, __webpack_require__){
module.exports = __webpack_require__.p + 'xxsdfasdasd.txt';
}
])
and we can just pick the webpackResult as inline exports
const txt = require('./some.txt');
will be
const txt = webpackBootstrap([
function (module, exports, __webpack_require__){
module.exports = __webpack_require__.p + 'xxsdfasdasd.txt';
}
]);
And for some loader, they may exports with other dependences, but it will works well. in this plugin, webpackConfig will be overwrite by the special config below:
{
entry: filename,
output: {
libraryTarget: 'commonjs2',
},
externals: [
(context, subRequest, callback) => {
if (subRequest !== filename) {
callback(null, subRequest);
} else {
callback();
}
}
]
}
To make sure only process the target file which is matched by loader.
Options
all options same as webpack, and we can assign a config by the webpack config file
{
"plugins": [
[
"babel-plugin-webpack-loaders-inline-exports",
{
"configFile": "./webpack.config.js"
}
]
]
}
special options in babel option for this plugin will merge into webpack config.
For ava
user, add set env var $PWD
is needed;
{
"plugins": [
[
"babel-plugin-webpack-loaders-inline-exports",
{
"configFile": "${PWD}/webpack.config.js"
}
]
]
}
Warning
- Please use this only in Node.
- And for
css-loader
, should use withextract-text-webpack-plugin
and don't use withstyle-loader
BABEL_DISABLE_CACHE=1
may used