Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from UmamiAppearance/v0.2.0
Browse files Browse the repository at this point in the history
V0.2.0
  • Loading branch information
UmamiAppearance authored Oct 22, 2022
2 parents 59ac671 + 7516795 commit 749bd51
Show file tree
Hide file tree
Showing 6 changed files with 551 additions and 572 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# rollup-plugin-minification

Right now this is an emergency replacement for [rollup-plugin-terser](https://github.com/TrySound/rollup-plugin-terser) which is currently not in active development. As the name _minification_ suggests this plugin will not be bound to terser. If it will be necessary to replace the underlying minification (which will not be the case as long as terser is in active development), the more generic name of this plugin makes it possible to do that without producing a misleading name.
This is an emergency replacement for [rollup-plugin-terser](https://github.com/TrySound/rollup-plugin-terser) which is currently not in active development.

The next steps will be to turn this into a real plugin while keeping it compatible with **rollup-plugin-terser**.
There is an official solution for the terser plugin on the way, as it is going to be part of the [rollup plugins repository](https://github.com/rollup/plugins). Until it is available you can use this plugin as a 1:1 replacement for **rollup-plugin-terser**.

## Installation
```console
Expand Down
81 changes: 67 additions & 14 deletions cjs/minify.cjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,73 @@
'use strict';

var terser$1 = require('terser');
var rollupPluginYourFunction = require('rollup-plugin-your-function');

const terser = () => rollupPluginYourFunction.yourFunction({
output: true,
name: "terser",
fn: async (source, options) => terser$1.minify(
source,
{
module: (/^esm?$/).test(options.outputOptions.format),
toplevel: options.outputOptions.format === "cjs",
sourceMap: true
}
)
});

/**
* [rollup-plugin-minification]{@link https://github.com/UmamiAppearance/minification}
*
* @version 0.2.0
* @author UmamiAppearance [mail@umamiappearance.eu]
* @license MIT
*/

const terser = (options={}) => {

return {
name: "minification",

async renderChunk(code, chunk, outputOptions) {

const defaultOptions = {
sourceMap:
Boolean(outputOptions.sourcemap) ||
Boolean(outputOptions.sourceMap),
module:
(/^esm?$/).test(outputOptions.format),
toplevel:
outputOptions.format === "cjs"
};

options = {
...defaultOptions,
...options
};

const result = await terser$1.minify(
code,
options
);

if (result.nameCache) {
let { vars, props } = options.nameCache;

// only assign nameCache.vars if it was provided, and if terser produced values:
if (vars) {
const newVars = result.nameCache.vars && result.nameCache.vars.props;
if (newVars) {
vars.props = vars.props || {};
Object.assign(vars.props, newVars);
}
}

// support populating an empty nameCache object:
if (!props) {
props = options.nameCache.props = {};
}

// merge updated props into original nameCache object:
const newProps =
result.nameCache.props && result.nameCache.props.props;
if (newProps) {
props.props = props.props || {};
Object.assign(props.props, newProps);
}
}

return result.code;
},
};

};

exports.terser = terser;
//# sourceMappingURL=minify.cjs.map
2 changes: 1 addition & 1 deletion cjs/minify.cjs.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 749bd51

Please sign in to comment.