mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(cli): support config site publicPath and outputDir
This commit is contained in:
parent
d44258c3c4
commit
f1310ff01b
@ -112,7 +112,11 @@
|
|||||||
"root": true,
|
"root": true,
|
||||||
"extends": [
|
"extends": [
|
||||||
"@vant"
|
"@vant"
|
||||||
]
|
],
|
||||||
|
"rules": {
|
||||||
|
"global-require": 0,
|
||||||
|
"import/no-dynamic-require": 0
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"stylelint": {
|
"stylelint": {
|
||||||
"extends": [
|
"extends": [
|
||||||
|
@ -5,6 +5,7 @@ export const ES_DIR = join(CWD, 'es');
|
|||||||
export const LIB_DIR = join(CWD, 'lib');
|
export const LIB_DIR = join(CWD, 'lib');
|
||||||
export const SRC_DIR = join(CWD, 'src');
|
export const SRC_DIR = join(CWD, 'src');
|
||||||
export const DOCS_DIR = join(CWD, 'docs');
|
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 CONFIG_FILE = join(CWD, 'vant.config.js');
|
||||||
export const PACKAGE_JSON_FILE = join(CWD, 'package.json');
|
export const PACKAGE_JSON_FILE = join(CWD, 'package.json');
|
||||||
export const WEBPACK_CONFIG_FILE = join(CWD, 'webpack.config.js');
|
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_ENTRY_FILE = join(DIST_DIR, 'package-entry.js');
|
||||||
export const PACKAGE_STYLE_FILE = join(DIST_DIR, 'package-style.css');
|
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 SITE_MODILE_SHARED_FILE = join(DIST_DIR, 'site-mobile-shared.js');
|
||||||
export const DESKTOP_ENTRY_FILE = join(DIST_DIR, 'site-desktop-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 STYPE_DEPS_JSON_FILE = join(DIST_DIR, 'style-deps.json');
|
||||||
|
|
||||||
export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js');
|
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 SCRIPT_EXTS = ['.js', '.jsx', '.vue', '.ts', '.tsx'];
|
||||||
export const STYLE_EXTS = ['.css', '.less', '.scss'];
|
export const STYLE_EXTS = ['.css', '.less', '.scss'];
|
||||||
|
|
||||||
// eslint-disable-next-line
|
|
||||||
export const CONFIG = require(CONFIG_FILE);
|
export const CONFIG = require(CONFIG_FILE);
|
||||||
// eslint-disable-next-line
|
|
||||||
export const PACKAGE_JSON = require(PACKAGE_JSON_FILE);
|
export const PACKAGE_JSON = require(PACKAGE_JSON_FILE);
|
||||||
|
@ -76,7 +76,6 @@ export function pascalize(str: string): string {
|
|||||||
|
|
||||||
export function getWebpackConfig(): object {
|
export function getWebpackConfig(): object {
|
||||||
if (existsSync(WEBPACK_CONFIG_FILE)) {
|
if (existsSync(WEBPACK_CONFIG_FILE)) {
|
||||||
// eslint-disable-next-line
|
|
||||||
const config = require(WEBPACK_CONFIG_FILE);
|
const config = require(WEBPACK_CONFIG_FILE);
|
||||||
|
|
||||||
if (typeof config === 'function') {
|
if (typeof config === 'function') {
|
||||||
|
@ -9,7 +9,6 @@ import { getStyleExt } from './gen-package-style';
|
|||||||
import { ES_DIR, LIB_DIR, STYPE_DEPS_JSON_FILE } from '../common/constant';
|
import { ES_DIR, LIB_DIR, STYPE_DEPS_JSON_FILE } from '../common/constant';
|
||||||
|
|
||||||
function getDeps(component: string): string[] {
|
function getDeps(component: string): string[] {
|
||||||
// eslint-disable-next-line
|
|
||||||
const styleDepsJson = require(STYPE_DEPS_JSON_FILE);
|
const styleDepsJson = require(STYPE_DEPS_JSON_FILE);
|
||||||
|
|
||||||
if (styleDepsJson.map[component]) {
|
if (styleDepsJson.map[component]) {
|
||||||
|
@ -20,7 +20,6 @@ export function getStyleExt(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function genPacakgeStyle() {
|
export function genPacakgeStyle() {
|
||||||
// eslint-disable-next-line
|
|
||||||
const styleDepsJson = require(STYPE_DEPS_JSON_FILE);
|
const styleDepsJson = require(STYPE_DEPS_JSON_FILE);
|
||||||
|
|
||||||
const ext = '.' + getStyleExt();
|
const ext = '.' + getStyleExt();
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
SRC_DIR,
|
SRC_DIR,
|
||||||
DOCS_DIR,
|
DOCS_DIR,
|
||||||
CONFIG_FILE,
|
CONFIG_FILE,
|
||||||
DESKTOP_ENTRY_FILE
|
SITE_DESKTOP_SHARED_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
|
|
||||||
type DocumentItem = {
|
type DocumentItem = {
|
||||||
@ -64,5 +64,5 @@ ${genExportConfig()}
|
|||||||
${genExportDocuments(documents)}
|
${genExportDocuments(documents)}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
writeFileSync(DESKTOP_ENTRY_FILE, code);
|
writeFileSync(SITE_DESKTOP_SHARED_FILE, code);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
CONFIG,
|
CONFIG,
|
||||||
SRC_DIR,
|
SRC_DIR,
|
||||||
DIST_DIR,
|
DIST_DIR,
|
||||||
MOBILE_ENTRY_FILE
|
SITE_MODILE_SHARED_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
|
|
||||||
type DemoItem = {
|
type DemoItem = {
|
||||||
@ -35,7 +35,6 @@ function genExports(demos: DemoItem[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function genConfig(demos: DemoItem[]) {
|
function genConfig(demos: DemoItem[]) {
|
||||||
// eslint-disable-next-line
|
|
||||||
const demoNames = demos.map(item => decamelize(item.name, '-'));
|
const demoNames = demos.map(item => decamelize(item.name, '-'));
|
||||||
|
|
||||||
CONFIG.site.nav = CONFIG.site.nav.filter((group: any) => {
|
CONFIG.site.nav = CONFIG.site.nav.filter((group: any) => {
|
||||||
@ -66,5 +65,5 @@ export function genSiteMobileShared() {
|
|||||||
const code = genCode(components);
|
const code = genCode(components);
|
||||||
|
|
||||||
ensureDirSync(DIST_DIR);
|
ensureDirSync(DIST_DIR);
|
||||||
writeFileSync(MOBILE_ENTRY_FILE, code);
|
writeFileSync(SITE_MODILE_SHARED_FILE, code);
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,12 @@ import merge from 'webpack-merge';
|
|||||||
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { baseConfig } from './webpack.base';
|
import { baseConfig } from './webpack.base';
|
||||||
import { CONFIG, MOBILE_ENTRY_FILE, DESKTOP_ENTRY_FILE } from '../common/constant';
|
|
||||||
import { getWebpackConfig } from '../common';
|
import { getWebpackConfig } from '../common';
|
||||||
|
import {
|
||||||
|
CONFIG,
|
||||||
|
SITE_MODILE_SHARED_FILE,
|
||||||
|
SITE_DESKTOP_SHARED_FILE
|
||||||
|
} from '../common/constant';
|
||||||
|
|
||||||
const siteConfig = CONFIG.site;
|
const siteConfig = CONFIG.site;
|
||||||
const title = `${siteConfig.title} - ${siteConfig.description}`;
|
const title = `${siteConfig.title} - ${siteConfig.description}`;
|
||||||
@ -23,8 +27,8 @@ export const siteDevConfig = merge(
|
|||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'site-mobile-shared': MOBILE_ENTRY_FILE,
|
'site-mobile-shared': SITE_MODILE_SHARED_FILE,
|
||||||
'site-desktop-shared': DESKTOP_ENTRY_FILE
|
'site-desktop-shared': SITE_DESKTOP_SHARED_FILE
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
import merge from 'webpack-merge';
|
import merge from 'webpack-merge';
|
||||||
import { join } from 'path';
|
import { get } from 'lodash';
|
||||||
import { siteDevConfig } from './webpack.site.dev';
|
import { siteDevConfig } from './webpack.site.dev';
|
||||||
import { getWebpackConfig } from '../common';
|
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(
|
export const sitePrdConfig = merge(
|
||||||
siteDevConfig,
|
siteDevConfig,
|
||||||
{
|
{
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
output: {
|
output: {
|
||||||
path: join(__dirname, '../../site/dist'),
|
publicPath,
|
||||||
publicPath: 'https://b.yzcdn.cn/vant/',
|
path: outputDir,
|
||||||
filename: '[name].[hash:8].js',
|
filename: '[name].[hash:8].js',
|
||||||
chunkFilename: 'async_[name].[chunkhash:8].js'
|
chunkFilename: 'async_[name].[chunkhash:8].js'
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user