feat(cli): support config site publicPath and outputDir

This commit is contained in:
陈嘉涵 2019-11-29 15:23:40 +08:00
parent d44258c3c4
commit f1310ff01b
9 changed files with 26 additions and 19 deletions

View File

@ -112,7 +112,11 @@
"root": true,
"extends": [
"@vant"
]
],
"rules": {
"global-require": 0,
"import/no-dynamic-require": 0
}
},
"stylelint": {
"extends": [

View File

@ -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);

View File

@ -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') {

View File

@ -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]) {

View File

@ -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();

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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: {

View File

@ -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'
}