Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ coverage
.test_gen_*
lib/
*.log
packages/babel-minify-standalone/babel-minify\.min\.js
packages/babel-minify-standalone/babel-minify\.js
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ node_js:
- '4'

before_script:
- yarn run bootstrap && yarn run build
- yarn run bootstrap && yarn run build && yarn run build-standalone

script:
- if [ -n "${LINT-}" ]; then yarn run lint ; fi
Expand Down
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"bootstrap": "lerna bootstrap",
"build": "gulp build",
"build-standalone": "gulp build-babel-minify-standalone --cwd=packages/babel-minify-standalone/",
"changelog": "lerna-changelog",
"clean": "lerna clean",
"coverage": "jest --coverage",
Expand All @@ -17,17 +18,19 @@
"publish": "git pull origin master --rebase && npm run build && npm test && lerna publish",
"publish-internal": "git pull origin master --rebase && npm run build && NPM_DIST_TAG=internal ./node_modules/.bin/lerna publish --skip-git",
"test": "jest",
"test-ci": "npm run bootstrap && npm run build && npm run coverage",
"test-ci": "npm run bootstrap && npm run build && npm run build-standalone && npm run coverage",
"updated": "lerna updated",
"watch": "gulp watch"
},
"devDependencies": {
"babel-core": "^6.25.0",
"babel-core": "^7.0.0-alpha.19",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an important/required change for including babel-minify-standalone ?

If so, then all the plugin and preset tests will run on babel7 instead of babel6, and almost everyone using this minifier would be using it with babel6.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some build errors with 6.x. I can try again and see if I can get it working. I think it was because the latest babel-standalone versions reference babel-core 7.x.

Is there a branch of babel-minify for Babel 7.x builds?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a open PR for babel 7 upgrade here #487

"babel-eslint": "^7.2.3",
"babel-jest": "^20.0.3",
"babel-plugin-transform-es2015-block-scoping": "^6.24.1",
"babel-loader": "^7.1.2",
"babel-plugin-transform-es2015-block-scoping": "^7.0.0-alpha.19",
"babel-preset-env": "^1.6.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2015": "^7.0.0-alpha.19",
"babel-preset-stage-0": "^7.0.0-alpha.19",
"babel-traverse": "^6.25.0",
"butternut": "^0.4.6",
"bytes": "^2.5.0",
Expand All @@ -36,22 +39,29 @@
"closure-compiler": "^0.2.12",
"codecov": "^2.3.0",
"commander": "^2.11.0",
"enhanced-resolve": "^3.4.1",
"eslint": "^4.4.0",
"fs-readdir-recursive": "^1.0.0",
"google-closure-compiler-js": "^20170626.0.0",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-babel": "^6.1.2",
"gulp-newer": "^1.3.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^3.0.0",
"gulp-util": "^3.0.8",
"jest-cli": "^20.0.4",
"lerna": "^2.0.0",
"lerna-changelog": "^0.6.0",
"markdown-table": "^1.1.1",
"prettier": "^1.5.3",
"pump": "^1.0.2",
"request": "^2.81.0",
"rimraf": "^2.6.1",
"through2": "^2.0.3",
"uglify-js": "^3.0.27"
"uglify-js": "^3.0.27",
"webpack": "^3.5.5",
"webpack-dependency-suite": "^2.4.5",
"webpack-stream": "^4.0.0"
},
"private": true,
"jest": {
Expand Down
6 changes: 6 additions & 0 deletions packages/babel-minify-standalone/Gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const registerBabelStandaloneTask = require("babel-standalone/src/gulpTasks")
.registerBabelStandaloneTask;
const gulp = require("gulp");

const version = require("./package.json").version;
registerBabelStandaloneTask(gulp, "babel-minify", "BabelMinify", __dirname, version);
37 changes: 37 additions & 0 deletions packages/babel-minify-standalone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
babel-minify-standalone
=======================

babel-minify-standalone is a standalone build of [babel-minify](https://github.com/babel/minify) for use in non-Node.js environments, including browsers.

But why?!
=========

It's true that using Babel (and babel-minify) through Webpack, Browserify or Gulp should be sufficient for most use cases. However, there are some valid use cases for babel-standalone:

- Sites like [JSFiddle](https://jsfiddle.net/), [JS Bin](https://jsbin.com/), the [REPL on the Babel site](http://babeljs.io/repl/), etc. These sites compile user-provided JavaScript in real-time, and babel-minify could be used to provide on-the-fly minification and related statistics,
- Apps that embed a JavaScript engine such as V8 directly, and want to use Babel for compilation and minification
- Apps that want to use JavaScript as a scripting language for extending the app itself, including all the goodies that ES2015 provides.
- Integration of Babel into a non-Node.js environment ([ReactJS.NET](http://reactjs.net/), [ruby-babel-transpiler](https://github.com/babel/ruby-babel-transpiler), [php-babel-transpiler](https://github.com/talyssonoc/php-babel-transpiler), etc).

Installation
============

There are several ways to get a copy of babel-minify. Pick whichever one you like:

- Use it via Unpkg: https://unpkg.com/babel-minify-standalone@0.x/babel-minify.min.js. This is a simple way to embed it on a webpage without having to do any other setup.
- Install via Bower: `bower install babili-standalone`
- Install via NPM: `npm install --save babel-minify`
- Manually grab `babel-minify.js` and/or `babel-minify.min.js` from the [GitHub releases page](https://github.com/Daniel15/babel-standalone/releases). Every release includes these files.

Usage
=====

Load `babel-minify.js` or `babel-minify.min.js` in your environment, **along with Babel-standalone**. This is important: You need to load Babel too!

This will load babel-minify's Babel plugins and preset, and expose a simple API in a `BabelMinify` object:

```js
var input = 'class Foo { constructor(bar) { this.bar = bar } }; new Foo()';
var output = BabelMinify.transform(input).code;
// class a{constructor(b){this.bar=b}};new a;
```
1 change: 1 addition & 0 deletions packages/babel-minify-standalone/__mocks__/Babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('babel-standalone');
16 changes: 16 additions & 0 deletions packages/babel-minify-standalone/__tests__/babel-minify-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const BabelMinify = require('../babel-minify');

// Basic smoke tests for babel-minify-standalone
describe('babel-minify-standalone', () => {
it('works', () => {
const output = BabelMinify.transform(
`
class Mangler {
constructor(program) {
this.program = program;
}
}
new Mangler();`).code;
expect(output).toBe('class Mangler{constructor(a){this.program=a}}new Mangler;');
});
});
42 changes: 42 additions & 0 deletions packages/babel-minify-standalone/examples/example.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the file extension is missing l for html.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's consistent with babel-standalone: https://github.com/babel/babel/blob/7.0/packages/babel-standalone/examples/example.htm

Should I change both?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I thought this extension was dead long before. Its totally up to you :)

<html>
<head>
<meta charset="utf-8" />
<title>babel-minify-standalone example</title>
</head>
<body>
Input:
<textarea id="input" style="width: 100%" rows="10">
// Example ES2015 Code
class Mangler {
constructor(program) {
this.program = program;
}
}
new Mangler();
</textarea>

Transformed code using babel-minify <strong id="version"></strong>:
<pre id="output">Loading...</pre>

<script src="https://unpkg.com/babel-standalone@7.0.0-alpha.19/babel.min.js"></script>
<script src="../babel-minify.js"></script>
<script>
console.log('Babel =', Babel);
console.log('Babel-Minify =', BabelMinify);
var inputEl = document.getElementById('input');
var outputEl = document.getElementById('output');

function transform() {
try {
outputEl.innerHTML = BabelMinify.transform(inputEl.value).code;
} catch (ex) {
outputEl.innerHTML = 'ERROR: ' + ex.message;
}
}

inputEl.addEventListener('keyup', transform, false);
transform();
</script>
</body>
</html>
58 changes: 58 additions & 0 deletions packages/babel-minify-standalone/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "babel-minify-standalone",
"version": "0.2.0",
"description": "Standalone build of Babili (babel-minify) for use in non-Node.js environments",
"main": "babili.js",
"files": [
"babili.js",
"babili.min.js",
"src"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Daniel15/babel-standalone.git"
},
"keywords": [
"babel-preset",
"babel-standalone",
"babel",
"6to5",
"minify",
"uglify"
],
"author": "Daniel Lo Nigro <daniel@dan.cx> (http://dan.cx/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/Daniel15/babel-standalone/issues"
},
"homepage": "https://dl.vc/babili-standalone",
"devDependencies": {
"babel-core": "^7.0.0-alpha.19",
"babel-plugin-minify-builtins": "0.2.0",
"babel-plugin-minify-constant-folding": "0.2.0",
"babel-plugin-minify-dead-code-elimination": "0.2.0",
"babel-plugin-minify-flip-comparisons": "0.2.0",
"babel-plugin-minify-guarded-expressions": "0.2.0",
"babel-plugin-minify-infinity": "0.2.0",
"babel-plugin-minify-mangle-names": "0.2.0",
"babel-plugin-minify-numeric-literals": "0.2.0",
"babel-plugin-minify-replace": "0.2.0",
"babel-plugin-minify-simplify": "0.2.0",
"babel-plugin-minify-type-constructors": "0.2.0",
"babel-plugin-transform-inline-consecutive-adds": "0.2.0",
"babel-plugin-transform-inline-environment-variables": "0.2.0",
"babel-plugin-transform-member-expression-literals": "6.8.5",
"babel-plugin-transform-merge-sibling-variables": "6.8.6",
"babel-plugin-transform-minify-booleans": "6.8.3",
"babel-plugin-transform-node-env-inline": "0.2.0",
"babel-plugin-transform-property-literals": "6.8.5",
"babel-plugin-transform-regexp-constructors": "0.2.0",
"babel-plugin-transform-remove-console": "6.8.5",
"babel-plugin-transform-remove-debugger": "6.8.5",
"babel-plugin-transform-remove-undefined": "0.2.0",
"babel-plugin-transform-simplify-comparison-operators": "6.8.5",
"babel-plugin-transform-undefined-to-void": "6.8.3",
"babel-preset-minify": "0.2.0",
"babel-standalone": "7.0.0-alpha.19"
}
}
42 changes: 42 additions & 0 deletions packages/babel-minify-standalone/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
registerPlugins,
registerPreset,
transform as babelTransform,
} from 'babel-standalone';

registerPlugins({
'minify-constant-folding': require('babel-plugin-minify-constant-folding'),
'minify-dead-code-elimination': require('babel-plugin-minify-dead-code-elimination'),
'minify-flip-comparisons': require('babel-plugin-minify-flip-comparisons'),
'minify-guarded-expressions': require('babel-plugin-minify-guarded-expressions'),
'minify-infinity': require('babel-plugin-minify-infinity'),
'minify-mangle-names': require('babel-plugin-minify-mangle-names'),
'minify-replace': require('babel-plugin-minify-replace'),
'minify-simplify': require('babel-plugin-minify-simplify'),
'minify-type-constructors': require('babel-plugin-minify-type-constructors'),
'transform-inline-environment-variables': require('babel-plugin-transform-inline-environment-variables'),
'transform-member-expression-literals': require('babel-plugin-transform-member-expression-literals'),
'transform-merge-sibling-variables': require('babel-plugin-transform-merge-sibling-variables'),
'transform-minify-booleans': require('babel-plugin-transform-minify-booleans'),
'transform-node-env-inline': require('babel-plugin-transform-node-env-inline'),
'transform-property-literals': require('babel-plugin-transform-property-literals'),
'transform-remove-console': require('babel-plugin-transform-remove-console'),
'transform-remove-debugger': require('babel-plugin-transform-remove-debugger'),
'transform-simplify-comparison-operators': require('babel-plugin-transform-simplify-comparison-operators'),
'transform-undefined-to-void': require('babel-plugin-transform-undefined-to-void'),
});
registerPreset('minify', require('babel-preset-minify'));

export function transform(code, options = {}) {
return babelTransform(code, Object.assign(
{},
options,
{
presets: [
...(options.presets || []),
'minify',
]
}));
}

export const version = VERSION;
Loading