
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
babel-plugin-miniprogram-add-globals
Advanced tools
帮助微信小程序项目添加全局变量
目前微信小程序虽然有 global 变量可以全局访问,但是并不能像 NodeJS 或者 浏览器那样直接不带前缀的访问全局变量,使用起来非常不方便。
如:
// globals.js
global.sayHi = () => console.log('hi');
// pageX.js
sayHi(); // Uncaught ReferenceError: sayHi is not defined
global.sayHi(); // hi
通过此插件,会在所有需要的文件顶部添加 global 变量的解构,如:
// pageX.js
const { sayHi } = global; // 插件自动插入该行代码
sayHi(); // hi
{
plugins: [
['miniprogram-add-globals', {
globals: [
'babelHelpers',
'regeneratorRuntime',
'pify',
],
exclude: [
/\/app\.js/,
/\/vendor/,
],
}],
]
}
// globals.js
const babelHelpers = require('./vendors/babelHelpers');
const regeneratorRuntime = require('./vendors/regeneratorRuntime');
const pify = require('./vendors/pify');
Object.assign(global, {
babelHelpers,
regeneratorRuntime,
pify,
});
miniprogram-add-globals 接受一个对象作为插件参数,里面接受如下参数
exclude/include/test 三个配置的用法同 webpack4 中 loader 的 rules 一致,具体用法可以参考 webpack4 配置
FAQs
We found that babel-plugin-miniprogram-add-globals demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.