diff --git a/packages/vant-cli/package.json b/packages/vant-cli/package.json index d5331f9b7..5809de67b 100644 --- a/packages/vant-cli/package.json +++ b/packages/vant-cli/package.json @@ -112,7 +112,11 @@ "root": true, "extends": [ "@vant" - ] + ], + "rules": { + "global-require": 0, + "import/no-dynamic-require": 0 + } }, "stylelint": { "extends": [ diff --git a/packages/vant-cli/src/common/constant.ts b/packages/vant-cli/src/common/constant.ts index c59d68c0c..49eeb358e 100644 --- a/packages/vant-cli/src/common/constant.ts +++ b/packages/vant-cli/src/common/constant.ts @@ -5,6 +5,7 @@ export const ES_DIR = join(CWD, 'es'); export const LIB_DIR = join(CWD, 'lib'); export const SRC_DIR = join(CWD, 'src'); export const DOCS_DIR = join(CWD, 'docs'); +export const SITE_DIST_DIR = join(CWD, 'site'); export const CONFIG_FILE = join(CWD, 'vant.config.js'); export const PACKAGE_JSON_FILE = join(CWD, 'package.json'); export const WEBPACK_CONFIG_FILE = join(CWD, 'webpack.config.js'); @@ -14,8 +15,8 @@ export const CONFIG_DIR = join(__dirname, '../config'); export const PACKAGE_ENTRY_FILE = join(DIST_DIR, 'package-entry.js'); export const PACKAGE_STYLE_FILE = join(DIST_DIR, 'package-style.css'); -export const MOBILE_ENTRY_FILE = join(DIST_DIR, 'site-mobile-shared.js'); -export const DESKTOP_ENTRY_FILE = join(DIST_DIR, 'site-desktop-shared.js'); +export const SITE_MODILE_SHARED_FILE = join(DIST_DIR, 'site-mobile-shared.js'); +export const SITE_DESKTOP_SHARED_FILE = join(DIST_DIR, 'site-desktop-shared.js'); export const STYPE_DEPS_JSON_FILE = join(DIST_DIR, 'style-deps.json'); export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js'); @@ -28,7 +29,5 @@ export const JEST_STYLE_MOCK_FILE = join(CONFIG_DIR, 'jest.style-mock.js'); export const SCRIPT_EXTS = ['.js', '.jsx', '.vue', '.ts', '.tsx']; export const STYLE_EXTS = ['.css', '.less', '.scss']; -// eslint-disable-next-line export const CONFIG = require(CONFIG_FILE); -// eslint-disable-next-line export const PACKAGE_JSON = require(PACKAGE_JSON_FILE); diff --git a/packages/vant-cli/src/common/index.ts b/packages/vant-cli/src/common/index.ts index c7f78a27c..ad9e511d0 100644 --- a/packages/vant-cli/src/common/index.ts +++ b/packages/vant-cli/src/common/index.ts @@ -76,7 +76,6 @@ export function pascalize(str: string): string { export function getWebpackConfig(): object { if (existsSync(WEBPACK_CONFIG_FILE)) { - // eslint-disable-next-line const config = require(WEBPACK_CONFIG_FILE); if (typeof config === 'function') { diff --git a/packages/vant-cli/src/compiler/gen-component-style.ts b/packages/vant-cli/src/compiler/gen-component-style.ts index b48abc70e..432934e58 100644 --- a/packages/vant-cli/src/compiler/gen-component-style.ts +++ b/packages/vant-cli/src/compiler/gen-component-style.ts @@ -9,7 +9,6 @@ import { getStyleExt } from './gen-package-style'; import { ES_DIR, LIB_DIR, STYPE_DEPS_JSON_FILE } from '../common/constant'; function getDeps(component: string): string[] { - // eslint-disable-next-line const styleDepsJson = require(STYPE_DEPS_JSON_FILE); if (styleDepsJson.map[component]) { diff --git a/packages/vant-cli/src/compiler/gen-package-style.ts b/packages/vant-cli/src/compiler/gen-package-style.ts index 9e691da2a..10a8ada36 100644 --- a/packages/vant-cli/src/compiler/gen-package-style.ts +++ b/packages/vant-cli/src/compiler/gen-package-style.ts @@ -20,7 +20,6 @@ export function getStyleExt(): string { } export function genPacakgeStyle() { - // eslint-disable-next-line const styleDepsJson = require(STYPE_DEPS_JSON_FILE); const ext = '.' + getStyleExt(); diff --git a/packages/vant-cli/src/compiler/gen-site-desktop-shared.ts b/packages/vant-cli/src/compiler/gen-site-desktop-shared.ts index 45c210b51..f44611b22 100644 --- a/packages/vant-cli/src/compiler/gen-site-desktop-shared.ts +++ b/packages/vant-cli/src/compiler/gen-site-desktop-shared.ts @@ -6,7 +6,7 @@ import { SRC_DIR, DOCS_DIR, CONFIG_FILE, - DESKTOP_ENTRY_FILE + SITE_DESKTOP_SHARED_FILE } from '../common/constant'; type DocumentItem = { @@ -64,5 +64,5 @@ ${genExportConfig()} ${genExportDocuments(documents)} `; - writeFileSync(DESKTOP_ENTRY_FILE, code); + writeFileSync(SITE_DESKTOP_SHARED_FILE, code); } diff --git a/packages/vant-cli/src/compiler/gen-site-mobile-shared.ts b/packages/vant-cli/src/compiler/gen-site-mobile-shared.ts index bcd009c3e..eb8362e37 100644 --- a/packages/vant-cli/src/compiler/gen-site-mobile-shared.ts +++ b/packages/vant-cli/src/compiler/gen-site-mobile-shared.ts @@ -5,7 +5,7 @@ import { CONFIG, SRC_DIR, DIST_DIR, - MOBILE_ENTRY_FILE + SITE_MODILE_SHARED_FILE } from '../common/constant'; type DemoItem = { @@ -35,7 +35,6 @@ function genExports(demos: DemoItem[]) { } function genConfig(demos: DemoItem[]) { - // eslint-disable-next-line const demoNames = demos.map(item => decamelize(item.name, '-')); CONFIG.site.nav = CONFIG.site.nav.filter((group: any) => { @@ -66,5 +65,5 @@ export function genSiteMobileShared() { const code = genCode(components); ensureDirSync(DIST_DIR); - writeFileSync(MOBILE_ENTRY_FILE, code); + writeFileSync(SITE_MODILE_SHARED_FILE, code); } diff --git a/packages/vant-cli/src/config/webpack.site.dev.ts b/packages/vant-cli/src/config/webpack.site.dev.ts index 183fa2c11..4df84d68c 100644 --- a/packages/vant-cli/src/config/webpack.site.dev.ts +++ b/packages/vant-cli/src/config/webpack.site.dev.ts @@ -2,8 +2,12 @@ import merge from 'webpack-merge'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import { join } from 'path'; import { baseConfig } from './webpack.base'; -import { CONFIG, MOBILE_ENTRY_FILE, DESKTOP_ENTRY_FILE } from '../common/constant'; import { getWebpackConfig } from '../common'; +import { + CONFIG, + SITE_MODILE_SHARED_FILE, + SITE_DESKTOP_SHARED_FILE +} from '../common/constant'; const siteConfig = CONFIG.site; const title = `${siteConfig.title} - ${siteConfig.description}`; @@ -23,8 +27,8 @@ export const siteDevConfig = merge( }, resolve: { alias: { - 'site-mobile-shared': MOBILE_ENTRY_FILE, - 'site-desktop-shared': DESKTOP_ENTRY_FILE + 'site-mobile-shared': SITE_MODILE_SHARED_FILE, + 'site-desktop-shared': SITE_DESKTOP_SHARED_FILE } }, output: { diff --git a/packages/vant-cli/src/config/webpack.site.prd.ts b/packages/vant-cli/src/config/webpack.site.prd.ts index 59e819eed..1f52deca5 100644 --- a/packages/vant-cli/src/config/webpack.site.prd.ts +++ b/packages/vant-cli/src/config/webpack.site.prd.ts @@ -1,15 +1,19 @@ import merge from 'webpack-merge'; -import { join } from 'path'; +import { get } from 'lodash'; import { siteDevConfig } from './webpack.site.dev'; import { getWebpackConfig } from '../common'; +import { CONFIG, SITE_DIST_DIR } from '../common/constant'; + +const outputDir = get(CONFIG, 'build.site.outputDir', SITE_DIST_DIR); +const publicPath = get(CONFIG, 'build.site.publicPath', '/'); export const sitePrdConfig = merge( siteDevConfig, { mode: 'production', output: { - path: join(__dirname, '../../site/dist'), - publicPath: 'https://b.yzcdn.cn/vant/', + publicPath, + path: outputDir, filename: '[name].[hash:8].js', chunkFilename: 'async_[name].[chunkhash:8].js' }