-
-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(terser): initial release (#1323)
* build(terser): add terser plugin to collection * build(terser): add README.md notice * fix(terser): test-suite + rollup plugin definition * style(terser): applied prettier rules * style(terser): apply prettier on root README.md + minor eslint fixes * test(terser): removed snapshot test due incorrect path with ava
- Loading branch information
Showing
21 changed files
with
600 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
[npm]: https://img.shields.io/npm/v/@rollup/plugin-terser | ||
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-terser | ||
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-terser | ||
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-terser | ||
|
||
[![npm][npm]][npm-url] | ||
[![size][size]][size-url] | ||
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com) | ||
|
||
# @rollup/plugin-terser | ||
|
||
🍣 A Rollup plugin to generate a minified output bundle. | ||
|
||
## Requirements | ||
|
||
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```console | ||
npm install @rollup/plugin-terser --save-dev | ||
``` | ||
|
||
## Usage | ||
|
||
Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin: | ||
|
||
```js | ||
import terser from '@rollup/plugin-terser'; | ||
|
||
export default { | ||
input: 'src/index.js', | ||
output: { | ||
dir: 'output', | ||
format: 'cjs' | ||
}, | ||
plugins: [terser()] | ||
}; | ||
``` | ||
|
||
Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api). | ||
|
||
## Options | ||
|
||
The plugin accepts a terser [Options](https://github.com/terser/terser#minify-options) object as input parameter, | ||
to modify the default behaviour. | ||
|
||
## Meta | ||
|
||
[CONTRIBUTING](/.github/CONTRIBUTING.md) | ||
|
||
[LICENSE (MIT)](/LICENSE) | ||
|
||
## Credits | ||
|
||
This package was originally developed by [https://github.com/TrySound](TrySound) but is not | ||
maintained anymore. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"name": "@rollup/plugin-terser", | ||
"version": "0.0.0", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "Generate minified bundle", | ||
"license": "MIT", | ||
"repository": { | ||
"url": "rollup/plugins", | ||
"directory": "packages/terser" | ||
}, | ||
"author": "Peter Placzek <peter.placzek1996@gmail.com>", | ||
"homepage": "https://github.com/rollup/plugins/tree/master/packages/terser#readme", | ||
"bugs": "https://github.com/rollup/plugins/issues", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/es/index.js", | ||
"exports": { | ||
"types": "./types/index.d.ts", | ||
"import": "./dist/es/index.js", | ||
"default": "./dist/cjs/index.js" | ||
}, | ||
"engines": { | ||
"node": ">=14.0.0" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov", | ||
"ci:lint": "pnpm build && pnpm lint", | ||
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", | ||
"ci:test": "pnpm test -- --verbose && pnpm test:ts", | ||
"prebuild": "del-cli dist", | ||
"prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", | ||
"prerelease": "pnpm build", | ||
"pretest": "pnpm build", | ||
"release": "pnpm --workspace-root plugin:terser --pkg $npm_package_name", | ||
"test": "ava", | ||
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit" | ||
}, | ||
"files": [ | ||
"dist", | ||
"!dist/**/*.map", | ||
"src", | ||
"types", | ||
"README.md" | ||
], | ||
"keywords": [ | ||
"rollup", | ||
"plugin", | ||
"terser", | ||
"minify", | ||
"npm", | ||
"modules" | ||
], | ||
"peerDependencies": { | ||
"rollup": "^2.x || ^3.x" | ||
}, | ||
"peerDependenciesMeta": { | ||
"rollup": { | ||
"optional": true | ||
} | ||
}, | ||
"dependencies": { | ||
"terser": "^5.15.1" | ||
}, | ||
"devDependencies": { | ||
"rollup": "^3.0.0-7", | ||
"typescript": "^4.8.3" | ||
}, | ||
"types": "./types/index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { readFileSync } from 'fs'; | ||
|
||
import { createConfig } from '../../shared/rollup.config.mjs'; | ||
|
||
export default { | ||
...createConfig({ | ||
pkg: JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')) | ||
}), | ||
input: 'src/index.ts' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NormalizedOutputOptions, RenderedChunk } from 'rollup'; | ||
import { minify, MinifyOptions } from 'terser'; | ||
|
||
export default function terser(options?: MinifyOptions) { | ||
return { | ||
name: 'terser', | ||
|
||
async renderChunk(code: string, chunk: RenderedChunk, outputOptions: NormalizedOutputOptions) { | ||
const defaultOptions: MinifyOptions = { | ||
sourceMap: outputOptions.sourcemap === true || typeof outputOptions.sourcemap === 'string' | ||
}; | ||
|
||
if (outputOptions.format === 'es') { | ||
defaultOptions.module = true; | ||
} | ||
|
||
if (outputOptions.format === 'cjs') { | ||
defaultOptions.toplevel = true; | ||
} | ||
|
||
return minify(code, { ...defaultOptions, ...(options || {}) }); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const chunk1 = 'chunk-1'; | ||
console.log(chunk1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const chunk2 = 'chunk-2'; | ||
console.log(chunk2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// eslint-disable-next-line no-undef | ||
window.a = 5; | ||
|
||
/* @preserve this comment */ | ||
|
||
/* delete this comment */ | ||
|
||
// and this one too | ||
|
||
// eslint-disable-next-line no-undef | ||
if (window.a < 3) { | ||
console.log(4); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const a = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
const foo = 'bar'; | ||
console.log(foo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function recurse(count) { | ||
if (count > 0) return recurse(count - 1); | ||
return count; | ||
} | ||
const obj = { | ||
foo: 1, | ||
_priv: 2 | ||
}; | ||
console.log(obj, recurse(10)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const obj = { | ||
foo: 1, | ||
_priv: 2 | ||
}; | ||
console.log(obj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import result from './export-number.js'; | ||
|
||
console.log(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// eslint-disable-next-line no-undef | ||
window.a = 5; | ||
|
||
// eslint-disable-next-line no-undef | ||
if (window.a < 3) { | ||
console.log(4); | ||
} |
Oops, something went wrong.