| 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' |