Commit f8ca6f5c0aec8847b8a19d902848f7b3d244aab6
1 parent
e82616aa
Exists in
master
and in
3 other branches
chore: 新增自定义打包
Showing
3 changed files
with
91 additions
and
1 deletions
Show diff stats
package.json
| ... | ... | @@ -7,7 +7,8 @@ |
| 7 | 7 | "serve": "vue-cli-service serve", |
| 8 | 8 | "build": "vue-cli-service build", |
| 9 | 9 | "lint": "vue-cli-service lint", |
| 10 | - "lib": "vue-cli-service build --target lib --name zee --dest lib packages/index.js" | |
| 10 | + "lib": "vue-cli-service build --target lib --name zee --dest lib packages/index.js", | |
| 11 | + "release": "node webpack/release.js" | |
| 11 | 12 | }, |
| 12 | 13 | "dependencies": { |
| 13 | 14 | "axios": "^0.19.2", |
| ... | ... | @@ -36,6 +37,7 @@ |
| 36 | 37 | "markdown-it": "^11.0.0", |
| 37 | 38 | "markdown-it-anchor": "^5.3.0", |
| 38 | 39 | "markdown-it-container": "^3.0.0", |
| 40 | + "ora": "^4.0.5", | |
| 39 | 41 | "sass": "^1.26.8", |
| 40 | 42 | "sass-loader": "^8.0.2", |
| 41 | 43 | "transliteration": "^2.1.11", | ... | ... |
| ... | ... | @@ -0,0 +1,57 @@ |
| 1 | +const fs = require('fs'); | |
| 2 | +const ora = require('ora'); | |
| 3 | +const path = require('path'); | |
| 4 | +const { exec } = require('child_process'); | |
| 5 | + | |
| 6 | +const outputPath = path.resolve(__dirname, '../release'); | |
| 7 | + | |
| 8 | +// 删除文件夹 | |
| 9 | +const delPath = path => { | |
| 10 | + if (!path.includes(process.cwd())) { | |
| 11 | + console.log('只能操作当前项目'); | |
| 12 | + throw path; | |
| 13 | + } | |
| 14 | + const info = fs.statSync(path); | |
| 15 | + if (info.isDirectory()) { | |
| 16 | + // 目录 | |
| 17 | + const data = fs.readdirSync(path); | |
| 18 | + if (data.length > 0) { | |
| 19 | + data.forEach((f, i) => { | |
| 20 | + delPath(`${path}/${f}`); // 使用递归 | |
| 21 | + if (i == data.length - 1) { | |
| 22 | + // 删了目录里的内容就删掉这个目录 | |
| 23 | + delPath(`${path}`); | |
| 24 | + } | |
| 25 | + }); | |
| 26 | + } else { | |
| 27 | + fs.rmdirSync(path); // 删除空目录 | |
| 28 | + } | |
| 29 | + } else if (info.isFile()) { | |
| 30 | + fs.unlinkSync(path); // 删除文件 | |
| 31 | + } | |
| 32 | +}; | |
| 33 | + | |
| 34 | +// 清除输出目录 | |
| 35 | +if (fs.existsSync(outputPath)) { | |
| 36 | + delPath(outputPath); | |
| 37 | +} | |
| 38 | + | |
| 39 | +const cmd = 'vue-cli-service build --target lib --name zee --dest release packages/index.js'; | |
| 40 | + | |
| 41 | +const spinner = ora('编译中...').start(); | |
| 42 | + | |
| 43 | +exec(cmd, function(error, stdout, stderr) { | |
| 44 | + if (error) { | |
| 45 | + throw error; | |
| 46 | + } | |
| 47 | + fs.readdirSync(outputPath).forEach(file => { | |
| 48 | + if (file !== 'zee.css') { | |
| 49 | + if (file === 'zee.umd.min.js') { | |
| 50 | + fs.renameSync(path.resolve(outputPath, file), path.resolve(outputPath, 'zee.js')); | |
| 51 | + } else { | |
| 52 | + fs.unlinkSync(path.resolve(outputPath, file)); | |
| 53 | + } | |
| 54 | + } | |
| 55 | + }); | |
| 56 | + spinner.succeed('编译完成'); | |
| 57 | +}); | ... | ... |
yarn.lock
| ... | ... | @@ -2708,6 +2708,11 @@ cli-spinners@^2.0.0: |
| 2708 | 2708 | resolved "https://registry.npm.taobao.org/cli-spinners/download/cli-spinners-2.2.0.tgz#e8b988d9206c692302d8ee834e7a85c0144d8f77" |
| 2709 | 2709 | integrity sha1-6LmI2SBsaSMC2O6DTnqFwBRNj3c= |
| 2710 | 2710 | |
| 2711 | +cli-spinners@^2.2.0: | |
| 2712 | + version "2.4.0" | |
| 2713 | + resolved "https://registry.npm.taobao.org/cli-spinners/download/cli-spinners-2.4.0.tgz?cache=0&sync_timestamp=1595080390100&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcli-spinners%2Fdownload%2Fcli-spinners-2.4.0.tgz#c6256db216b878cfba4720e719cec7cf72685d7f" | |
| 2714 | + integrity sha1-xiVtsha4eM+6RyDnGc7Hz3JoXX8= | |
| 2715 | + | |
| 2711 | 2716 | cli-truncate@2.1.0, cli-truncate@^2.1.0: |
| 2712 | 2717 | version "2.1.0" |
| 2713 | 2718 | resolved "https://registry.npm.taobao.org/cli-truncate/download/cli-truncate-2.1.0.tgz#c39e28bf05edcde5be3b98992a22deed5a2b93c7" |
| ... | ... | @@ -5372,6 +5377,11 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1: |
| 5372 | 5377 | dependencies: |
| 5373 | 5378 | is-extglob "^2.1.1" |
| 5374 | 5379 | |
| 5380 | +is-interactive@^1.0.0: | |
| 5381 | + version "1.0.0" | |
| 5382 | + resolved "https://registry.npm.taobao.org/is-interactive/download/is-interactive-1.0.0.tgz#cea6e6ae5c870a7b0a0004070b7b587e0252912e" | |
| 5383 | + integrity sha1-zqbmrlyHCnsKAAQHC3tYfgJSkS4= | |
| 5384 | + | |
| 5375 | 5385 | is-number@^3.0.0: |
| 5376 | 5386 | version "3.0.0" |
| 5377 | 5387 | resolved "https://registry.npm.taobao.org/is-number/download/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" |
| ... | ... | @@ -5923,6 +5933,13 @@ log-symbols@^2.2.0: |
| 5923 | 5933 | dependencies: |
| 5924 | 5934 | chalk "^2.0.1" |
| 5925 | 5935 | |
| 5936 | +log-symbols@^3.0.0: | |
| 5937 | + version "3.0.0" | |
| 5938 | + resolved "https://registry.npm.taobao.org/log-symbols/download/log-symbols-3.0.0.tgz?cache=0&sync_timestamp=1589682056270&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Flog-symbols%2Fdownload%2Flog-symbols-3.0.0.tgz#f3a08516a5dea893336a7dee14d18a1cfdab77c4" | |
| 5939 | + integrity sha1-86CFFqXeqJMzan3uFNGKHP2rd8Q= | |
| 5940 | + dependencies: | |
| 5941 | + chalk "^2.4.2" | |
| 5942 | + | |
| 5926 | 5943 | log-symbols@^4.0.0: |
| 5927 | 5944 | version "4.0.0" |
| 5928 | 5945 | resolved "https://registry.npm.taobao.org/log-symbols/download/log-symbols-4.0.0.tgz#69b3cc46d20f448eccdb75ea1fa733d9e821c920" |
| ... | ... | @@ -6789,6 +6806,20 @@ ora@^3.4.0: |
| 6789 | 6806 | strip-ansi "^5.2.0" |
| 6790 | 6807 | wcwidth "^1.0.1" |
| 6791 | 6808 | |
| 6809 | +ora@^4.0.5: | |
| 6810 | + version "4.0.5" | |
| 6811 | + resolved "https://registry.npm.taobao.org/ora/download/ora-4.0.5.tgz?cache=0&sync_timestamp=1594997490641&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fora%2Fdownload%2Fora-4.0.5.tgz#7410b5cc2d99fa637fd5099bbb9f02bfbb5a361e" | |
| 6812 | + integrity sha1-dBC1zC2Z+mN/1Qmbu58Cv7taNh4= | |
| 6813 | + dependencies: | |
| 6814 | + chalk "^3.0.0" | |
| 6815 | + cli-cursor "^3.1.0" | |
| 6816 | + cli-spinners "^2.2.0" | |
| 6817 | + is-interactive "^1.0.0" | |
| 6818 | + log-symbols "^3.0.0" | |
| 6819 | + mute-stream "0.0.8" | |
| 6820 | + strip-ansi "^6.0.0" | |
| 6821 | + wcwidth "^1.0.1" | |
| 6822 | + | |
| 6792 | 6823 | original@^1.0.0: |
| 6793 | 6824 | version "1.0.2" |
| 6794 | 6825 | resolved "https://registry.npm.taobao.org/original/download/original-1.0.2.tgz#e442a61cffe1c5fd20a65f3261c26663b303f25f" | ... | ... |