chore: 完成部分 vite 构建相关

This commit is contained in:
winixt 2022-04-03 20:00:24 +08:00
parent 31ff10532e
commit e3d49d51c8
7 changed files with 186 additions and 19 deletions

View File

@ -28,7 +28,8 @@
"strong"
],
"dependencies": {
"lerna": "^4.0.0"
"lerna": "^4.0.0",
"vuepress": "2.0.0-beta.28"
},
"devDependencies": {
"@babel/core": "^7.15.0",
@ -51,7 +52,6 @@
"lint-staged": "^10.4.0",
"postcss": "^8.0.0",
"postcss-loader": "^5.0.0",
"vuepress": "2.0.0-beta.28",
"yargs-parser": "^20.2.9"
},
"lint-staged": {
@ -117,4 +117,4 @@
}
}
}
}
}

View File

@ -25,10 +25,13 @@
},
"dependencies": {
"@fesjs/utils": "^2.0.4",
"@vitejs/plugin-legacy": "^1.8.0",
"@vitejs/plugin-vue": "^2.2.4",
"@vitejs/plugin-vue-jsx": "^1.3.8",
"autoprefixer": "^10.4.4",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-safe-parser": "^6.0.0",
"rollup-plugin-visualizer": "^5.6.0",
"vite": "^2.8.6",
"vite-plugin-html": "^3.2.0"
},

View File

@ -0,0 +1,29 @@
import { getInnerCommonConfig } from '../../common/getConfig';
/**
* polyfill @vitejs/plugin-legacy
* 确认 css 最终构建实现 autoprefixer postcss-safe-parser postcss-flexbugs-fixes
*/
export default async (api) => {
const { deepmerge } = api.utils;
const { build = {} } = api.config.viteOption;
return deepmerge(
{
mode: 'production',
css: {
postcss: {
plugins: [require('postcss-flexbugs-fixes'), require('postcss-safe-parser'), [require('autoprefixer'), {}]],
},
},
build: {
...build,
outDir: build.outDir || api.config.outputPath || 'dist',
assetsInlineLimit: build.assetsInlineLimit || api.config.inlineLimit || 8192,
},
},
getInnerCommonConfig(api),
);
};

View File

@ -1,11 +1,42 @@
/**
* outputPath
* inlineLimit: 如何实现
* publicPath: 就是 base
* polyfill @vitejs/plugin-legacy
* 确认 css 最终构建实现 autoprefixer postcss-safe-parser postcss-flexbugs-fixes
*/
import { build } from 'vite';
import { existsSync } from 'fs';
import getBuildConfig from './getBuildConfig';
export default () => {
// console.log(api, 'TODO: 实现 vite build');
};
export default function (api) {
const {
paths,
utils: { rimraf },
} = api;
api.registerCommand({
command: 'build',
description: 'build application for production',
async fn() {
rimraf.sync(paths.absTmpPath);
// generate files
await api.applyPlugins({
key: 'onGenerateFiles',
type: api.ApplyPluginsType.event,
});
const bundleConfig = await getBuildConfig(api);
try {
// clear output path before exec build
if (process.env.CLEAR_OUTPUT !== 'none') {
if (paths.absOutputPath && existsSync(paths.absOutputPath)) {
rimraf.sync(paths.absOutputPath);
}
}
await build(bundleConfig);
if (process.env.RM_TMPDIR !== 'none') {
rimraf.sync(paths.absTmpPath);
}
} catch (err) {
// throw build error
throw err;
}
},
});
}

View File

@ -12,10 +12,11 @@ export function getInnerCommonConfig(api) {
const { deepmerge } = api.utils;
const { server, build, define, base, ...otherViteOption } = api.config.viteOption;
const publicPath = base || api.config.publicPath;
const publicPath = base || api.config.publicPath || '/';
return deepmerge(
{
base: publicPath,
configFile: false,
define: getDefine(api, publicPath),
cacheDir: join(api.cwd, '.cache'),

View File

@ -0,0 +1,12 @@
export default (api) => {
api.describe({
key: 'viteAnalyze',
config: {
schema(joi) {
return joi.object({}).unknown(true);
},
default: {},
},
enableBy: () => !!process.env.ANALYZE,
});
};

101
yarn.lock
View File

@ -1137,6 +1137,11 @@
dependencies:
regenerator-runtime "^0.13.4"
"@babel/standalone@^7.17.8":
version "7.17.8"
resolved "https://registry.npmmirror.com/@babel/standalone/-/standalone-7.17.8.tgz#517064e5b21015476d4dc9c6518b47bf2ec4d094"
integrity sha512-tr3SDpVnxR/fzrxyG+HZPAyEA9eTHZIAjy4eqrc7m+KBwsdo1YvTbUfJ6teWHQ177mk6GmdmltsIiOYCcvRPWA==
"@babel/template@^7.0.0", "@babel/template@^7.16.7", "@babel/template@^7.3.3":
version "7.16.7"
resolved "https://registry.npmmirror.com/@babel/template/-/template-7.16.7.tgz#8d126c8701fde4d66b264b3eba3d96f07666d155"
@ -2987,6 +2992,17 @@
dependencies:
"@types/yargs-parser" "*"
"@vitejs/plugin-legacy@^1.8.0":
version "1.8.0"
resolved "https://registry.npmmirror.com/@vitejs/plugin-legacy/-/plugin-legacy-1.8.0.tgz#6521e6de924641094aad5d804eaef3ac7db71284"
integrity sha512-S3+uL1zp8GLUbmJAQk2wQbZLTyISKRFSMBwCFI3XQVRD3OZshqkiPyOKdRiSPlP9HoGz+q90kk+1qPm1tJRqCg==
dependencies:
"@babel/standalone" "^7.17.8"
core-js "^3.21.1"
magic-string "^0.26.1"
regenerator-runtime "^0.13.9"
systemjs "^6.12.1"
"@vitejs/plugin-vue-jsx@^1.3.8":
version "1.3.9"
resolved "https://registry.npmmirror.com/@vitejs/plugin-vue-jsx/-/plugin-vue-jsx-1.3.9.tgz#2a9f9c5adcc90556aa56bc60dd923e6259d5f40e"
@ -4019,7 +4035,7 @@ atob@^2.1.2:
resolved "https://registry.npmmirror.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==
autoprefixer@^10.2.4, autoprefixer@^10.4.0:
autoprefixer@^10.2.4, autoprefixer@^10.4.0, autoprefixer@^10.4.4:
version "10.4.4"
resolved "https://registry.npmmirror.com/autoprefixer/-/autoprefixer-10.4.4.tgz#3e85a245b32da876a893d3ac2ea19f01e7ea5a1e"
integrity sha512-Tm8JxsB286VweiZ5F0anmbyGiNI3v3wGv3mz9W+cxEDYB/6jbnj6GM9H9mK3wIL8ftgl+C07Lcwb8PG5PCCPzA==
@ -5089,7 +5105,7 @@ core-js-compat@^3.20.2, core-js-compat@^3.21.0:
browserslist "^4.19.1"
semver "7.0.0"
core-js@^3.6.1, core-js@^3.8.3:
core-js@^3.21.1, core-js@^3.6.1, core-js@^3.8.3:
version "3.21.1"
resolved "https://registry.npmmirror.com/core-js/-/core-js-3.21.1.tgz#f2e0ddc1fc43da6f904706e8e955bc19d06a0d94"
integrity sha512-FRq5b/VMrWlrmCzwRrpDYNxyHP9BcAZC+xHJaqTgIE5091ZV1NTmyh0sGOg5XqpnHvR0svdy0sv1gWA1zmhxig==
@ -5463,6 +5479,11 @@ defaults@^1.0.3:
dependencies:
clone "^1.0.2"
define-lazy-prop@^2.0.0:
version "2.0.0"
resolved "https://registry.npmmirror.com/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz#3f7ae421129bcaaac9bc74905c98a0009ec9ee7f"
integrity sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==
define-properties@^1.1.3:
version "1.1.3"
resolved "https://registry.npmmirror.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"
@ -7873,6 +7894,11 @@ is-descriptor@^1.0.0, is-descriptor@^1.0.2:
is-data-descriptor "^1.0.0"
kind-of "^6.0.2"
is-docker@^2.0.0, is-docker@^2.1.1:
version "2.2.1"
resolved "https://registry.npmmirror.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa"
integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==
is-extendable@^0.1.0, is-extendable@^0.1.1:
version "0.1.1"
resolved "https://registry.npmmirror.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89"
@ -8109,6 +8135,13 @@ is-wsl@^1.1.0:
resolved "https://registry.npmmirror.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d"
integrity sha512-gfygJYZ2gLTDlmbWMI0CE2MwnFzSN/2SZfkMlItC4K/JBlsWVDB0bO6XhqcY13YXE7iMcAJnzTCJjPiTeJJ0Mw==
is-wsl@^2.2.0:
version "2.2.0"
resolved "https://registry.npmmirror.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271"
integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==
dependencies:
is-docker "^2.0.0"
isarray@1.0.0, isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.npmmirror.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
@ -9159,6 +9192,13 @@ magic-string@^0.25.0, magic-string@^0.25.7:
dependencies:
sourcemap-codec "^1.4.8"
magic-string@^0.26.1:
version "0.26.1"
resolved "https://registry.npmmirror.com/magic-string/-/magic-string-0.26.1.tgz#ba9b651354fa9512474199acecf9c6dbe93f97fd"
integrity sha512-ndThHmvgtieXe8J/VGPjG+Apu7v7ItcD5mhEIvOscWjPF/ccOiLxHaSuCAS2G+3x4GKsAbT8u7zdyamupui8Tg==
dependencies:
sourcemap-codec "^1.4.8"
make-dir@^2.0.0, make-dir@^2.1.0:
version "2.1.0"
resolved "https://registry.npmmirror.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5"
@ -9669,7 +9709,7 @@ nan@^2.12.1:
resolved "https://registry.npmmirror.com/nan/-/nan-2.15.0.tgz#3f34a473ff18e15c1b5626b62903b5ad6e665fee"
integrity sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==
nanoid@^3.1.23, nanoid@^3.3.1:
nanoid@^3.1.23, nanoid@^3.1.32, nanoid@^3.3.1:
version "3.3.2"
resolved "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.2.tgz#c89622fafb4381cd221421c69ec58547a1eec557"
integrity sha512-CuHBogktKwpm5g2sRgv83jEy2ijFzBwMoYA60orPDR7ynsLijJDqgsi4RDGj3OJpy3Ieb+LYwiRmIOGyytgITA==
@ -10110,6 +10150,15 @@ onetime@^5.1.0, onetime@^5.1.2:
dependencies:
mimic-fn "^2.1.0"
open@^8.4.0:
version "8.4.0"
resolved "https://registry.npmmirror.com/open/-/open-8.4.0.tgz#345321ae18f8138f82565a910fdc6b39e8c244f8"
integrity sha512-XgFPPM+B28FtCCgSb9I+s9szOC1vZRSwgWsRUA5ylIxRTgKozqjOCrVOqGsYABPYK5qnfqClxZTFBa8PKt2v6Q==
dependencies:
define-lazy-prop "^2.0.0"
is-docker "^2.1.1"
is-wsl "^2.2.0"
opencollective-postinstall@^2.0.2:
version "2.0.3"
resolved "https://registry.npmmirror.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259"
@ -11308,7 +11357,7 @@ regenerate@^1.4.2:
resolved "https://registry.npmmirror.com/regenerate/-/regenerate-1.4.2.tgz#b9346d8827e8f5a32f7ba29637d398b69014848a"
integrity sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==
regenerator-runtime@^0.13.4:
regenerator-runtime@^0.13.4, regenerator-runtime@^0.13.9:
version "0.13.9"
resolved "https://registry.npmmirror.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"
integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==
@ -11570,6 +11619,16 @@ rollup-plugin-terser@^7.0.0:
serialize-javascript "^4.0.0"
terser "^5.0.0"
rollup-plugin-visualizer@^5.6.0:
version "5.6.0"
resolved "https://registry.npmmirror.com/rollup-plugin-visualizer/-/rollup-plugin-visualizer-5.6.0.tgz#06aa7cf3fd504a29d404335700f2a3f28ebb33f3"
integrity sha512-CKcc8GTUZjC+LsMytU8ocRr/cGZIfMR7+mdy4YnlyetlmIl/dM8BMnOEpD4JPIGt+ZVW7Db9ZtSsbgyeBH3uTA==
dependencies:
nanoid "^3.1.32"
open "^8.4.0"
source-map "^0.7.3"
yargs "^17.3.1"
rollup@^2.43.1, rollup@^2.59.0, rollup@^2.60.2:
version "2.70.1"
resolved "https://registry.npmmirror.com/rollup/-/rollup-2.70.1.tgz#824b1f1f879ea396db30b0fc3ae8d2fead93523e"
@ -11641,7 +11700,7 @@ sass-loader@^12.4.0:
klona "^2.0.4"
neo-async "^2.6.2"
sass@^1.32.11, sass@^1.44.0:
sass@^1.32.11:
version "1.49.10"
resolved "https://registry.npmmirror.com/sass/-/sass-1.49.10.tgz#7b83cee0f03bbba443111b3f94944fde2b0c7a6b"
integrity sha512-w37zfWJwKu4I78U4z63u1mmgoncq+v3iOB4yzQMPyAPVHHawaQSnu9C9ysGQnZEhW609jkcLioJcMCqm75JMdg==
@ -11650,6 +11709,15 @@ sass@^1.32.11, sass@^1.44.0:
immutable "^4.0.0"
source-map-js ">=0.6.2 <2.0.0"
sass@^1.44.0:
version "1.49.11"
resolved "https://registry.npmmirror.com/sass/-/sass-1.49.11.tgz#1ffeb77faeed8b806a2a1e021d7c9fd3fc322cb7"
integrity sha512-wvS/geXgHUGs6A/4ud5BFIWKO1nKd7wYIGimDk4q4GFkJicILActpv9ueMT4eRGSsp1BdKHuw1WwAHXbhsJELQ==
dependencies:
chokidar ">=3.0.0 <4.0.0"
immutable "^4.0.0"
source-map-js ">=0.6.2 <2.0.0"
saxes@^5.0.1:
version "5.0.1"
resolved "https://registry.npmmirror.com/saxes/-/saxes-5.0.1.tgz#eebab953fa3b7608dbe94e5dadb15c888fa6696d"
@ -12535,6 +12603,11 @@ symbol-tree@^3.2.4:
resolved "https://registry.npmmirror.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==
systemjs@^6.12.1:
version "6.12.1"
resolved "https://registry.npmmirror.com/systemjs/-/systemjs-6.12.1.tgz#47cdd23a6ec9f1b01cf5b5f70562c8550da229d3"
integrity sha512-hqTN6kW+pN6/qro6G9OZ7ceDQOcYno020zBQKpZQLsJhYTDMCMNfXi/Y8duF5iW+4WWZr42ry0MMkcRGpbwG2A==
tapable@^2.0.0, tapable@^2.1.1, tapable@^2.2.0:
version "2.2.1"
resolved "https://registry.npmmirror.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0"
@ -13961,6 +14034,11 @@ yargs-parser@^18.1.2:
camelcase "^5.0.0"
decamelize "^1.2.0"
yargs-parser@^21.0.0:
version "21.0.1"
resolved "https://registry.npmmirror.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35"
integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==
yargs@^13.3.2:
version "13.3.2"
resolved "https://registry.npmmirror.com/yargs/-/yargs-13.3.2.tgz#ad7ffefec1aa59565ac915f82dccb38a9c31a2dd"
@ -14007,6 +14085,19 @@ yargs@^16.0.0, yargs@^16.2.0:
y18n "^5.0.5"
yargs-parser "^20.2.2"
yargs@^17.3.1:
version "17.4.0"
resolved "https://registry.npmmirror.com/yargs/-/yargs-17.4.0.tgz#9fc9efc96bd3aa2c1240446af28499f0e7593d00"
integrity sha512-WJudfrk81yWFSOkZYpAZx4Nt7V4xp7S/uJkX0CnxovMCt1wCE8LNftPpNuF9X/u9gN5nsD7ycYtRcDf2pL3UiA==
dependencies:
cliui "^7.0.2"
escalade "^3.1.1"
get-caller-file "^2.0.5"
require-directory "^2.1.1"
string-width "^4.2.3"
y18n "^5.0.5"
yargs-parser "^21.0.0"
yn@3.1.1:
version "3.1.1"
resolved "https://registry.npmmirror.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"