diff --git a/packages/vant-cli/package.json b/packages/vant-cli/package.json index 4d61bdfcb..9fc7c1c27 100644 --- a/packages/vant-cli/package.json +++ b/packages/vant-cli/package.json @@ -27,6 +27,7 @@ "vue-template-compiler": "^2.6.10" }, "devDependencies": { + "@types/csso": "^3.5.1", "@types/eslint": "^6.1.3", "@types/fs-extra": "^8.0.1", "@types/html-webpack-plugin": "^3.2.1", diff --git a/packages/vant-cli/src/compiler/compile-css.ts b/packages/vant-cli/src/compiler/compile-css.ts index 9f718a31f..8faadc51e 100644 --- a/packages/vant-cli/src/compiler/compile-css.ts +++ b/packages/vant-cli/src/compiler/compile-css.ts @@ -1,12 +1,13 @@ import postcss from 'postcss'; import postcssrc from 'postcss-load-config'; +import { minify } from 'csso'; import { POSTCSS_CONFIG_FILE } from '../common/constant'; export async function compileCss(source: string | Buffer) { const config = await postcssrc({}, POSTCSS_CONFIG_FILE); - const output = await postcss(config.plugins as any).process(source, { + const { css } = await postcss(config.plugins as any).process(source, { from: undefined }); - return output; + return minify(css).css; } diff --git a/packages/vant-cli/src/compiler/compile-style.ts b/packages/vant-cli/src/compiler/compile-style.ts index 4fd246eff..8f15f4eba 100644 --- a/packages/vant-cli/src/compiler/compile-style.ts +++ b/packages/vant-cli/src/compiler/compile-style.ts @@ -23,7 +23,7 @@ async function compileFile(filePath: string) { } export async function compileStyle(filePath: string) { - const content = await compileFile(filePath); + const css = await compileFile(filePath); - writeFileSync(replaceExt(filePath, '.css'), content); + writeFileSync(replaceExt(filePath, '.css'), css); } diff --git a/packages/vant-cli/yarn.lock b/packages/vant-cli/yarn.lock index 8b6c485c8..ce70519a0 100644 --- a/packages/vant-cli/yarn.lock +++ b/packages/vant-cli/yarn.lock @@ -1252,6 +1252,18 @@ dependencies: "@types/node" "*" +"@types/css-tree@*": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@types/css-tree/-/css-tree-1.0.3.tgz#69112ebce09f582c9e0f32a46de2598930847cd7" + integrity sha512-ScS4V2j9vL6aMzCIPxJLGKqyslg8zEj+XkzUXCDMHbFftakwEl9WL6RBj3VBTH4O+EVwUM3umZTwu0ZedXyuaA== + +"@types/csso@^3.5.1": + version "3.5.1" + resolved "https://registry.yarnpkg.com/@types/csso/-/csso-3.5.1.tgz#f923bc919bfc89c1b5d149cff80d7bfb5e8e1e8d" + integrity sha512-NnALC1ZR5H4kg/9wUOa8/U2HOAwN4O71Av90HClgCteuwj6UHBEr37I0Cl10EY2gHd5p/JtsbY2r0WbOhYN+gw== + dependencies: + "@types/css-tree" "*" + "@types/eslint-visitor-keys@^1.0.0": version "1.0.0" resolved "https://registry.npm.taobao.org/@types/eslint-visitor-keys/download/@types/eslint-visitor-keys-1.0.0.tgz?cache=0&sync_timestamp=1572470950582&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Feslint-visitor-keys%2Fdownload%2F%40types%2Feslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"