提交 f5854b97 编写于 作者: 5 592767809

更新

上级 517a414b
node webpack_mixer.js -l pcweb.js -o webpack_out.js
\ No newline at end of file
此差异已折叠。
// window = this;
// navigator = {
// appName: 'Netscape'
// };
// localStorage = {
// getItem: function () {
// return null;
// }
// };
// sessionStorage = {
// getItem: function () {
// return null;
// }
// };
//
// document = {
// cookie: ""
// };
const t = require('./webpack_out');
let dutO = t('dutO').a;
cons
const parser = require("@babel/parser");
const t = require("@babel/types");
const generator = require("@babel/generator");
const traverse = require("@babel/traverse").default;
const fs = require("fs");
function wtofile(path, flags, code) {
var fd = fs.openSync(path,flags);
fs.writeSync(fd, code);
fs.closeSync(fd);
}
function run(loader_path, out_path, modular_path) {
let js_code = fs.readFileSync(loader_path, {
encoding: "utf-8"
});
// 转换为AST语法树
let loader_ast = parser.parse(js_code);
// 获取加载器代码
let loader_body;
if (loader_ast.program.body[0].expression.type === 'UnaryExpression'){
loader_body = loader_ast.program.body[0].expression.argument.callee.body.body;
}else{
loader_body = loader_ast.program.body[0].expression.callee.body.body;
}
for (let i = 0; i < loader_body.length; i++){
if (loader_body[i].type === 'VariableDeclaration'){
let j = i + 1;
while (j < loader_body.length){
if (loader_body[j].type === 'VariableDeclaration'){
loader_body.splice(j, (loader_body.length - j));
loader_body.splice(0, i);
let tempname = '';
loader_body.forEach(function (item, index) {
if (item.type === 'FunctionDeclaration'){
tempname = item.id.name;
}
});
loader_body.push(t.assignmentExpression("=", t.identifier("export_function"), t.identifier(tempname)));
}else {
j++;
}
}
break;
}
}
// 导入加载器中的函数体
let loader_arguments;
if (loader_ast.program.body[0].expression.type === 'UnaryExpression'){
loader_arguments = loader_ast.program.body[0].expression.argument.arguments[0];
}else{
loader_arguments = loader_ast.program.body[0].expression.arguments[0];
}
if (loader_arguments.type === 'ArrayExpression'){
let tempobjectexpression = t.objectExpression([]);
loader_arguments.elements.forEach(function (item, index) {
if (item && item.type === 'FunctionExpression'){
tempobjectexpression.properties.push(t.objectProperty(
t.numericLiteral(index),
item,
false,
false
));
}
});
loader_arguments = tempobjectexpression;
}
// 加载外部函数体
modular_path.forEach(function (item, index) {
var jscode = fs.readFileSync(item, {
encoding: "utf-8"
});
let modular_ast = parser.parse(jscode);
modular_ast.program.body[0].expression.arguments[0].elements.forEach(function (item2, index2) {
if (item2.type === 'ArrayExpression'){
item2.elements.forEach(function (item3, index3) {
if (item3 && item3.type === 'FunctionExpression'){
loader_arguments.properties.push(t.objectProperty(
t.numericLiteral(index3),
item3,
false,
false
));
}
});
}else {
item2.properties.forEach(function (item3, index3) {
loader_arguments.properties.push(item3)
})
}
});
});
if (loader_ast.program.body[0].expression.type === 'UnaryExpression'){
loader_ast.program.body[0].expression.argument.arguments[0] = loader_arguments;
}else{
loader_ast.program.body[0].expression.arguments[0] = loader_arguments;
}
// 申请全局导出函数
loader_ast.program.body.splice(0, 0, t.variableDeclaration("var",[t.variableDeclarator(t.identifier("export_function"))]));
// 导出函数
loader_ast.program.body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier("module"), t.identifier("exports"), false), t.identifier("export_function"))));
let code = generator.default(loader_ast, {
compact: false, // 压缩格式
comments: false, // 注释
jsescOption: {
minimal: false // 转义
}
}).code;
wtofile(out_path, 'w', code);
}
!function () {
let loader_path, out_path;
let modular_path = [];
for(let i = 0; i < process.argv.length; i++){
if (process.argv[i] === '-l'){
loader_path = process.argv[i + 1];
i += 1;
}else if(process.argv[i] === '-m'){
modular_path.push(process.argv[i + 1]);
i += 1;
}else if(process.argv[i] === '-o'){
out_path = process.argv[i + 1];
i += 1;
}
}
if (loader_path && out_path){
run(loader_path, out_path, modular_path)
}
}();
此差异已折叠。
node webpack_mixer.js -l runtime.f14829991e28826b88df.js -m polyfills.e375cefe300714a6da33.js -m vendor.7e178057f36014b4b175.js -m main.f0409bc0315ca30a178d.js -o webpack_out.js
\ No newline at end of file
此差异已折叠。
此差异已折叠。
!function(e){function r(r){for(var n,a,c=r[0],u=r[1],i=r[2],l=0,p=[];l<c.length;l++)a=c[l],o[a]&&p.push(o[a][0]),o[a]=0;for(n in u)Object.prototype.hasOwnProperty.call(u,n)&&(e[n]=u[n]);for(d&&d(r);p.length;)p.shift()();return f.push.apply(f,i||[]),t()}function t(){for(var e,r=0;r<f.length;r++){for(var t=f[r],n=!0,c=1;c<t.length;c++){var u=t[c];0!==o[u]&&(n=!1)}n&&(f.splice(r--,1),e=a(a.s=t[0]))}return e}var n={},o={1:0},f=[];function a(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,a),t.l=!0,t.exports}a.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise(function(r,n){t=o[e]=[r,n]});r.push(t[2]=n);var f,c=document.createElement("script");c.charset="utf-8",c.timeout=120,a.nc&&c.setAttribute("nonce",a.nc),c.src=function(e){return a.p+""+({0:"common"}[e]||e)+"."+{0:"4b154e71fdf18ded7a60",2:"52253ade2b0d0e4749c2",7:"e8aacf5df9f667b67c84",8:"04bd0443ef913fa9f24a",9:"87554c7525b7fdb6fb21",10:"f674017b1d7479c82941",11:"bb0d396d72f499b69042",12:"3804713ee4d9731f39de",13:"35fc4bad058324a1d772",14:"2147d7aee0a834ef3ab9",15:"8a008f4fbf2808bbf3aa",16:"97b4c072b9c25b1e2af1",17:"d5cf495f0c0bfc6dc55f",18:"8fdc2137cc28fe381c12",19:"826f9c62cd73f4783791",20:"711fa0d3f90444e5e790"}[e]+".js"}(e),f=function(r){c.onerror=c.onload=null,clearTimeout(u);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),f=r&&r.target&&r.target.src,a=new Error("Loading chunk "+e+" failed.\n("+n+": "+f+")");a.type=n,a.request=f,t[1](a)}o[e]=void 0}};var u=setTimeout(function(){f({type:"timeout",target:c})},12e4);c.onerror=c.onload=f,document.head.appendChild(c)}return Promise.all(r)},a.m=e,a.c=n,a.d=function(e,r,t){a.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,r){if(1&r&&(e=a(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(a.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)a.d(t,n,(function(r){return e[r]}).bind(null,n));return t},a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,"a",r),r},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},a.p="",a.oe=function(e){throw console.error(e),e};var c=window.webpackJsonp=window.webpackJsonp||[],u=c.push.bind(c);c.push=r,c=c.slice();for(var i=0;i<c.length;i++)r(c[i]);var d=u;t()}([]);
\ No newline at end of file
window = this;
navigator = {
appName: 'Netscape'
};
localStorage = {
getItem: function () {
return null;
}
};
sessionStorage = {
getItem: function () {
return null;
}
};
document = {
cookie: ""
};
const t = require('./webpack_out');
const request = require('request');
let dutO = t('dutO').a;
// console.log(dutO);
let aaa = dutO.prototype.post('https://tianaw.95505.cn/tacpc/tiananapp/customer_login/taPcLogin', {loginMethod: "1", name: "13800000000", password: "a123456789"});
console.log(aaa);
request({
url: aaa[1],
method: "POST",
json: true,
headers: {
"key": aaa[0],
"content-type": "application/json",
},
body: JSON.stringify({
jsonKey: aaa[1].split('=')[1]
})
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // 请求成功的处理逻辑
}
});
此差异已折叠。
const parser = require("@babel/parser");
const t = require("@babel/types");
const generator = require("@babel/generator");
const traverse = require("@babel/traverse").default;
const fs = require("fs");
function wtofile(path, flags, code) {
var fd = fs.openSync(path,flags);
fs.writeSync(fd, code);
fs.closeSync(fd);
}
function run(loader_path, out_path, modular_path) {
let js_code = fs.readFileSync(loader_path, {
encoding: "utf-8"
});
// 转换为AST语法树
let loader_ast = parser.parse(js_code);
// 获取加载器代码
let loader_body;
if (loader_ast.program.body[0].expression.type === 'UnaryExpression'){
loader_body = loader_ast.program.body[0].expression.argument.callee.body.body;
}else{
loader_body = loader_ast.program.body[0].expression.callee.body.body;
}
for (let i = 0; i < loader_body.length; i++){
if (loader_body[i].type === 'VariableDeclaration'){
let j = i + 1;
while (j < loader_body.length){
if (loader_body[j].type === 'VariableDeclaration'){
loader_body.splice(j, (loader_body.length - j));
loader_body.splice(0, i);
let tempname = '';
loader_body.forEach(function (item, index) {
if (item.type === 'FunctionDeclaration'){
tempname = item.id.name;
}
});
loader_body.push(t.assignmentExpression("=", t.identifier("export_function"), t.identifier(tempname)));
}else {
j++;
}
}
break;
}
}
// 导入加载器中的函数体
let loader_arguments;
if (loader_ast.program.body[0].expression.type === 'UnaryExpression'){
loader_arguments = loader_ast.program.body[0].expression.argument.arguments[0];
}else{
loader_arguments = loader_ast.program.body[0].expression.arguments[0];
}
if (loader_arguments.type === 'ArrayExpression'){
let tempobjectexpression = t.objectExpression([]);
loader_arguments.elements.forEach(function (item, index) {
if (item && item.type === 'FunctionExpression'){
tempobjectexpression.properties.push(t.objectProperty(
t.numericLiteral(index),
item,
false,
false
));
}
});
loader_arguments = tempobjectexpression;
}
// 加载外部函数体
modular_path.forEach(function (item, index) {
var jscode = fs.readFileSync(item, {
encoding: "utf-8"
});
let modular_ast = parser.parse(jscode);
modular_ast.program.body[0].expression.arguments[0].elements.forEach(function (item2, index2) {
if (item2.type === 'ArrayExpression'){
item2.elements.forEach(function (item3, index3) {
if (item3 && item3.type === 'FunctionExpression'){
loader_arguments.properties.push(t.objectProperty(
t.numericLiteral(index3),
item3,
false,
false
));
}
});
}else {
item2.properties.forEach(function (item3, index3) {
loader_arguments.properties.push(item3)
})
}
});
});
if (loader_ast.program.body[0].expression.type === 'UnaryExpression'){
loader_ast.program.body[0].expression.argument.arguments[0] = loader_arguments;
}else{
loader_ast.program.body[0].expression.arguments[0] = loader_arguments;
}
// 申请全局导出函数
loader_ast.program.body.splice(0, 0, t.variableDeclaration("var",[t.variableDeclarator(t.identifier("export_function"))]));
// 导出函数
loader_ast.program.body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier("module"), t.identifier("exports"), false), t.identifier("export_function"))));
let code = generator.default(loader_ast, {
compact: false, // 压缩格式
comments: false, // 注释
jsescOption: {
minimal: false // 转义
}
}).code;
wtofile(out_path, 'w', code);
}
!function () {
let loader_path, out_path;
let modular_path = [];
for(let i = 0; i < process.argv.length; i++){
if (process.argv[i] === '-l'){
loader_path = process.argv[i + 1];
i += 1;
}else if(process.argv[i] === '-m'){
modular_path.push(process.argv[i + 1]);
i += 1;
}else if(process.argv[i] === '-o'){
out_path = process.argv[i + 1];
i += 1;
}
}
if (loader_path && out_path){
run(loader_path, out_path, modular_path)
}
}();
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册