@rollup/plugin-terser 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/dist/cjs/index.js +27 -0
- package/dist/es/index.js +22 -0
- package/dist/es/package.json +1 -0
- package/package.json +71 -0
- package/src/index.ts +24 -0
- package/types/index.d.ts +10 -0
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
[npm]: https://img.shields.io/npm/v/@rollup/plugin-terser
|
|
2
|
+
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-terser
|
|
3
|
+
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-terser
|
|
4
|
+
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-terser
|
|
5
|
+
|
|
6
|
+
[![npm][npm]][npm-url]
|
|
7
|
+
[![size][size]][size-url]
|
|
8
|
+
[](https://liberamanifesto.com)
|
|
9
|
+
|
|
10
|
+
# @rollup/plugin-terser
|
|
11
|
+
|
|
12
|
+
🍣 A Rollup plugin to generate a minified output bundle.
|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
Using npm:
|
|
21
|
+
|
|
22
|
+
```console
|
|
23
|
+
npm install @rollup/plugin-terser --save-dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import terser from '@rollup/plugin-terser';
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
input: 'src/index.js',
|
|
35
|
+
output: {
|
|
36
|
+
dir: 'output',
|
|
37
|
+
format: 'cjs'
|
|
38
|
+
},
|
|
39
|
+
plugins: [terser()]
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
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).
|
|
44
|
+
|
|
45
|
+
## Options
|
|
46
|
+
|
|
47
|
+
The plugin accepts a terser [Options](https://github.com/terser/terser#minify-options) object as input parameter,
|
|
48
|
+
to modify the default behaviour.
|
|
49
|
+
|
|
50
|
+
## Meta
|
|
51
|
+
|
|
52
|
+
[CONTRIBUTING](/.github/CONTRIBUTING.md)
|
|
53
|
+
|
|
54
|
+
[LICENSE (MIT)](/LICENSE)
|
|
55
|
+
|
|
56
|
+
## Credits
|
|
57
|
+
|
|
58
|
+
This package was originally developed by [https://github.com/TrySound](TrySound) but is not
|
|
59
|
+
maintained anymore.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var terser$1 = require('terser');
|
|
6
|
+
|
|
7
|
+
function terser(options) {
|
|
8
|
+
return {
|
|
9
|
+
name: 'terser',
|
|
10
|
+
async renderChunk(code, chunk, outputOptions) {
|
|
11
|
+
const defaultOptions = {
|
|
12
|
+
sourceMap: outputOptions.sourcemap === true || typeof outputOptions.sourcemap === 'string'
|
|
13
|
+
};
|
|
14
|
+
if (outputOptions.format === 'es') {
|
|
15
|
+
defaultOptions.module = true;
|
|
16
|
+
}
|
|
17
|
+
if (outputOptions.format === 'cjs') {
|
|
18
|
+
defaultOptions.toplevel = true;
|
|
19
|
+
}
|
|
20
|
+
return terser$1.minify(code, { ...defaultOptions, ...(options || {}) });
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.default = terser;
|
|
26
|
+
module.exports = Object.assign(exports.default, exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { minify } from 'terser';
|
|
2
|
+
|
|
3
|
+
function terser(options) {
|
|
4
|
+
return {
|
|
5
|
+
name: 'terser',
|
|
6
|
+
async renderChunk(code, chunk, outputOptions) {
|
|
7
|
+
const defaultOptions = {
|
|
8
|
+
sourceMap: outputOptions.sourcemap === true || typeof outputOptions.sourcemap === 'string'
|
|
9
|
+
};
|
|
10
|
+
if (outputOptions.format === 'es') {
|
|
11
|
+
defaultOptions.module = true;
|
|
12
|
+
}
|
|
13
|
+
if (outputOptions.format === 'cjs') {
|
|
14
|
+
defaultOptions.toplevel = true;
|
|
15
|
+
}
|
|
16
|
+
return minify(code, { ...defaultOptions, ...(options || {}) });
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { terser as default };
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rollup/plugin-terser",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Generate minified bundle",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "rollup/plugins",
|
|
11
|
+
"directory": "packages/terser"
|
|
12
|
+
},
|
|
13
|
+
"author": "Peter Placzek <peter.placzek1996@gmail.com>",
|
|
14
|
+
"homepage": "https://github.com/rollup/plugins/tree/master/packages/terser#readme",
|
|
15
|
+
"bugs": "https://github.com/rollup/plugins/issues",
|
|
16
|
+
"main": "dist/cjs/index.js",
|
|
17
|
+
"module": "dist/es/index.js",
|
|
18
|
+
"exports": {
|
|
19
|
+
"types": "./types/index.d.ts",
|
|
20
|
+
"import": "./dist/es/index.js",
|
|
21
|
+
"default": "./dist/cjs/index.js"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=14.0.0"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "rollup -c",
|
|
28
|
+
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
|
|
29
|
+
"ci:lint": "pnpm build && pnpm lint",
|
|
30
|
+
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
|
|
31
|
+
"ci:test": "pnpm test -- --verbose && pnpm test:ts",
|
|
32
|
+
"prebuild": "del-cli dist",
|
|
33
|
+
"prepare": "if [ ! -d 'dist' ]; then pnpm build; fi",
|
|
34
|
+
"prerelease": "pnpm build",
|
|
35
|
+
"pretest": "pnpm build",
|
|
36
|
+
"release": "pnpm --workspace-root plugin:release --pkg $npm_package_name",
|
|
37
|
+
"test": "ava",
|
|
38
|
+
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"!dist/**/*.map",
|
|
43
|
+
"src",
|
|
44
|
+
"types",
|
|
45
|
+
"README.md"
|
|
46
|
+
],
|
|
47
|
+
"keywords": [
|
|
48
|
+
"rollup",
|
|
49
|
+
"plugin",
|
|
50
|
+
"terser",
|
|
51
|
+
"minify",
|
|
52
|
+
"npm",
|
|
53
|
+
"modules"
|
|
54
|
+
],
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"rollup": "^2.x || ^3.x"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"rollup": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"terser": "^5.15.1"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"rollup": "^3.0.0-7",
|
|
68
|
+
"typescript": "^4.8.3"
|
|
69
|
+
},
|
|
70
|
+
"types": "./types/index.d.ts"
|
|
71
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NormalizedOutputOptions, RenderedChunk } from 'rollup';
|
|
2
|
+
import { minify, MinifyOptions } from 'terser';
|
|
3
|
+
|
|
4
|
+
export default function terser(options?: MinifyOptions) {
|
|
5
|
+
return {
|
|
6
|
+
name: 'terser',
|
|
7
|
+
|
|
8
|
+
async renderChunk(code: string, chunk: RenderedChunk, outputOptions: NormalizedOutputOptions) {
|
|
9
|
+
const defaultOptions: MinifyOptions = {
|
|
10
|
+
sourceMap: outputOptions.sourcemap === true || typeof outputOptions.sourcemap === 'string'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
if (outputOptions.format === 'es') {
|
|
14
|
+
defaultOptions.module = true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (outputOptions.format === 'cjs') {
|
|
18
|
+
defaultOptions.toplevel = true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return minify(code, { ...defaultOptions, ...(options || {}) });
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from 'rollup';
|
|
2
|
+
import { MinifyOptions } from 'terser';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A Rollup plugin to generate a minified output bundle.
|
|
6
|
+
*
|
|
7
|
+
* @param options - Plugin options.
|
|
8
|
+
* @returns Plugin instance.
|
|
9
|
+
*/
|
|
10
|
+
export default function terser(options?: MinifyOptions): Plugin;
|