Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gxlmyacc/babel-plugin-provide
a babel provide that like webpack-provide-plugin
https://github.com/gxlmyacc/babel-plugin-provide
babel babel-plugin global-variables provide webpack webpack-provide-plugin
Last synced: 17 days ago
JSON representation
a babel provide that like webpack-provide-plugin
- Host: GitHub
- URL: https://github.com/gxlmyacc/babel-plugin-provide
- Owner: gxlmyacc
- License: mit
- Created: 2019-11-04T01:46:29.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T00:03:26.000Z (about 2 years ago)
- Last Synced: 2024-04-25T23:21:36.495Z (9 months ago)
- Topics: babel, babel-plugin, global-variables, provide, webpack, webpack-provide-plugin
- Language: JavaScript
- Homepage:
- Size: 224 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# babel-plugin-provide
a babel provide that like webpack-provode-plugin that convert global variables to local references.[![NPM version](https://img.shields.io/npm/v/babel-plugin-provide.svg?style=flat)](https://npmjs.com/package/babel-plugin-provide)
[![NPM downloads](https://img.shields.io/npm/dm/babel-plugin-provide.svg?style=flat)](https://npmjs.com/package/babel-plugin-provide)## installtion
```bash
npm install --save-dev babel-plugin-provide
// or
yarn add -D babel-plugin-provide
```## config
```js
// babel.config.jsconst path = require('path');
module.exports = {
presets: [
],
plugins: [
[
'babel-plugin-provide',
{
_: 'lodash',
importJs: filename => `./${path.relative(path.dirname(filename), path.join(__dirname, 'demo/src/import-js')).replace(/\\/g, '/')}`,
$: 'jquery'
}
],
...
]
};
```## demo
source file:
```js
function test() {
_.defaultsDeep({}, {});
$(document.body);
$.each([], {});
let a;
a.$.dd('dd');importJs('http://www.xxxx.com/something.js');
}export default test;
```
source file will be transformed that:
```js
import importJs from "./import-js";
import $ from "jquery";
import _ from "lodash";function test() {
_.defaultsDeep({}, {});$(document.body);
$.each([], {});
let a;
a.$.dd('dd');
importJs('http://www.xxxx.com/something.js');
}export default test;
```