https://github.com/morlay/babel-plugin-webpack-loaders-inline-exports
https://github.com/morlay/babel-plugin-webpack-loaders-inline-exports
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/morlay/babel-plugin-webpack-loaders-inline-exports
- Owner: morlay
- Created: 2016-02-20T14:00:21.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-12-30T09:35:17.000Z (over 9 years ago)
- Last Synced: 2024-10-03T09:18:06.385Z (over 1 year ago)
- Language: TypeScript
- Size: 66.4 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## babel-plugin-webpack-loaders-inline-exports
Make webpack-loaders inline exports
[](https://travis-ci.org/morlay/babel-plugin-webpack-loaders-inline-exports)
[](https://npmjs.org/package/babel-plugin-webpack-loaders-inline-exports)
[](https://david-dm.org/morlay/babel-plugin-webpack-loaders-inline-exports)
[](https://npmjs.org/package/babel-plugin-webpack-loaders-inline-exports)
[webpack-loaders](https://github.com/istarkov/babel-plugin-webpack-loaders) is cool,
but it did some transforms from loader compiled result.
For each matched loader, they could transform as a commonjs module
```js
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
```js
const txt = require('./some.txt');
```
will be
```js
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:
```js
{
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
```json
{
"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;
```json
{
"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