mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(@vant/cli): suport modify internal webpack config (#7227)
This commit is contained in:
parent
43da00b724
commit
0642a73628
@ -6,12 +6,14 @@ import {
|
|||||||
readFileSync,
|
readFileSync,
|
||||||
outputFileSync,
|
outputFileSync,
|
||||||
} from 'fs-extra';
|
} from 'fs-extra';
|
||||||
|
import merge from 'webpack-merge';
|
||||||
import {
|
import {
|
||||||
SRC_DIR,
|
SRC_DIR,
|
||||||
getVantConfig,
|
getVantConfig,
|
||||||
ROOT_WEBPACK_CONFIG_FILE,
|
ROOT_WEBPACK_CONFIG_FILE,
|
||||||
ROOT_POSTCSS_CONFIG_FILE,
|
ROOT_POSTCSS_CONFIG_FILE,
|
||||||
} from './constant';
|
} from './constant';
|
||||||
|
import { WebpackConfig } from './types';
|
||||||
|
|
||||||
export const EXT_REGEXP = /\.\w+$/;
|
export const EXT_REGEXP = /\.\w+$/;
|
||||||
export const SFC_REGEXP = /\.(vue)$/;
|
export const SFC_REGEXP = /\.(vue)$/;
|
||||||
@ -37,9 +39,9 @@ export function getComponents() {
|
|||||||
const EXCLUDES = ['.DS_Store'];
|
const EXCLUDES = ['.DS_Store'];
|
||||||
const dirs = readdirSync(SRC_DIR);
|
const dirs = readdirSync(SRC_DIR);
|
||||||
return dirs
|
return dirs
|
||||||
.filter(dir => !EXCLUDES.includes(dir))
|
.filter((dir) => !EXCLUDES.includes(dir))
|
||||||
.filter(dir =>
|
.filter((dir) =>
|
||||||
ENTRY_EXTS.some(ext => {
|
ENTRY_EXTS.some((ext) => {
|
||||||
const path = join(SRC_DIR, dir, `index.${ext}`);
|
const path = join(SRC_DIR, dir, `index.${ext}`);
|
||||||
if (existsSync(path)) {
|
if (existsSync(path)) {
|
||||||
return hasDefaultExport(readFileSync(path, 'utf-8'));
|
return hasDefaultExport(readFileSync(path, 'utf-8'));
|
||||||
@ -99,18 +101,20 @@ export function normalizePath(path: string): string {
|
|||||||
return path.replace(/\\/g, '/');
|
return path.replace(/\\/g, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getWebpackConfig(): object {
|
export function getWebpackConfig(defaultConfig: WebpackConfig): object {
|
||||||
if (existsSync(ROOT_WEBPACK_CONFIG_FILE)) {
|
if (existsSync(ROOT_WEBPACK_CONFIG_FILE)) {
|
||||||
const config = require(ROOT_WEBPACK_CONFIG_FILE);
|
const config = require(ROOT_WEBPACK_CONFIG_FILE);
|
||||||
|
|
||||||
|
// 如果是函数形式,可能并不仅仅是添加额外的处理流程,而是在原有流程上进行修改
|
||||||
|
// 比如修改markdown-loader,添加options.enableMetaData
|
||||||
if (typeof config === 'function') {
|
if (typeof config === 'function') {
|
||||||
return config();
|
return config(defaultConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return merge(defaultConfig, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return defaultConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPostcssConfig(): object {
|
export function getPostcssConfig(): object {
|
||||||
|
@ -10,9 +10,8 @@ export function getPackageConfig(isMinify: boolean): WebpackConfig {
|
|||||||
|
|
||||||
setBuildTarget('package');
|
setBuildTarget('package');
|
||||||
|
|
||||||
return merge(
|
return getWebpackConfig(
|
||||||
baseConfig as any,
|
merge(baseConfig as any, {
|
||||||
{
|
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
entry: {
|
entry: {
|
||||||
[name]: join(ES_DIR, 'index.js'),
|
[name]: join(ES_DIR, 'index.js'),
|
||||||
@ -39,7 +38,6 @@ export function getPackageConfig(isMinify: boolean): WebpackConfig {
|
|||||||
optimization: {
|
optimization: {
|
||||||
minimize: isMinify,
|
minimize: isMinify,
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
getWebpackConfig()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -103,5 +103,5 @@ export function getSiteDevBaseConfig(): WebpackConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getSiteDevConfig(): WebpackConfig {
|
export function getSiteDevConfig(): WebpackConfig {
|
||||||
return merge(getSiteDevBaseConfig(), getWebpackConfig());
|
return getWebpackConfig(getSiteDevBaseConfig());
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,8 @@ const outputDir = get(vantConfig, 'build.site.outputDir', SITE_DIST_DIR);
|
|||||||
const publicPath = get(vantConfig, 'build.site.publicPath', '/');
|
const publicPath = get(vantConfig, 'build.site.publicPath', '/');
|
||||||
|
|
||||||
export function getSitePrdConfig(): WebpackConfig {
|
export function getSitePrdConfig(): WebpackConfig {
|
||||||
return merge(
|
return getWebpackConfig(
|
||||||
getSiteDevBaseConfig(),
|
merge(getSiteDevBaseConfig(), {
|
||||||
{
|
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
stats: 'none',
|
stats: 'none',
|
||||||
performance: {
|
performance: {
|
||||||
@ -25,7 +24,6 @@ export function getSitePrdConfig(): WebpackConfig {
|
|||||||
filename: '[name].[hash:8].js',
|
filename: '[name].[hash:8].js',
|
||||||
chunkFilename: 'async_[name].[chunkhash:8].js',
|
chunkFilename: 'async_[name].[chunkhash:8].js',
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
getWebpackConfig()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1988,8 +1988,8 @@
|
|||||||
|
|
||||||
"@vant/markdown-loader@^2.3.0":
|
"@vant/markdown-loader@^2.3.0":
|
||||||
version "2.3.0"
|
version "2.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/@vant/markdown-loader/-/markdown-loader-2.3.0.tgz#ea8ab4d8d41609839b40b817bc3a598cf13f9920"
|
resolved "https://registry.npm.taobao.org/@vant/markdown-loader/download/@vant/markdown-loader-2.3.0.tgz#ea8ab4d8d41609839b40b817bc3a598cf13f9920"
|
||||||
integrity sha512-efNAnJMQbX3yP0+/zvnlYda+xIATLl+T9BXOB179M8KkS3hKk0b8tYHYVeLmdCLbJFeVd8bVXICILIplOYQJ5A==
|
integrity sha1-6oq02NQWCYObQLgXvDpZjPE/mSA=
|
||||||
dependencies:
|
dependencies:
|
||||||
front-matter "^3.0.2"
|
front-matter "^3.0.2"
|
||||||
highlight.js "^9.16.2"
|
highlight.js "^9.16.2"
|
||||||
@ -5901,9 +5901,9 @@ he@^1.2.0:
|
|||||||
integrity sha1-hK5l+n6vsWX922FWauFLrwVmTw8=
|
integrity sha1-hK5l+n6vsWX922FWauFLrwVmTw8=
|
||||||
|
|
||||||
highlight.js@^9.16.2:
|
highlight.js@^9.16.2:
|
||||||
version "9.18.1"
|
version "9.18.3"
|
||||||
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.18.1.tgz#ed21aa001fe6252bb10a3d76d47573c6539fe13c"
|
resolved "https://registry.npm.taobao.org/highlight.js/download/highlight.js-9.18.3.tgz#a1a0a2028d5e3149e2380f8a865ee8516703d634"
|
||||||
integrity sha512-OrVKYz70LHsnCgmbXctv/bfuvntIKDz177h0Co37DQ5jamGZLVmoCVMtjMtNZY3X9DrCcKfklHPNeA0uPZhSJg==
|
integrity sha1-oaCiAo1eMUniOA+Khl7oUWcD1jQ=
|
||||||
|
|
||||||
hmac-drbg@^1.0.0:
|
hmac-drbg@^1.0.0:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user