
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
在我们模块化项目时,经常调用一个模块,使用了其中一个方法,其它 N 多的方法我们未调用,我们希望未调用到的方法或者变量忽略它们,并且不打包到 js 文件中,这样在大项目里面可以显著减少文件的体积,特别在移动终端,虽然 4G 非常快,但是我还是希望更省流量。
ES6 帮我们实现了,目前 webpack 和 browserify 都还不支持这一屌爆了的功能。如果你现在就想实现这一功能的话,你就可以尝试使用rollup.js
使用gulp工具来搞定打包功能。首先在根目录建立gulpfile.js 和 package.json 文件这个是 gulp 工具的标配。如果不知道怎么玩儿gulp,得先去研究研究
先安装依赖模块
npm install gulp --save
npm install rollup --save
npm install rollup-plugin-commonjs --save
npm install rollup-plugin-node-resolve --save
gulpfile.js
var gulp = require("gulp");
var fs = require("fs");
var rollup = require("rollup").rollup;
var commonjs = require("rollup-plugin-commonjs");
var nodeResolve = require("rollup-plugin-node-resolve");
gulp.task("script", function () {
return rollup({
entry: "src/main.js",
plugins: [nodeResolve({ jsnext: true }), commonjs()],
}).then(function (bundle) {
// 输出 bundle + sourcemap
var result = bundle.generate({
// output format - 'amd', 'cjs', 'es6', 'iife', 'umd'
// amd – 使用像requirejs一样的银木块定义
// cjs – CommonJS,适用于node和browserify / Webpack
// es6 (default) – 保持ES6的格式
// iife – 使用于<script> 标签引用的方式
// umd – 适用于CommonJs和AMD风格通用模式
/**
* output format - 'amd', 'cjs', 'es6', 'iife', 'umd'
* amd – 使用像requirejs一样的银木块定义
* cjs – CommonJS,适用于node和browserify / Webpack
* es6 (default) – 保持ES6的格式
* iife – 使用于<script> 标签引用的方式
* umd – 适用于CommonJs和AMD风格通用模式
*/
format: "cjs",
});
fs.writeFileSync("bundle.js", result.code);
bundle.write({
format: "cjs",
dest: "dist/main.js",
});
});
});
再去建立 main.js 和 main.js ,运行 npm script 进行打包,就可得到你想要的 js 文件了。
Plugins: https://github.com/rollup/rollup/wiki/Plugins
node_modules, installed with npm)官网:http://rollupjs.org
Github:https://github.com/rollup/rollup
FAQs
vue-dict是一个vue深入订制的字典集工具,有多种使用方式,方便开发者使用
We found that vue-dict 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
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.