前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >你知道那些长长的js怎么来的吗?

你知道那些长长的js怎么来的吗?

作者头像
润森
发布2019-09-18 17:15:55
7160
发布2019-09-18 17:15:55
举报
文章被收录于专栏:毛利学Python毛利学Python

今天不知道写啥东西,随便写了点,好水啊

大家知不知道每次用js逆向时,发现那些长长的js代码,那可不是人写的。那到底是怎么来的,前端的人应该都知道用框架生成的,没错就是webpack

webpack

Webpack 是当下最热门的前端资源模块化管理和打包工具,它可以将许多松散耦合的模块按照依赖和规则打包成符合生产环境部署的前端资源。

安装 nvm

https://github.com/nvm-sh/nvm

通过 curl 安装:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

通过 wget 安装:wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

安装 Node.js 和 NPM

·nvm install v10.15.3 ·检查是否安装成功:node -v, npm -v

安装 webpack 和 webpack-cli

创建空?目录和 package.json ·

  • mkdir my-project
  • cd my-project ·
  • npm init -y

创建webpack.config.js

  • webpack.config.js
代码语言:javascript
复制
// 加载path
const path = require('path');

module.exports = {
    entry: './src/index.js',
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js'
    },
    mode: 'production'
};
  • entry打包的js
  • output输出的js
创建src/index.js
代码语言:javascript
复制
// 导入helloworld.js
import { helloworld } from './helloworld';

document.write(helloworld());
创建src/helloworld.js
代码语言:javascript
复制
// export 导入
export function helloworld() {
    return 'Hello webpack';
}

这样通过打包index.js输出到dist文件夹中的bundle.js,执行npm run build将其打包

这是bundle.js就是你看不懂的js代码

代码语言:javascript
复制
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"?developer/article/1508982/undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t),document.write("Hello webpack")}]);

这段代码就是打印Hello webpack一样的意思,只不过通过js生成的

新建./dist/index.html 导入

代码语言:javascript
复制
<body>
    <script src="./bundle.js"></script>
</body>

这该就是你zaijs慢慢扣的代码来源

一直原创,从未转载

本文参与?腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-09-18,如有侵权请联系?cloudcommunity@tencent.com 删除

本文分享自 小刘IT教程 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • webpack
  • 安装 nvm
  • 安装 Node.js 和 NPM
  • 安装 webpack 和 webpack-cli
    • 创建src/index.js
      • 创建src/helloworld.js
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
      http://www.vxiaotou.com