Skip to content

Commit

Permalink
move core-js bundle to a separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 9, 2018
1 parent 2fc583b commit 07128c8
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
/packages/core-js/bundles/
/packages/core-js-bundle/
/packages/core-js-pure/override/
/tests/bundles/
!**/.eslintrc.js
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ node_modules/
*.bak
*.swp

/packages/core-js/bundles/
/packages/core-js-bundle/LICENSE
/packages/core-js-bundle/index.js
/packages/core-js-bundle/minified.js
/packages/core-js-bundle/minified.js.map
/packages/core-js/LICENSE
/packages/core-js-pure/es/
/packages/core-js-pure/features/
Expand Down
18 changes: 15 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = grunt => {
uglify: {
build: {
files: {
'./packages/core-js/bundles/core.js.min.js': './packages/core-js/bundles/core.js',
'./packages/core-js-bundle/minified.js': './packages/core-js-bundle/index.js',
},
options: {
mangle: {
Expand Down Expand Up @@ -50,6 +50,9 @@ module.exports = grunt => {
'core-js-builder': [
'./packages/core-js-builder/LICENSE',
],
'core-js-bundle': [
'./packages/core-js/LICENSE',
],
tests: [
'./tests/bundles/*',
],
Expand Down Expand Up @@ -92,6 +95,15 @@ module.exports = grunt => {
},
],
},
'core-js-bundle': {
files: [
{
expand: true,
src: ['LICENSE'],
dest: './packages/core-js-builder/',
},
],
},
},
karma: {
options: {
Expand All @@ -102,7 +114,7 @@ module.exports = grunt => {
},
tests: {
files: [
'packages/core-js/bundles/core.js',
'packages/core-js-bundle/index.js',
'tests/bundles/qunit-helpers.js',
'tests/bundles/tests.js',
].map(it => ({ src: it })),
Expand All @@ -121,7 +133,7 @@ module.exports = grunt => {
build({
modules: ['es', 'esnext', 'web'],
}).then(it => {
const filename = './packages/core-js/bundles/core.js';
const filename = './packages/core-js-bundle/index.js';
mkdirp.sync(path.dirname(filename));
fs.writeFile(filename, it, done);
}).catch(it => {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ npm i core-js
// Include all polyfills
require('core-js');
```
If you need already bundled version of `core-js`, use `core-js/bundles/core.js` or `core-js/bundles/core.min.js` from `npm` package.
If you need already bundled version of `core-js`, use `core-js-bundle` `npm` package or a [version of this package from CDN](https://unpkg.com/core-js[email protected]) ([minified version](https://unpkg.com/core[email protected]/minified.js)).

Warning: if you use `core-js` with the extension of native objects, require all needed `core-js` modules at the top of entry point of your application, otherwise, you can have conflicts.
Warning: if you use `core-js` with the extension of native objects, load all `core-js` modules at the top of entry point of your application, otherwise, you can have conflicts.

### CommonJS
You can require only needed modules, like in examples in examples at the top of `README.md`. Available entry points for methods / constructors and namespaces: for example, `core-js/es/array` (`core-js-pure/es/array`) contains all [ES `Array` features](#ecmascript-array), `core-js/es` (`core-js-pure/es`) contains all ES features.
Expand Down
5 changes: 5 additions & 0 deletions packages/core-js-bundle/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
index.js
minified.js
minified.js,map
*.log
.*
38 changes: 38 additions & 0 deletions packages/core-js-bundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# core-js

Modular standard library for JavaScript. Includes polyfills for [ECMAScript 5, 2015, 2016, 2017](https://github.com/zloirock/core-js#ecmascript): [promises](https://github.com/zloirock/core-js#ecmascript-promise), [symbols](https://github.com/zloirock/core-js#ecmascript-symbol), [collections](https://github.com/zloirock/core-js#ecmascript-collections), iterators, [typed arrays](https://github.com/zloirock/core-js#ecmascript-typed-arrays), many other features, [ECMAScript proposals](https://github.com/zloirock/core-js#ecmascript-proposals), [some cross-platform WHATWG / W3C ECMAScript-related features and proposals](https://github.com/zloirock/core-js#web-standards) like [setImmediate](https://github.com/zloirock/core-js#setimmediate). You can load only required features or use it without global namespace pollution.

[*Example*](http://goo.gl/a2xexl):
```js
import 'core-js'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, [2, 3], [4, [5]]].flatten(2); // => [1, 2, 3, 4, 5]
Promise.resolve(32).then(x => console.log(x)); // => 32
```

*You can load only required features*:
```js
import 'core-js/features/array/from'; // <- at the top of your entry point
import 'core-js/features/array/flatten'; // <- at the top of your entry point
import 'core-js/features/set'; // <- at the top of your entry point
import 'core-js/features/promise'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
[1, [2, 3], [4, [5]]].flatten(2); // => [1, 2, 3, 4, 5]
Promise.resolve(32).then(x => console.log(x)); // => 32
```

*Or use it without global namespace pollution*:
```js
import from from 'core-js-pure/features/array/from';
import flatten from 'core-js-pure/features/array/flatten';
import Set from 'core-js-pure/features/set';
import Promise from 'core-js-pure/features/promise';

from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
flatten([1, [2, 3], [4, [5]]], 2); // => [1, 2, 3, 4, 5]
Promise.resolve(32).then(x => console.log(x)); // => 32
```

**It's a bundled global version, for more info see [`core-js` documentation](https://github.com/zloirock/core-js/blob/v3/README.md).**
40 changes: 40 additions & 0 deletions packages/core-js-bundle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "core-js-bundle",
"description": "Standard library",
"version": "3.0.0-alpha.1",
"repository": {
"type": "git",
"url": "https://github.com/zloirock/core-js.git"
},
"main": "index.js",
"license": "MIT",
"keywords": [
"ES3",
"ES5",
"ES6",
"ES7",
"ES2015",
"ES2016",
"ES2017",
"ECMAScript 3",
"ECMAScript 5",
"ECMAScript 6",
"ECMAScript 7",
"ECMAScript 2015",
"ECMAScript 2016",
"ECMAScript 2017",
"Harmony",
"Strawman",
"Map",
"Set",
"WeakMap",
"WeakSet",
"Promise",
"Symbol",
"TypedArray",
"setImmediate",
"Dict",
"polyfill",
"shim"
]
}
2 changes: 1 addition & 1 deletion tests/promises-aplus.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>
<body>
<div id="mocha"></div>
<script src="../packages/core-js/bundles/core.js"></script>
<script src="../packages/core-js-bundle/index.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js"></script>
<script>
mocha.setup({ ui: "bdd", timeout: 1e3, slow: Infinity });
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<div id='qunit'></div>
<div id='qunit-fixture'></div>
<script src='https://code.jquery.com/qunit/qunit-1.23.1.js'></script>
<script src='../packages/core-js/bundles/core.js'></script>
<script src='../packages/core-js-bundle/index.js'></script>
<script src='./bundles/qunit-helpers.js'></script>
<script src='./bundles/tests.js'></script>
2 changes: 1 addition & 1 deletion tests/worker/runner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
importScripts('../../packages/core-js/bundles/core.js');
importScripts('../../packages/core-js-bundle/index.js');

postMessage(typeof core !== 'undefined');

Expand Down

0 comments on commit 07128c8

Please sign in to comment.