(outputDir = 'output-chrome/apps')
| 111 | |
| 112 | // 合并 & 压缩 js |
| 113 | function processJs(outputDir = 'output-chrome/apps') { |
| 114 | let jsMerge = () => { |
| 115 | return through.obj(function (file, enc, cb) { |
| 116 | let contents = file.contents.toString('utf-8'); |
| 117 | let merge = (fp, fc) => { |
| 118 | return fc.replace(/__importScript\(\s*(['"])([^'"]*)\1\s*\)/gm, function (frag, $1, mod) { |
| 119 | let mp = path.resolve(fp, '../' + mod + (/\.js$/.test(mod) ? '' : '.js')); |
| 120 | let mc = fs.readFileSync(mp).toString('utf-8'); |
| 121 | return merge(mp, mc + ';'); |
| 122 | }); |
| 123 | }; |
| 124 | contents = merge(file.path, contents); |
| 125 | file.contents = Buffer.from(contents); |
| 126 | this.push(file); |
| 127 | return cb(); |
| 128 | }) |
| 129 | }; |
| 130 | const shouldSkipProcessing = (file) => { |
| 131 | const relativePath = path.relative(path.join(process.cwd(), 'apps'), file.path); |
| 132 | return relativePath === 'chart-maker/lib/xlsx.full.min.js' |
| 133 | || relativePath === 'static/vendor/evalCore.min.js' |
| 134 | || relativePath === 'code-compress/htmlminifier.min.js'; |
| 135 | }; |
| 136 | return gulp.src('apps/**/*.js') |
| 137 | .pipe(jsMerge()) |
| 138 | .pipe(gulpIf(file => !shouldSkipProcessing(file), babel({ |
| 139 | presets: [ |
| 140 | ['@babel/preset-env', { modules: false }] |
| 141 | ] |
| 142 | }))) |
| 143 | .pipe(gulpIf(file => !shouldSkipProcessing(file), uglifyjs({ |
| 144 | compress: { |
| 145 | ecma: 2015 |
| 146 | } |
| 147 | }))) |
| 148 | .pipe(gulp.dest(outputDir)); |
| 149 | } |
| 150 | |
| 151 | // 合并 & 压缩 css |
| 152 | function processCss(outputDir = 'output-chrome/apps') { |
no test coverage detected