package.json
- {
- “name”: “camera”,
- “version”: “1.0.0”,
- “description”: “2019年4月15日14:12:51”,
- “main”: “config.js”,
- “scripts”: {
- “test”: “echo \”Error: no test specified\” && exit 1″,
- “build”: “gulp copy && gulp min”
- },
- “devDependencies”: {
- “babel-core”: “^6.22.1”,
- “babel-helper-vue-jsx-merge-props”: “^2.0.3”,
- “babel-loader”: “^7.1.1”,
- “babel-plugin-syntax-jsx”: “^6.18.0”,
- “babel-plugin-transform-runtime”: “^6.22.0”,
- “babel-plugin-transform-vue-jsx”: “^3.5.0”,
- “babel-polyfill”: “^6.26.0”,
- “babel-preset-env”: “^1.3.2”,
- “babel-preset-stage-2”: “^6.22.0”,
- “gulp”: “^3.9.1”,
- “gulp-babel”: “^6.0.0”,
- “gulp-htmlmin”: “^5.0.1”,
- “gulp-javascript-obfuscator”: “^1.1.5”,
- “gulp-sftp”: “^0.1.5”,
- “gulp-uglify”: “^3.0.2”,
- “gulp-util”: “^3.0.8”,
- “javascript-obfuscator”: “^0.18.1”,
- “minify”: “^4.1.1”
- },
- “author”: “”,
- “license”: “ISC”
- }
gulpfile.js
- const gulp = require(‘gulp’)
- const path = require(‘path’)
- const uglify = require(‘gulp-uglify’)
- const babel = require(‘gulp-babel’);
- const htmlmin = require(‘gulp-htmlmin’);
- const javascriptObfuscator = require(‘gulp-javascript-obfuscator’);
- /**
- * 拷贝
- */
- gulp.task(‘assetsCopy’, function () {
- return gulp.src(‘./assets/**’)
- .pipe(gulp.dest(‘./dist/assets’))
- });
- gulp.task(‘pageCopy’, function () {
- return gulp.src(‘./page/**’)
- .pipe(gulp.dest(‘./dist/page’))
- });
- gulp.task(‘pageJsCopy’, function () {
- return gulp.src(‘./pageJs/**’)
- .pipe(gulp.dest(‘./dist/pageJs’))
- });
- gulp.task(‘fileCopy’, function () {
- return gulp.src(‘./file/**’)
- .pipe(gulp.dest(‘./dist/file’))
- });
- gulp.task(‘htmlCopy’, function () {
- return gulp.src(‘./*.html’)
- .pipe(gulp.dest(‘./dist’))
- });
- /**
- * 共通js
- */
- gulp.task(‘commonJs’, function () {
- /////找到需要压缩的文件
- gulp.src([‘assets/js/common.js’, ‘assets/js/index.js’, ‘assets/js/display.js’, ‘assets/js/login.js’, ‘assets/js/upload.js’]) //// /**/ 表示js目录下的任意层级的目录
- .pipe(babel())
- /////压缩文件
- .pipe(uglify())
- // 混淆
- .pipe(javascriptObfuscator({
- stringArrayEncoding: true
- }))
- /////另存压缩后文件
- .pipe(gulp.dest(‘dist/assets/js’));
- });
- /**
- * 内嵌页面js
- */
- gulp.task(‘pageJs’, function () {
- /////找到需要压缩的文件
- gulp.src(‘pageJs/*.js’) //// /**/ 表示js目录下的任意层级的目录
- .pipe(babel())
- /////压缩文件
- .pipe(uglify())
- // 混淆
- .pipe(javascriptObfuscator())
- /////另存压缩后文件
- .pipe(gulp.dest(‘dist/pageJs’));
- });
- /**
- * 页面html
- */
- gulp.task(‘pageHtml’, function () {
- const options = {
- removeComments: true, //清除HTML注释
- collapseWhitespace: true, //压缩HTML
- collapseBooleanAttributes: false, //省略布尔属性的值 <input checked=”true”/> ==> <input />
- removeEmptyAttributes: false, //删除所有空格作属性值 <input id=”” /> ==> <input />
- removeScriptTypeAttributes: true, //删除<script>的type=”text/javascript”
- removeStyleLinkTypeAttributes: true, //删除<style>和<link>的type=”text/css”
- minifyJS: true, //压缩页面JS
- minifyCSS: true //压缩页面CSS
- };
- gulp.src(‘page/*.html’)
- .pipe(htmlmin(options))
- .pipe(gulp.dest(‘dist/page’));
- });
- /**
- * 配置文件
- */
- gulp.task(‘configJs’, function () {
- /////找到需要压缩的文件
- gulp.src(‘./config.js’) //// /**/ 表示js目录下的任意层级的目录
- .pipe(babel())
- /////压缩文件
- .pipe(uglify())
- // 混淆
- .pipe(javascriptObfuscator({
- stringArrayEncoding: true
- }))
- /////另存压缩后文件
- .pipe(gulp.dest(‘dist’));
- });
- // 执行任务
- gulp.task(‘copy’, [‘assetsCopy’, ‘pageCopy’, ‘pageJsCopy’, ‘fileCopy’, ‘htmlCopy’])
- gulp.task(‘min’, [‘commonJs’, ‘pageJs’, ‘pageHtml’, ‘configJs’])
安装依赖
npm install
执行命令
npm run build
本文链接地址: gulp 批量混淆代码