Skip to content

Commit

Permalink
feat: added uglify option on all build formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Harrison Ifeanyichukwu authored and Harrison Ifeanyichukwu committed Mar 21, 2020
1 parent 3d3c943 commit 7e29189
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export interface CommonConfig {
*/
assets?: (string | RegExp)[];

/**
* boolean indicating if rollup plugin terser should be applied to the build, when in production mode
* default to false
*/
uglify?: boolean;

/**
* boolean indicating if the interop rollup setting should be enabled for the build
*/
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonConfig } from './@types';

export const COMMON_CONFIGS: (keyof CommonConfig)[] = ['sourcemap', 'interop'];
export const COMMON_CONFIGS: (keyof CommonConfig)[] = ['sourcemap', 'interop', 'uglify'];

export const REGEX_FIELDS = ['assets', 'include', 'exclude'];
6 changes: 1 addition & 5 deletions src/modules/Bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,7 @@ class Bundler {

log(chalk.yellow(`generating ${config.format} builds...\n`));

const plugins = getRollupPlugins(
this.config,
this.generalConfig,
config.format === 'esm',
);
const plugins = getRollupPlugins(mainConfig, config, this.generalConfig);
const external =
config.format === 'iife' || config.format === 'umd'
? config.externals
Expand Down
19 changes: 10 additions & 9 deletions src/modules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import commonjs from '@rollup/plugin-commonjs';
import babel from 'rollup-plugin-babel';
import json from '@rollup/plugin-json';
import { terser } from 'rollup-plugin-terser';
import { Config, GeneralConfig } from '../@types';
import { isProdEnv, getEntryPath } from '@teclone/node-utils';
import { Config, GeneralConfig, DistConfig, ESMConfig, CJSConfig } from '../@types';
import { getEntryPath } from '@teclone/node-utils';

import path from 'path';
import fs from 'fs';

Expand Down Expand Up @@ -81,14 +82,14 @@ export const getBabelPresets = (
};

export const getRollupPlugins = (
config: Config,
mainConfig: Config,
buildConfig: DistConfig | ESMConfig | CJSConfig,
generalConfig: GeneralConfig,
useESModules: boolean = false,
) => {
const internalNodeModulesDir = getEntryPath(__dirname);
return [
resolve({
extensions: config.extensions,
extensions: mainConfig.extensions,
}),

commonjs({
Expand All @@ -106,20 +107,20 @@ export const getRollupPlugins = (
plugins: getBabelPlugins(
generalConfig?.babelConfig?.plugins,
internalNodeModulesDir,
useESModules,
buildConfig.format === 'esm',
),

exclude: 'node_modules/**',

extensions: config.extensions,
extensions: mainConfig.extensions,

runtimeHelpers: true,
}),

json(),

config.uglify && isProdEnv() && terser(),
buildConfig.uglify && terser(),

...config.plugins,
...mainConfig.plugins,
];
};

0 comments on commit 7e29189

Please sign in to comment.