From 384ee56f13d04d3ba6d1d3f0c93141ba44c07a51 Mon Sep 17 00:00:00 2001 From: zoy-l <409626581@qq.com> Date: Fri, 25 Jun 2021 17:02:55 +0800 Subject: [PATCH] feat(cli): add convention static directory (#8929) * fix: #8890 sfc compile error * chore(vant-cli): add convention static directory * chore(vant-cli): another way to deal with static resources --- packages/vant-cli/src/commands/build.ts | 5 +++++ packages/vant-cli/src/common/index.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/vant-cli/src/commands/build.ts b/packages/vant-cli/src/commands/build.ts index 1660897ad..9ec5b533a 100644 --- a/packages/vant-cli/src/commands/build.ts +++ b/packages/vant-cli/src/commands/build.ts @@ -19,6 +19,7 @@ import { genVeturConfig } from '../compiler/gen-vetur-config'; import { isDir, isSfc, + isAsset, isStyle, isScript, isDemoDir, @@ -41,6 +42,10 @@ async function compileFile(filePath: string) { return compileStyle(filePath); } + if (isAsset(filePath)) { + return Promise.resolve(); + } + return remove(filePath); } diff --git a/packages/vant-cli/src/common/index.ts b/packages/vant-cli/src/common/index.ts index 0feb4efaa..283674fed 100644 --- a/packages/vant-cli/src/common/index.ts +++ b/packages/vant-cli/src/common/index.ts @@ -14,6 +14,7 @@ export const EXT_REGEXP = /\.\w+$/; export const SFC_REGEXP = /\.(vue)$/; export const DEMO_REGEXP = new RegExp('\\' + sep + 'demo$'); export const TEST_REGEXP = new RegExp('\\' + sep + 'test$'); +export const ASSET_REGEXP = /\.(png|jpe?g|gif|webp|ico|jfif|svg|woff2?|ttf)$/i; export const STYLE_REGEXP = /\.(css|less|scss)$/; export const SCRIPT_REGEXP = /\.(js|ts|jsx|tsx)$/; export const ENTRY_EXTS = ['js', 'ts', 'tsx', 'jsx', 'vue']; @@ -60,6 +61,10 @@ export function isTestDir(dir: string) { return TEST_REGEXP.test(dir); } +export function isAsset(path: string) { + return ASSET_REGEXP.test(path); +} + export function isSfc(path: string) { return SFC_REGEXP.test(path); }