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

Commit

Permalink
feat: v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Mar 16, 2022
1 parent 6976dce commit e5716ed
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

### 2.1.0 (2022-03-16)

- Add `@rollup/plugin-typescript` plugin
- Support `@rollup/plugin-json` plugin options
- Rename `minimize` to `terser`

### 2.0.0 (2022-03-16)

**Breaking Change**
Expand Down
3 changes: 2 additions & 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.1",
"version": "2.1.0",
"description": "Universal JavaScript library bundler",
"author": "Surmon",
"license": "MIT",
Expand Down Expand Up @@ -47,6 +47,7 @@
"@rollup/plugin-json": "^4.1",
"@rollup/plugin-node-resolve": "^13.1",
"@rollup/plugin-replace": "^4.0",
"@rollup/plugin-typescript": "^8.3.1",
"chalk": "^4.1.2",
"commander": "^9.0",
"consola": "^2.15",
Expand Down
31 changes: 15 additions & 16 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import buble from '@rollup/plugin-buble'
import eslint from '@rollup/plugin-eslint'
import babel from '@rollup/plugin-babel'
import postcss from 'rollup-plugin-postcss'
import { terser } from 'rollup-plugin-terser'
import typescript from '@rollup/plugin-typescript'
import ts from 'rollup-plugin-ts'
import visualizer from 'rollup-plugin-visualizer'
import typescript from 'rollup-plugin-ts'
import { terser } from 'rollup-plugin-terser'
import { TargetModuleEnum, ParserEnum } from './constant'
import { LibundlerConfigObject } from './interface'
import { logger } from './logger'
Expand Down Expand Up @@ -74,23 +75,25 @@ export const configToRollupConfig = (bundlerConfig: LibundlerConfigObject): Roll
rollupPlugins.push(eslint(bundlerConfig.eslint))
}

// ts
if (bundlerConfig.ts) {
rollupPlugins.push(ts(bundlerConfig.ts))
}

// TypeScript
if (bundlerConfig.typescript) {
rollupPlugins.push(typescript(bundlerConfig.typescript))
}

// JSON
rollupPlugins.push(json())
rollupPlugins.push(json(bundlerConfig.json))

// postcss
rollupPlugins.push(
postcss({
extract: true,
minimize: bundlerConfig.minimize,
minimize: true,
extensions: ['.css', '.styl', '.sass', '.scss', 'less'],
// namedExports(name) {
// return name
// },
...bundlerConfig.postcss,
})
)
Expand Down Expand Up @@ -135,17 +138,13 @@ export const configToRollupConfig = (bundlerConfig: LibundlerConfigObject): Roll
rollupPlugins.push(alias(bundlerConfig.alias))
}

// minimize
if (bundlerConfig.minimize) {
// terser
if (bundlerConfig.terser) {
rollupPlugins.push(
terser(
typeof bundlerConfig.minimize === 'object'
? bundlerConfig.minimize
: {
output: {
ecma: 5,
},
}
typeof bundlerConfig.terser === 'object'
? bundlerConfig.terser
: { output: { ecma: 5 } }
)
)
}
Expand Down
6 changes: 4 additions & 2 deletions src/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ export const getDefaultConfig = (): Partial<LibundlerConfigObject> => {
parser: ParserEnum.Buble,
parserOptions: {},
postcss: {},
json: {},
eslint: isEnabledESLint ? {} : false,
typescript: isEnabledTS ? {} : false,
minimize: true,
ts: isEnabledTS ? {} : false,
typescript: false,
terser: true,
visualizer: false,
verbose: false,
}
Expand Down
36 changes: 26 additions & 10 deletions src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { RollupOptions, ExternalOption, GlobalsOption, OutputOptions } from 'rollup'
import { RollupNodeResolveOptions } from '@rollup/plugin-node-resolve'
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs'
import { RollupTypescriptOptions } from '@rollup/plugin-typescript'
import { RollupAliasOptions } from '@rollup/plugin-alias'
import { RollupReplaceOptions } from '@rollup/plugin-replace'
import { RollupJsonOptions } from '@rollup/plugin-json'
import { RollupEslintOptions } from '@rollup/plugin-eslint'
import { PostCSSPluginConf } from 'rollup-plugin-postcss'
import { TypescriptPluginOptions } from 'rollup-plugin-ts'
Expand Down Expand Up @@ -114,7 +116,7 @@ export interface LibundlerConfigObject {
replace?: RollupReplaceOptions

/**
* Treating [module] as external dependency.
* Treating `[module]` as external dependency.
* @see [rollup - peer-dependencies](https://rollupjs.org/guide/en/#peer-dependencies)
* @see [rollup - warning-treating-module-as-external-dependency](https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency)
* @default []
Expand Down Expand Up @@ -146,32 +148,46 @@ export interface LibundlerConfigObject {
parserOptions?: Record<string, unknown>

/**
* postcss plugin options, defined to overwrite the default options.
* Rollup postcss plugin options, defined to overwrite the default options.
* @see [rollup-plugin-postcss](https://github.com/egoist/rollup-plugin-postcss)
* @default { ... }
* @default {}
*/
postcss?: Partial<PostCSSPluginConf>

/**
* Enable ESLint plugin (before build), `false` to disable.
* @see [@rollup/plugin-eslint](https://github.com/rollup/plugins/tree/master/packages/eslint)
* @default auto enable by `<package.json>.devDependencies`
* Rollup JSON plugin options, defined to overwrite the default options.
* @see [@rollup/plugin-json](https://github.com/rollup/plugins/tree/master/packages/json)
* @default {}
*/
eslint?: false | RollupEslintOptions
json?: RollupJsonOptions

/**
* Enable TypeScript plugin (before build), `false` to disable.
* Rollup TypeScript plugin options, `false` to disable.
* @see [@rollup/plugin-typescript](https://github.com/rollup/plugins/tree/master/packages/typescript)
* @default false
*/
typescript?: false | Partial<RollupTypescriptOptions>

/**
* Enable TS plugin (before build), `false` to disable.
* @see [rollup-plugin-ts](https://github.com/wessberg/rollup-plugin-ts)
* @default auto enable by `<package.json>.devDependencies`
*/
typescript?: false | Partial<TypescriptPluginOptions>
ts?: false | Partial<TypescriptPluginOptions>

/**
* Enable ESLint plugin (before build), `false` to disable.
* @see [@rollup/plugin-eslint](https://github.com/rollup/plugins/tree/master/packages/eslint)
* @default auto enable by `<package.json>.devDependencies`
*/
eslint?: false | RollupEslintOptions

/**
* Enable compression, use terser, `false` to disable.
* @see [rollup-plugin-terser](https://github.com/TrySound/rollup-plugin-terser)
* @default true
*/
minimize?: boolean | RollupTerserOptions
terser?: boolean | RollupTerserOptions

/**
* Visualize and analyze this bundle file, use `rollup-plugin-visualizer`, `false` to disable.
Expand Down
2 changes: 1 addition & 1 deletion tests/cjs-config/libundler.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
outFileName: 'js-lib-file',
entry: './src/index.js',
outDir: './dist',
minimize: false,
terser: false,
}
2 changes: 1 addition & 1 deletion tests/esm-config/libundler.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default {
outFileName: 'js-lib-file',
entry: './src/index.js',
outDir: './dist',
minimize: false,
terser: false,
}
2 changes: 1 addition & 1 deletion tests/react-jsx-scss/libundler.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default {
react: 'React',
'react-dom': 'ReactDOM',
},
minimize: false,
terser: false,
}
16 changes: 12 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@
"@types/buble" "^0.19.2"
buble "^0.20.0"

"@rollup/plugin-commonjs@^21.0":
version "21.0.1"
resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-21.0.1.tgz#1e57c81ae1518e4df0954d681c642e7d94588fee"
integrity sha512-EA+g22lbNJ8p5kuZJUYyhhDK7WgJckW5g4pNN7n4mAFUM96VuwUnNT3xr2Db2iCZPI1pJPbGyfT5mS9T1dHfMg==
"@rollup/plugin-commonjs@^21.0.2":
version "21.0.2"
resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-21.0.2.tgz#0b9c539aa1837c94abfaf87945838b0fc8564891"
integrity sha512-d/OmjaLVO4j/aQX69bwpWPpbvI3TJkQuxoAk7BH8ew1PyoMBLTOuvJTjzG8oEoW7drIIqB0KCJtfFLu/2GClWg==
dependencies:
"@rollup/pluginutils" "^3.1.0"
commondir "^1.0.1"
Expand Down Expand Up @@ -385,6 +385,14 @@
"@rollup/pluginutils" "^3.1.0"
magic-string "^0.25.7"

"@rollup/plugin-typescript@^8.3.1":
version "8.3.1"
resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.3.1.tgz#b7dc75ed6b4876e260b9e80624fab23bc98e4ac1"
integrity sha512-84rExe3ICUBXzqNX48WZV2Jp3OddjTMX97O2Py6D1KJaGSwWp0mDHXj+bCGNJqWHIEKDIT2U0sDjhP4czKi6cA==
dependencies:
"@rollup/pluginutils" "^3.1.0"
resolve "^1.17.0"

"@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b"
Expand Down

0 comments on commit e5716ed

Please sign in to comment.