Skip to content

Commit dfc1470

Browse files
committed
feat: simplify configuration object
simplifies configuration object by moving defaults config to root level BREAKING CHANGE: config.defaults is now moved to config root level
1 parent db7a425 commit dfc1470

File tree

11 files changed

+171
-178
lines changed

11 files changed

+171
-178
lines changed

README.md

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,44 +81,46 @@ module.exports = createConfig({
8181
*/
8282
formats: ['cjs', 'es'],
8383

84-
/**
85-
* defines default configurations for all build formats
86-
*/
87-
defaults: {
88-
src: './src',
84+
// defines default configurations for all build formats
8985

90-
entryFile: './index',
86+
// default src directory
87+
src: './src',
9188

92-
/**
93-
* allowed file extensions
94-
*/
95-
extensions: ['.js', '.ts', '.jsx', '.tsx'],
89+
// default entry file
90+
entryFile: './index',
9691

97-
/**
98-
* boolean indicating if the interop rollup setting should be enabled
99-
*/
100-
interop: true,
92+
/**
93+
* default allowed file extensions
94+
*/
95+
extensions: ['.js', '.ts', '.jsx', '.tsx'],
10196

102-
/**
103-
* boolean indicating if sourcemap should be generated, can be true, false, or 'inline'
104-
*/
105-
sourcemap: true,
97+
/**
98+
* boolean indicating if the interop rollup setting should be enabled
99+
*/
100+
interop: true,
106101

107-
/**
108-
* applies to umd and iife builds
109-
*/
110-
globals: {},
102+
/**
103+
* boolean indicating if sourcemap should be generated, can be true, false, or 'inline'
104+
*/
105+
sourcemap: true,
111106

112-
babelPlugins: [],
107+
/**
108+
* applies to umd and iife builds
109+
*/
110+
globals: {},
113111

114-
babelPresets: [],
112+
babelPlugins: [],
115113

116-
exclude: [],
114+
babelPresets: [],
117115

118-
include: [],
116+
exclude: [],
119117

120-
plugins: [],
121-
},
118+
include: [],
119+
120+
/**
121+
* rollup plugins to add for all builds
122+
*/
123+
plugins: [],
122124

123125
/**
124126
* cjs build config
@@ -146,9 +148,14 @@ module.exports = createConfig({
146148
['production', 'unminified'],
147149
],
148150

149-
minifiedSuffix: 'min', // set to false if you do not want .[min] prefix in minified builds,
150-
prodBuildSuffix: 'production', // set to false or empty string if you do not want .[production] suffix in output files,
151-
devBuildSuffix: 'development', // set to false or empty string if you do not want .[development] suffix in output files
151+
// set to false if you do not want .[min] prefix in minified builds,
152+
minifiedSuffix: 'min',
153+
154+
// set to false or empty string if you do not want .production suffix in prod build ouputs
155+
prodBuildSuffix: 'production',
156+
157+
// set to false or empty string if you do not want .development suffix in prod build ouputs
158+
devBuildSuffix: 'development',
152159
},
153160

154161
/**

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
"husky": "^9.0.11",
5959
"jest": "26.0.1",
6060
"semantic-release": "^17.3.9",
61-
"semantic-release-cli": "^5.4.3"
61+
"semantic-release-cli": "^5.4.3",
62+
"@types/lodash": "4.17.20"
6263
},
6364
"config": {
6465
"commitizen": {
@@ -86,6 +87,7 @@
8687
"rimraf": "^5.0.0",
8788
"rollup": "^2.39.0",
8889
"rollup-plugin-preserve-shebang": "^1.0.1",
89-
"typescript": "^4.1.5"
90+
"typescript": "^4.1.5",
91+
"lodash": "4.17.21"
9092
}
9193
}

src/@types/index.d.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ export type BuildEnvironment = 'development' | 'production';
77
export type Sourcemap = true | false | 'inline';
88

99
export interface FormatConfig {
10-
moduleName?: string;
11-
1210
src?: string;
1311

1412
out?: string;
@@ -89,19 +87,42 @@ export interface FormatConfig {
8987
prodBuildSuffix?: string | false;
9088
}
9189

92-
export type Config = {
90+
export interface Config extends Omit<FormatConfig, 'out'> {
9391
/**
9492
* formats to build
9593
*/
9694
formats?: Array<BuildFormat>;
9795

96+
/**
97+
* module name
98+
*/
99+
moduleName?: string;
100+
98101
/**
99102
* if true, output logs are not logged
100103
*/
101104
silent?: boolean;
102-
} & Partial<{
103-
[p in BuildFormat | 'defaults']: FormatConfig;
104-
}>;
105+
106+
/**
107+
* cjs specific config
108+
*/
109+
cjs?: FormatConfig;
110+
111+
/**
112+
* iife specific config
113+
*/
114+
iife?: FormatConfig;
115+
116+
/**
117+
* es module specific config
118+
*/
119+
es?: FormatConfig;
120+
121+
/**
122+
* umd specific config
123+
*/
124+
umd?: FormatConfig;
125+
}
105126

106127
export interface Module {
107128
// id for indexing this file

src/config.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,39 @@ import { Config } from './@types';
33
export const config: Config = {
44
formats: ['cjs', 'es'],
55

6-
defaults: {
7-
src: './src',
6+
src: './src',
87

9-
entryFile: './index',
8+
entryFile: './index',
109

11-
/**
12-
* allowed file extensions
13-
*/
14-
extensions: ['.js', '.ts', '.jsx', '.tsx'],
10+
/**
11+
* allowed file extensions
12+
*/
13+
extensions: ['.js', '.ts', '.jsx', '.tsx'],
1514

16-
/**
17-
* boolean indicating if the interop rollup setting should be enabled
18-
*/
19-
interop: true,
15+
/**
16+
* boolean indicating if the interop rollup setting should be enabled
17+
*/
18+
interop: true,
2019

21-
/**
22-
* boolean indicating if sourcemap should be generated, can be true, false, or 'inline'
23-
*/
24-
sourcemap: true,
20+
/**
21+
* boolean indicating if sourcemap should be generated, can be true, false, or 'inline'
22+
*/
23+
sourcemap: true,
2524

26-
/**
27-
* applies to umd and iife builds
28-
*/
29-
globals: {},
25+
/**
26+
* applies to umd and iife builds
27+
*/
28+
globals: {},
3029

31-
babelPlugins: [],
30+
babelPlugins: [],
3231

33-
babelPresets: [],
32+
babelPresets: [],
3433

35-
exclude: [],
34+
exclude: [],
3635

37-
include: [],
36+
include: [],
3837

39-
plugins: [],
40-
},
38+
plugins: [],
4139

4240
/**
4341
* cjs build config

src/constants.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { BuildFormat } from './@types';
2-
31
export const BASE_ASSET_EXTENSIONS = [
42
'.json',
53
'.png',
@@ -12,7 +10,5 @@ export const BASE_ASSET_EXTENSIONS = [
1210
'.sass',
1311
];
1412

15-
export const formats: BuildFormat[] = ['cjs', 'es', 'iife', 'umd'];
16-
1713
export const EXCLUDE_FILES_EXT_REGEX =
1814
/\.(spec|test|stories|tests|specs|cy|snap)(\.[\w-_]+)*$/i;

src/ex/helper.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,39 @@ const name =
88
console.log(name);
99

1010
export const config: Config = {
11-
defaults: {
12-
src: './src',
11+
src: './src',
1312

14-
out: './build',
13+
entryFile: './index',
1514

16-
entryFile: './index',
17-
18-
/**
19-
* allowed file extensions
20-
*/
21-
extensions: ['.js', '.ts', '.jsx', '.tsx'],
15+
/**
16+
* allowed file extensions
17+
*/
18+
extensions: ['.js', '.ts', '.jsx', '.tsx'],
2219

23-
/**
24-
* boolean indicating if the interop rollup setting should be enabled
25-
*/
26-
interop: true,
20+
/**
21+
* boolean indicating if the interop rollup setting should be enabled
22+
*/
23+
interop: true,
2724

28-
/**
29-
* boolean indicating if sourcemap should be generated, can be true, false, or 'inline'
30-
*/
31-
sourcemap: true,
25+
/**
26+
* boolean indicating if sourcemap should be generated, can be true, false, or 'inline'
27+
*/
28+
sourcemap: true,
3229

33-
/**
34-
* applies to umd and iife builds
35-
*/
36-
globals: {},
30+
/**
31+
* applies to umd and iife builds
32+
*/
33+
globals: {},
3734

38-
babelPlugins: [],
35+
babelPlugins: [],
3936

40-
babelPresets: [],
37+
babelPresets: [],
4138

42-
exclude: [],
39+
exclude: [],
4340

44-
include: [],
41+
include: [],
4542

46-
plugins: [],
47-
},
43+
plugins: [],
4844

4945
/**
5046
* cjs build config

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export const createConfig = (config: Config) => {
66

77
export { Bundler } from './modules/Bundler';
88
export * from './utils/camelCase';
9-
export * from './utils/copy';
109
export * from './utils/getClosestPackageDir';
1110
export * from './utils/isCallable';
1211
export * from './utils/isObject';

0 commit comments

Comments
 (0)