Comments (2)
这里代码自检的写法是不是有问题啊,代码运行时才能获取到toString的结果,不同的打包机制也会影响toString的结果
from blog.
这里代码自检的写法是不是有问题啊,代码运行时才能获取到toString的结果,不同的打包机制也会影响toString的结果
实现细节上注意一下就可以,例如手动实现打包插件,设定函数abc,然后在插件打包时增加一层函数名为abc的闭包,同时对函数体本身进行离线的计算签名,注入到打包代码里,如下
源码
var onlineSign = calc_sign(abc.toString());
if (onlineSign !== offlineSign) {
// do something
}
插件代码:
function transform(code) {
var closureCode = `function abc() {${code} }`
var offlineSign = calc_sign(closureCode);
return `var offlineSign = '${offlineSign}';
(${closureCode})();
`;
}
打包打包后的代码
var offlineSign = '离线计算出的签名'
(function abc() {
var onlineSign = calc_sign(abc.toString());
if (onlineSign !== offlineSign) {
// do something
}
})();
from blog.
Related Issues (20)
- Webpack 插件总结归类
- 一年半经验,百度、有赞、阿里前端面试总结 HOT 3
- 记一次前端面试的全过程 HOT 3
- 关于回流与重绘优化的探索
- 从React转职到Vue开发的项目准备
- Webpack构建和性能优化探索
- JavaScript抽象语法树AST
- Vue+Express+Mysql 全栈初体验
- 面试官:聊聊对Vue.js框架的理解 HOT 7
- 前端赋能业务 - Node实现自动化部署平台 HOT 10
- 浏览器工作原理 HOT 12
- Promise实现原理
- 彻底理解服务端渲染 - SSR原理 HOT 27
- 一次关于Vue的自我模拟面试 HOT 5
- 转载申请 HOT 1
- 深入理解Chrome V8垃圾回收机制 HOT 6
- 我们把公司前端慢慢架构了 HOT 2
- Hi, an offfer
- 请问这个是怎么实现的 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.