Skip to content

Commit

Permalink
feat: simplify configuration object
Browse files Browse the repository at this point in the history
this simplifies how to configure which build formats are enabled

BREAKING CHANGE: it changes how build formats to be generated are enabled
  • Loading branch information
Harrison Ifeanyichukwu authored and Harrison Ifeanyichukwu committed Aug 17, 2024
1 parent 1794b3c commit 5fa0454
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ It is possible to configure the build process via a config file or via cli optio
```javascript
const { createConfig } = require('@teclone/rollup-all');
module.exports = createConfig({
/**
* defines formats to build
*/
formats: ['cjs', 'es'],

/**
* defines default configurations for all build formats
*/
defaults: {
src: './src',

out: './build',

entryFile: './index',

/**
Expand Down Expand Up @@ -118,25 +124,21 @@ module.exports = createConfig({
* cjs build config
*/
cjs: {
enabled: true,
out: './build/cjs',
},

/**
* es build config
*/
es: {
enabled: true,
out: './build/es',
},

/**
* iife build config, disabled by default
*/
iife: {
enabled: true,
out: './build/iife',
src: './src',

// defines outputs
outputs: [
Expand All @@ -151,10 +153,7 @@ module.exports = createConfig({
* umd build config, disabled by default
*/
umd: {
enabled: false,
out: './build/umd',
src: './src',

// defines outputs
outputs: [
['development', 'minified'],
Expand Down Expand Up @@ -193,11 +192,11 @@ This configuration is achieved using the output option as shown below
```typescript
const { createConfig } = require('@teclone/rollup-all');
module.exports = createConfig({
formats: ['umd'],
/**
* umd build config, disabled by default
* umd build config
*/
umd: {
enabled: false,
out: './build/umd',
src: './src',

Expand Down
15 changes: 9 additions & 6 deletions src/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export type Sourcemap = true | false | 'inline';
export interface FormatConfig {
moduleName?: string;

enabled?: boolean;

src?: string;

out?: string;
Expand Down Expand Up @@ -79,14 +77,19 @@ export interface FormatConfig {
minifiedSuffix?: string | false;
}

export type Config = Partial<{
[p in BuildFormat | 'defaults']: FormatConfig;
}> & {
export type Config = {
/**
* formats to build
*/
formats?: Array<BuildFormat>;

/**
* if true, output logs are not logged
*/
silent?: boolean;
};
} & Partial<{
[p in BuildFormat | 'defaults']: FormatConfig;
}>;

export interface Module {
// id for indexing this file
Expand Down
9 changes: 2 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Config } from './@types';

export const config: Config = {
formats: ['cjs', 'es'],
defaults: {
src: './src',

out: './build',

entryFile: './index',

/**
Expand Down Expand Up @@ -43,25 +42,21 @@ export const config: Config = {
* cjs build config
*/
cjs: {
enabled: true,
out: './build/cjs',
},

/**
* es build config
*/
es: {
enabled: true,
out: './build/es',
},

/**
* iife build config, disabled by default
*/
iife: {
enabled: false,
out: './build/iife',
src: './src',

// defines outputs
outputs: [
Expand All @@ -76,7 +71,6 @@ export const config: Config = {
* umd build config, disabled by default
*/
umd: {
enabled: false,
out: './build/umd',
src: './src',

Expand All @@ -85,6 +79,7 @@ export const config: Config = {
['development', 'minified'],
['production', 'minified'],
],

minifiedSuffix: 'min',
},
};
5 changes: 1 addition & 4 deletions src/modules/Bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,8 @@ class Bundler {
async process() {
const config = this.config;

forEach(formats, async (format) => {
forEach(config.formats, async (format) => {
const formatConfig = config[format];
if (!formatConfig.enabled) {
return;
}

const modules = await this.getModules(
[],
Expand Down

0 comments on commit 5fa0454

Please sign in to comment.