Skip to content

Commit 70663cc

Browse files
Jasper De Moordevongovett
authored andcommitted
Change to uglify es & output uglify errors (#157)
* uglify-es * fix error handling * dump estree, enables ES6+ support * fix comment * change comment to match npm package name * remove useless comment * remove unused imports, change asset.generate to babel generate * improve minify options * fix comment * remove unused import * pivot back to asset.generate().js
1 parent 0479dee commit 70663cc

6 files changed

Lines changed: 81 additions & 75 deletions

File tree

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
## Features
1616

17-
- 🚀 **Blazing fast** bundle times - multicore compilation, and a filesystem cache for fast rebuilds even after a restart.
18-
- 📦 Out of the box support for JS, CSS, HTML, file assets, and more - **no plugins to install**.
19-
- 🐠 **Automatically transforms modules** using Babel, PostCSS, and PostHTML when needed - even `node_modules`.
20-
- ✂️ Zero configuration **code splitting** using dynamic `import()` statements.
21-
- 🔥 Built in support for **hot module replacement**
22-
- 🚨 Friendly error logging experience - syntax highlighted code frames help pinpoint the problem.
17+
* 🚀 **Blazing fast** bundle times - multicore compilation, and a filesystem cache for fast rebuilds even after a restart.
18+
* 📦 Out of the box support for JS, CSS, HTML, file assets, and more - **no plugins to install**.
19+
* 🐠 **Automatically transforms modules** using Babel, PostCSS, and PostHTML when needed - even `node_modules`.
20+
* ✂️ Zero configuration **code splitting** using dynamic `import()` statements.
21+
* 🔥 Built in support for **hot module replacement**
22+
* 🚨 Friendly error logging experience - syntax highlighted code frames help pinpoint the problem.
2323

2424
## Getting started
2525

@@ -74,7 +74,7 @@ Finally, existing bundlers are built around string loaders/transforms, where the
7474

7575
`parcel` transforms a tree of assets to a tree of bundles. Many other bundlers are fundamentally based around JavaScript assets, with other formats tacked on - for example, by default inlined as strings into JS files. `parcel` is file-type agnostic - it will work with any type of assets the way you'd expect, with no configuration.
7676

77-
`parcel` takes as input a single entry asset, which could be any type: a JS file, HTML, CSS, image, etc. There are various asset types defined in `parcel` which know how to handle specific file types. The assets are parsed, their dependencies are extracted, and they are transformed to their final compiled form. This creates a tree of assets.
77+
`parcel` takes as input a single entry asset, which could be any type: a JS file, HTML, CSS, image, etc. There are various asset types defined in `parcel` which know how to handle specific file types. The assets are parsed, their dependencies are extracted, and they are transformed to their final compiled form. This creates a tree of assets.
7878

7979
Once the asset tree has been constructed, the assets are placed into a bundle tree. A bundle is created for the entry asset, and child bundles are created for dynamic imports, which cause code splitting to occur. Child bundles are also created when assets of a different type are imported, for example if you imported a CSS file from JavaScript, it would be placed into a sibling bundle to the corresponding JavaScript. If an asset is required in more than one bundle, it is hoisted up to the nearest common ancestor in the bundle tree so it is not included more than once.
8080

@@ -84,10 +84,9 @@ After the bundle tree is constructed, each bundle is written to a file by a pack
8484

8585
All feedback and suggestions are welcome!
8686

87-
- 💬 Chat: Join us on [slack](https://slack.parceljs.org/).
88-
- 📣 Stay up to date on new features and announcements on [@parceljs](https://twitter.com/parceljs).
87+
* 💬 Chat: Join us on [slack](https://slack.parceljs.org/).
88+
* 📣 Stay up to date on new features and announcements on [@parceljs](https://twitter.com/parceljs).
8989

9090
## License
9191

9292
MIT
93-

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"babel-core": "^6.25.0",
1212
"babel-generator": "^6.25.0",
1313
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
14-
"babel-to-estree": "^0.0.3",
1514
"babylon": "^6.17.4",
1615
"babylon-walk": "^1.0.2",
1716
"browser-resolve": "^1.11.2",
@@ -34,8 +33,8 @@
3433
"posthtml": "^0.10.1",
3534
"resolve": "^1.4.0",
3635
"serve-static": "^1.12.4",
36+
"uglify-es": "^3.2.1",
3737
"strip-json-comments": "^2.0.1",
38-
"uglify-js": "^3.0.28",
3938
"v8-compile-cache": "^1.1.0",
4039
"worker-farm": "^1.4.1",
4140
"ws": "^3.3.2"

src/HMRServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class HMRServer {
4444
});
4545
}
4646

47-
const containsHtmlAsset = assets.some(asset => asset.type === "html");
47+
const containsHtmlAsset = assets.some(asset => asset.type === 'html');
4848
if (containsHtmlAsset) {
4949
this.broadcast({
5050
type: 'reload'

src/WorkerFarm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class WorkerFarm extends Farm {
99
constructor(options) {
1010
let opts = {
1111
autoStart: true,
12-
maxConcurrentWorkers: getNumWorkers(),
12+
maxConcurrentWorkers: getNumWorkers()
1313
};
1414

1515
super(opts, require.resolve('./worker'));

src/transforms/uglify.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1-
const {AST_Node, minify} = require('uglify-js');
2-
const {toEstree} = require('babel-to-estree');
3-
const types = require('babel-types');
4-
const walk = require('babylon-walk');
1+
const {minify} = require('uglify-es');
52

63
module.exports = async function(asset) {
74
await asset.parseIfNeeded();
85

9-
// Convert to UglifyJS AST
10-
var ast = AST_Node.from_mozilla_ast(toEstree(asset.ast, asset.contents));
11-
var result = minify(ast, {
12-
toplevel: true
13-
});
6+
// Convert AST into JS
7+
let code = asset.generate().js;
148

15-
// Uglify did our code generation for us, so remove the old AST
9+
let options = {
10+
warnings: true,
11+
mangle: {
12+
toplevel: true
13+
},
14+
compress: {
15+
drop_console: true
16+
}
17+
};
18+
19+
let result = minify(code, options);
20+
21+
if (result.error) throw result.error;
22+
23+
// Log all warnings
24+
if (result.warnings) {
25+
result.warnings.forEach(warning => {
26+
// TODO: warn this using the logger
27+
console.log(warning);
28+
});
29+
}
30+
31+
// babel-generator did our code generation for us, so remove the old AST
1632
asset.ast = null;
1733
asset.outputCode = result.code;
1834
asset.isAstDirty = false;

yarn.lock

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -673,15 +673,7 @@ babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.26.0:
673673
babylon "^6.18.0"
674674
lodash "^4.17.4"
675675

676-
babel-to-estree@^0.0.3:
677-
version "0.0.3"
678-
resolved "https://registry.yarnpkg.com/babel-to-estree/-/babel-to-estree-0.0.3.tgz#8a6c5dc9e57d4f9d9397cd1aa98afc554f928824"
679-
dependencies:
680-
babel-traverse "^6.23.1"
681-
babel-types "^6.23.0"
682-
babylon "^6.16.1"
683-
684-
babel-traverse@^6.18.0, babel-traverse@^6.23.1, babel-traverse@^6.24.1, babel-traverse@^6.26.0:
676+
babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-traverse@^6.26.0:
685677
version "6.26.0"
686678
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee"
687679
dependencies:
@@ -695,7 +687,7 @@ babel-traverse@^6.18.0, babel-traverse@^6.23.1, babel-traverse@^6.24.1, babel-tr
695687
invariant "^2.2.2"
696688
lodash "^4.17.4"
697689

698-
babel-types@^6.15.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.23.0, babel-types@^6.24.1, babel-types@^6.26.0:
690+
babel-types@^6.15.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26.0:
699691
version "6.26.0"
700692
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497"
701693
dependencies:
@@ -712,7 +704,7 @@ babylon-walk@^1.0.2:
712704
babel-types "^6.15.0"
713705
lodash.clone "^4.5.0"
714706

715-
babylon@^6.16.1, babylon@^6.17.4, babylon@^6.18.0:
707+
babylon@^6.17.4, babylon@^6.18.0:
716708
version "6.18.0"
717709
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3"
718710

@@ -887,11 +879,11 @@ browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6:
887879
electron-to-chromium "^1.2.7"
888880

889881
browserslist@^2.1.2:
890-
version "2.9.1"
891-
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-2.9.1.tgz#b72d3982ab01b5cd24da62ff6d45573886aff275"
882+
version "2.10.0"
883+
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-2.10.0.tgz#bac5ee1cc69ca9d96403ffb8a3abdc5b6aed6346"
892884
dependencies:
893-
caniuse-lite "^1.0.30000770"
894-
electron-to-chromium "^1.3.27"
885+
caniuse-lite "^1.0.30000780"
886+
electron-to-chromium "^1.3.28"
895887

896888
buffer-xor@^1.0.3:
897889
version "1.0.3"
@@ -968,12 +960,12 @@ caniuse-api@^1.5.2:
968960
lodash.uniq "^4.5.0"
969961

970962
caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634, caniuse-db@^1.0.30000639:
971-
version "1.0.30000780"
972-
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000780.tgz#8d1977561d00ff0f0ed2b6b66140328ab4504c0a"
963+
version "1.0.30000782"
964+
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000782.tgz#d8815bce1578c350aced1132507301205e0fab53"
973965

974-
caniuse-lite@^1.0.30000770:
975-
version "1.0.30000780"
976-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000780.tgz#1f9095f2efd4940e0ba6c5992ab7a9b64cc35ba4"
966+
caniuse-lite@^1.0.30000780:
967+
version "1.0.30000782"
968+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000782.tgz#5b82b8c385f25348745c471ca51320afb1b7f254"
977969

978970
caseless@~0.11.0:
979971
version "0.11.0"
@@ -1195,8 +1187,8 @@ copy-descriptor@^0.1.0:
11951187
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
11961188

11971189
core-js@^2.4.0, core-js@^2.5.0:
1198-
version "2.5.1"
1199-
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.1.tgz#ae6874dc66937789b80754ff5428df66819ca50b"
1190+
version "2.5.2"
1191+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.2.tgz#bc4648656e7dc9dc80d7d3c7bbc172d96e744e63"
12001192

12011193
core-util-is@1.0.2, core-util-is@~1.0.0:
12021194
version "1.0.2"
@@ -1537,7 +1529,7 @@ ee-first@1.1.1:
15371529
version "1.1.1"
15381530
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
15391531

1540-
electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.27:
1532+
electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.28:
15411533
version "1.3.28"
15421534
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.28.tgz#8dd4e6458086644e9f9f0a1cf32e2a1f9dffd9ee"
15431535

@@ -1570,10 +1562,10 @@ entities@^1.1.1, entities@~1.1.1:
15701562
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"
15711563

15721564
errno@^0.1.1, errno@^0.1.4:
1573-
version "0.1.4"
1574-
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.4.tgz#b896e23a9e5e8ba33871fc996abd3635fc9a1c7d"
1565+
version "0.1.5"
1566+
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.5.tgz#a563781a6052bc2c9ccd89e8cef0eb9506e0c321"
15751567
dependencies:
1576-
prr "~0.0.0"
1568+
prr "~1.0.1"
15771569

15781570
error-ex@^1.2.0, error-ex@^1.3.1:
15791571
version "1.3.1"
@@ -3103,11 +3095,11 @@ minimist@~0.0.1:
31033095
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
31043096

31053097
mixin-deep@^1.2.0:
3106-
version "1.2.0"
3107-
resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.2.0.tgz#d02b8c6f8b6d4b8f5982d3fd009c4919851c3fe2"
3098+
version "1.3.0"
3099+
resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.0.tgz#47a8732ba97799457c8c1eca28f95132d7e8150a"
31083100
dependencies:
31093101
for-in "^1.0.2"
3110-
is-extendable "^0.1.1"
3102+
is-extendable "^1.0.1"
31113103

31123104
mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1:
31133105
version "0.5.1"
@@ -3335,8 +3327,8 @@ number-is-nan@^1.0.0:
33353327
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
33363328

33373329
nyc@^11.1.0:
3338-
version "11.4.0"
3339-
resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.4.0.tgz#18634c24058c12a4b7c9872b846249fb96e30719"
3330+
version "11.3.0"
3331+
resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.3.0.tgz#a42bc17b3cfa41f7b15eb602bc98b2633ddd76f0"
33403332
dependencies:
33413333
archy "^1.0.0"
33423334
arrify "^1.0.1"
@@ -3361,7 +3353,7 @@ nyc@^11.1.0:
33613353
resolve-from "^2.0.0"
33623354
rimraf "^2.5.4"
33633355
signal-exit "^3.0.1"
3364-
spawn-wrap "^1.4.1"
3356+
spawn-wrap "=1.3.8"
33653357
test-exclude "^4.1.1"
33663358
yargs "^10.0.3"
33673359
yargs-parser "^8.0.0"
@@ -3973,9 +3965,9 @@ promise@^7.1.1:
39733965
dependencies:
39743966
asap "~2.0.3"
39753967

3976-
prr@~0.0.0:
3977-
version "0.0.0"
3978-
resolved "https://registry.yarnpkg.com/prr/-/prr-0.0.0.tgz#1a84b85908325501411853d0081ee3fa86e2926a"
3968+
prr@~1.0.1:
3969+
version "1.0.1"
3970+
resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476"
39793971

39803972
pseudomap@^1.0.2:
39813973
version "1.0.2"
@@ -4129,8 +4121,8 @@ regenerator-runtime@^0.10.5:
41294121
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658"
41304122

41314123
regenerator-runtime@^0.11.0:
4132-
version "0.11.0"
4133-
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1"
4124+
version "0.11.1"
4125+
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"
41344126

41354127
regenerator-transform@^0.10.0:
41364128
version "0.10.1"
@@ -4318,7 +4310,7 @@ right-align@^0.1.1:
43184310
dependencies:
43194311
align-text "^0.1.1"
43204312

4321-
rimraf@2, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2:
4313+
rimraf@2, rimraf@^2.3.3, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1:
43224314
version "2.6.2"
43234315
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
43244316
dependencies:
@@ -4558,16 +4550,16 @@ source-map@^0.6.1, source-map@~0.6.1:
45584550
version "0.6.1"
45594551
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
45604552

4561-
spawn-wrap@^1.4.1:
4562-
version "1.4.2"
4563-
resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-1.4.2.tgz#cff58e73a8224617b6561abdc32586ea0c82248c"
4553+
spawn-wrap@=1.3.8:
4554+
version "1.3.8"
4555+
resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-1.3.8.tgz#fa2a79b990cbb0bb0018dca6748d88367b19ec31"
45644556
dependencies:
45654557
foreground-child "^1.5.6"
45664558
mkdirp "^0.5.0"
45674559
os-homedir "^1.0.1"
4568-
rimraf "^2.6.2"
4560+
rimraf "^2.3.3"
45694561
signal-exit "^3.0.2"
4570-
which "^1.3.0"
4562+
which "^1.2.4"
45714563

45724564
spdx-correct@~1.0.0:
45734565
version "1.0.2"
@@ -4893,6 +4885,13 @@ typescript@^2.6.2:
48934885
version "2.6.2"
48944886
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"
48954887

4888+
uglify-es@^3.2.1:
4889+
version "3.2.2"
4890+
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.2.2.tgz#15c62b7775002c81b7987a1c49ecd3f126cace73"
4891+
dependencies:
4892+
commander "~2.12.1"
4893+
source-map "~0.6.1"
4894+
48964895
uglify-js@^2.6, uglify-js@^2.8.29:
48974896
version "2.8.29"
48984897
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd"
@@ -4902,13 +4901,6 @@ uglify-js@^2.6, uglify-js@^2.8.29:
49024901
optionalDependencies:
49034902
uglify-to-browserify "~1.0.0"
49044903

4905-
uglify-js@^3.0.28:
4906-
version "3.2.1"
4907-
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.2.1.tgz#d6427fd45a25fefc5d196689c0c772a6915e10fe"
4908-
dependencies:
4909-
commander "~2.12.1"
4910-
source-map "~0.6.1"
4911-
49124904
uglify-to-browserify@~1.0.0:
49134905
version "1.0.2"
49144906
resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7"
@@ -5035,7 +5027,7 @@ which-module@^2.0.0:
50355027
version "2.0.0"
50365028
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"
50375029

5038-
which@1, which@^1.2.10, which@^1.2.9, which@^1.3.0:
5030+
which@1, which@^1.2.10, which@^1.2.4, which@^1.2.9:
50395031
version "1.3.0"
50405032
resolved "https://registry.yarnpkg.com/which/-/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a"
50415033
dependencies:

0 commit comments

Comments
 (0)