Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
feat: v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Mar 16, 2022
1 parent 6cc23e0 commit 6976dce
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@surmon-china/libundler",
"version": "2.0.0",
"version": "2.0.1",
"description": "Universal JavaScript library bundler",
"author": "Surmon",
"license": "MIT",
Expand Down
12 changes: 6 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import postcss from 'rollup-plugin-postcss'
import { terser } from 'rollup-plugin-terser'
import visualizer from 'rollup-plugin-visualizer'
import typescript from 'rollup-plugin-ts'
import { TargetBundleModuleType, RollupParserType } from './constant'
import { TargetModuleEnum, ParserEnum } from './constant'
import { LibundlerConfigObject } from './interface'
import { logger } from './logger'

Expand All @@ -27,7 +27,7 @@ export const configToRollupConfig = (bundlerConfig: LibundlerConfigObject): Roll
}

/** output */
if (bundlerConfig.targets!.includes(TargetBundleModuleType.ESM)) {
if (bundlerConfig.targets!.includes(TargetModuleEnum.ESM)) {
rollupOutput.push({
banner: bundlerConfig.banner || void 0,
sourcemap: bundlerConfig.sourcemap,
Expand All @@ -37,7 +37,7 @@ export const configToRollupConfig = (bundlerConfig: LibundlerConfigObject): Roll
exports: bundlerConfig.exports,
})
}
if (bundlerConfig.targets!.includes(TargetBundleModuleType.CJS)) {
if (bundlerConfig.targets!.includes(TargetModuleEnum.CJS)) {
rollupOutput.push({
banner: bundlerConfig.banner || void 0,
sourcemap: bundlerConfig.sourcemap,
Expand All @@ -49,7 +49,7 @@ export const configToRollupConfig = (bundlerConfig: LibundlerConfigObject): Roll
globals: bundlerConfig.globals,
})
}
if (bundlerConfig.targets!.includes(TargetBundleModuleType.UMD)) {
if (bundlerConfig.targets!.includes(TargetModuleEnum.UMD)) {
rollupOutput.push({
banner: bundlerConfig.banner || void 0,
sourcemap: bundlerConfig.sourcemap,
Expand Down Expand Up @@ -97,7 +97,7 @@ export const configToRollupConfig = (bundlerConfig: LibundlerConfigObject): Roll

// parser
if (bundlerConfig.parser) {
if (bundlerConfig.parser === RollupParserType.Babel) {
if (bundlerConfig.parser === ParserEnum.Babel) {
rollupPlugins.push(
babel(
bundlerConfig.parserOptions || {
Expand All @@ -108,7 +108,7 @@ export const configToRollupConfig = (bundlerConfig: LibundlerConfigObject): Roll
}
)
)
} else if (bundlerConfig.parser === RollupParserType.Buble) {
} else if (bundlerConfig.parser === ParserEnum.Buble) {
rollupPlugins.push(
// https://buble.surge.sh/guide/
buble(
Expand Down
6 changes: 4 additions & 2 deletions src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ export const LIB_NAME = 'libundler'
export const LIB_CONFIG_FILE_NAME = 'libundler.config'
export const LIB_PACKAGE_JSON = require(path.resolve(__dirname, '..', 'package.json'))

export const enum TargetBundleModuleType {
export type TargetModuleType = 'umd' | 'cjs' | 'esm'
export const enum TargetModuleEnum {
UMD = 'umd',
CJS = 'cjs',
ESM = 'esm',
}

export const enum RollupParserType {
export type ParserType = 'babel' | 'buble'
export const enum ParserEnum {
Babel = 'babel',
Buble = 'buble',
}
10 changes: 3 additions & 7 deletions src/default.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TargetBundleModuleType, RollupParserType } from './constant'
import { TargetModuleEnum, ParserEnum } from './constant'
import { LibundlerConfigObject } from './interface'
import { getDefaultBanner } from './banner'
import { pascalify, kebabcase, loadProjectFile } from './utils'
Expand Down Expand Up @@ -43,11 +43,7 @@ export const getDefaultConfig = (): Partial<LibundlerConfigObject> => {
outDir: 'dist',
banner,
sourcemap: true,
targets: [
TargetBundleModuleType.ESM,
TargetBundleModuleType.UMD,
TargetBundleModuleType.CJS,
],
targets: [TargetModuleEnum.ESM, TargetModuleEnum.UMD, TargetModuleEnum.CJS],
exports: 'auto',
commonjs: {
// https://github.com/rollup/plugins/tree/master/packages/node-resolve#extensions
Expand All @@ -64,7 +60,7 @@ export const getDefaultConfig = (): Partial<LibundlerConfigObject> => {
},
external: [],
globals: {},
parser: RollupParserType.Buble,
parser: ParserEnum.Buble,
parserOptions: {},
postcss: {},
eslint: isEnabledESLint ? {} : false,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { getDefaultConfig } from './default'
import { configToRollupConfig } from './config'
import { logger, br, dir, yellow } from './logger'

export * from './interface'
export { configToRollupConfig } from './config'
export * from './interface'

export const bundle = (bundlerConfig?: LibundlerConfig) => {
// config
Expand Down
6 changes: 3 additions & 3 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PostCSSPluginConf } from 'rollup-plugin-postcss'
import { TypescriptPluginOptions } from 'rollup-plugin-ts'
import { Options as RollupTerserOptions } from 'rollup-plugin-terser'
import { PluginVisualizerOptions } from 'rollup-plugin-visualizer'
import { TargetBundleModuleType, RollupParserType } from './constant'
import { TargetModuleType, ParserType } from './constant'

/**
* Type helper to make it easier to use libundler.config.ts
Expand Down Expand Up @@ -70,7 +70,7 @@ export interface LibundlerConfigObject {
* @type `TargetBundleModuleType`
* @default ['umd', 'esm', 'cjs']
*/
targets?: TargetBundleModuleType[]
targets?: TargetModuleType[]

/**
* Bundle file export mode.
Expand Down Expand Up @@ -133,7 +133,7 @@ export interface LibundlerConfigObject {
* @type `false` | `'babel'` | `'buble'`
* @default 'buble'
*/
parser?: false | RollupParserType
parser?: false | ParserType

/**
* Rollup parser plugin options.
Expand Down
1 change: 1 addition & 0 deletions tests/typescript/libundler.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { defineConfig } from '../../lib'
export default defineConfig({
libName: 'TsLib',
eslint: false,
targets: ['esm', 'cjs'],
})

0 comments on commit 6976dce

Please sign in to comment.