CompilerConfiguration提供更加完善的类型信息
This commit is contained in:
parent
ffe98e1710
commit
6e211b447c
|
|
@ -391,17 +391,30 @@ module.exports = function (webpackEnv) {
|
|||
net: false,
|
||||
tls: false,
|
||||
};
|
||||
let merged = defaultFb;
|
||||
if (
|
||||
projectConfiguration &&
|
||||
projectConfiguration.resolve &&
|
||||
projectConfiguration.resolve.fallback
|
||||
) {
|
||||
Object.assign(
|
||||
defaultFb,
|
||||
projectConfiguration.resolve.fallback
|
||||
);
|
||||
if(Array.isArray(projectConfiguration.resolve.fallback)) {
|
||||
merged = [...Object.keys(defaultFb).map(key => {
|
||||
// transform to :
|
||||
// {
|
||||
// alias: string | false | string[];
|
||||
// name: string;
|
||||
// onlyModule?: boolean;
|
||||
// }[]
|
||||
return {
|
||||
alias: defaultFb[key],
|
||||
name: key,
|
||||
}
|
||||
}), ...projectConfiguration.resolve.fallback];
|
||||
} else {
|
||||
merged = Object.assign(defaultFb, projectConfiguration.resolve.fallback);
|
||||
}
|
||||
}
|
||||
return defaultFb;
|
||||
return merged;
|
||||
})(),
|
||||
// This allows you to set a fallback for where webpack should look for modules.
|
||||
// We placed these paths second because we want `node_modules` to "win"
|
||||
|
|
@ -433,17 +446,34 @@ module.exports = function (webpackEnv) {
|
|||
'bn.js': require.resolve('bn.js'),
|
||||
assert: require.resolve('browser-assert'),
|
||||
};
|
||||
let merged = defaultAlias;
|
||||
if (
|
||||
projectConfiguration &&
|
||||
projectConfiguration.resolve &&
|
||||
projectConfiguration.resolve.alias
|
||||
) {
|
||||
Object.assign(
|
||||
defaultAlias,
|
||||
projectConfiguration.resolve.alias
|
||||
);
|
||||
// Object.assign(
|
||||
// defaultAlias,
|
||||
// projectConfiguration.resolve.alias
|
||||
// );
|
||||
if (Array.isArray(projectConfiguration.resolve.alias)) {
|
||||
// transform to :
|
||||
//{
|
||||
// alias: string | false | string[];
|
||||
// name: string;
|
||||
// onlyModule?: boolean;
|
||||
// }[]
|
||||
merged = [...Object.keys(defaultAlias).map(key => {
|
||||
return {
|
||||
alias: defaultAlias[key],
|
||||
name: key,
|
||||
}
|
||||
}), ...projectConfiguration.resolve.alias];
|
||||
} else {
|
||||
merged = Object.assign(defaultAlias, projectConfiguration.resolve.alias)
|
||||
}
|
||||
}
|
||||
return defaultAlias;
|
||||
return merged;
|
||||
})(),
|
||||
plugins: [
|
||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||
|
|
|
|||
|
|
@ -1,4 +1,25 @@
|
|||
import { CompilerConfiguration } from 'oak-domain/lib/types/Configuration';
|
||||
import { Configuration as WebpackConfiguration } from 'webpack';
|
||||
type ResolveType = Required<WebpackConfiguration>['resolve'];
|
||||
type AliasType = Required<ResolveType>['alias'];
|
||||
type FallbackType = Required<ResolveType>['fallback'];
|
||||
type OptimizationType = Required<WebpackConfiguration>['optimization'];
|
||||
type SplitChunks = Required<OptimizationType>['splitChunks'];
|
||||
type CacheGroups = Exclude<SplitChunks, false>["cacheGroups"];
|
||||
/**
|
||||
* 编译环境配置
|
||||
*/
|
||||
export type CompilerConfiguration = {
|
||||
webpack?: {
|
||||
resolve?: {
|
||||
alias?: AliasType;
|
||||
fallback?: FallbackType;
|
||||
};
|
||||
extraOakModules?: (string | RegExp)[];
|
||||
splitChunks: {
|
||||
cacheGroups: CacheGroups;
|
||||
};
|
||||
};
|
||||
};
|
||||
/**
|
||||
* 创建一个oak编译器配置
|
||||
* @param raw 原始配置
|
||||
|
|
@ -6,3 +27,9 @@ import { CompilerConfiguration } from 'oak-domain/lib/types/Configuration';
|
|||
* 通过这个函数可以实现对配置文件的预处理,以及在项目中创建配置时提供类型参考
|
||||
*/
|
||||
export declare function CreateComilerConfig(raw: CompilerConfiguration): CompilerConfiguration;
|
||||
export {};
|
||||
/**
|
||||
* 将compiler.js中的模块导出使用以下形式:
|
||||
* module.exports = CreateComilerConfig({})
|
||||
* 可以在编写时获得类型提示
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -11,3 +11,8 @@ function CreateComilerConfig(raw) {
|
|||
// 在这里可以做配置的预处理
|
||||
return raw;
|
||||
}
|
||||
/**
|
||||
* 将compiler.js中的模块导出使用以下形式:
|
||||
* module.exports = CreateComilerConfig({})
|
||||
* 可以在编写时获得类型提示
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,31 @@
|
|||
import { CompilerConfiguration } from 'oak-domain/lib/types/Configuration';
|
||||
// webpack config type
|
||||
import { Configuration as WebpackConfiguration } from 'webpack';
|
||||
|
||||
type ResolveType = Required<WebpackConfiguration>['resolve'];
|
||||
type AliasType = Required<ResolveType>['alias'];
|
||||
type FallbackType = Required<ResolveType>['fallback'];
|
||||
type OptimizationType = Required<WebpackConfiguration>['optimization'];
|
||||
type SplitChunks = Required<OptimizationType>['splitChunks'];
|
||||
type CacheGroups = Exclude<SplitChunks, false>["cacheGroups"];
|
||||
type ExternalsType = Required<WebpackConfiguration>['externals'];
|
||||
type ExternalsObjectType = Exclude<ExternalsType, RegExp | string | Function | Array<any>>;
|
||||
|
||||
/**
|
||||
* 编译环境配置
|
||||
*/
|
||||
export type CompilerConfiguration = {
|
||||
webpack?: {
|
||||
resolve?: {
|
||||
alias?: AliasType;
|
||||
fallback?: FallbackType;
|
||||
},
|
||||
extraOakModules?: (string | RegExp)[]; // 被标记的module也会和项目一起被oak编译plugin进行处理(注入getRender,处理i18n等)
|
||||
splitChunks: {
|
||||
cacheGroups: CacheGroups;
|
||||
},
|
||||
externals?: ExternalsObjectType;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建一个oak编译器配置
|
||||
|
|
|
|||
Loading…
Reference in New Issue