babel-plugin-webpack-loaders-inline-exports
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

babel-plugin-webpack-loaders-inline-exports

Make webpack-loaders inline exports

Build Status NPM Dependencies License

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 with extract-text-webpack-plugin and don't use with style-loader
  • BABEL_DISABLE_CACHE=1 may used

Package Sidebar

Install

npm i babel-plugin-webpack-loaders-inline-exports

Weekly Downloads

1

Version

0.4.0

License

WTFPL

Last publish

Collaborators

  • morlay_null