Comments (9)
from uglifyify.
¯\(°_o)/¯
also this:
❯ for i in 0 1 2 3 4 5 6 7 8 9; do echo "require('react-dom')" | ./node_modules/.bin/browserify - | ./node_modules/.bin/uglifyjs -cm 2>/dev/null| wc -c; done
242537
242537
242537
242537
242537
242537
242537
242537
242537
242537
from uglifyify.
Also, "Minimal test case below." was a bit cheeky to say. react
is a beast.
from uglifyify.
Okay, I have a much smaller test case without React involved. Repository here https://github.com/casr/uglifyify-bug
It seems to have something to do with including files that are similar to one and other. I'm guessing the reason it's unstable has something to do with the order in which files are pushed through the uglifyify transform.
--- output-1.js 2017-03-31 22:26:02.000000000 +0100
+++ output-35.js 2017-03-31 22:26:12.000000000 +0100
@@ -4,14 +4,13 @@
module.exports="a string";
},{}],3:[function(require,module,exports){
var c=require("./c");module.exports=[c];
-
},{"./c":2}],4:[function(require,module,exports){
require("./d");
},{"./d":3}],5:[function(require,module,exports){
arguments[4][2][0].apply(exports,arguments)
},{"dup":2}],6:[function(require,module,exports){
-var c=require("./c");module.exports=[c];
-},{"./c":5}],7:[function(require,module,exports){
+arguments[4][3][0].apply(exports,arguments)
+},{"./c":5,"dup":3}],7:[function(require,module,exports){
require("../a"),require("./d");
},{"../a":4,"./d":6}]},{},[1]);
Note: Because this test case is so small, it doesn't trigger quite as often as the React one. But at least the builds are quicker...
from uglifyify.
Theory: the variations are coming from browserify, and it's only showing up with uglifyify because it's a long, blocking task.
from uglifyify.
I reran the same test with Browserify's --no-dedupe
switch and still got differences. This time it was just new lines. Adding a new line gives a new hash for its contents which then leads to much more dramatic differences when it's run through the dedupe part of Browserify's pipeline.
Probably related to #57 although the suggested fix didn't work for me.
from uglifyify.
I was playing around and I think I've managed to fix it, however, my solution hooks more directly into the UglifyJS API. In doing so I've rewritten the source map code to just use UglifyJS's built in one. It all seems to be working fine but I would like to write some tests to confirm before submitting a PR.
The approach I have taken so far is to try and do the bare minimum to just get rid dead code and extraneous require calls. I think that was in keeping with the spirit of the readme. Why? The thinking is that you will be piping it through uglifyjs -cm
anyway so there's not point doing the work twice.
On a large codebase like React's it's resulting in quicker build times and ever so slightly smaller bundles (probably related to the dedupe problem). If you're happy to accept a PR along those lines then I'll try and get something done by next weekend.
In other news, UglifyJS's API has made me sad.
from uglifyify.
More research: The real problem is in fact that opts._flags doesn't always get sent through. This causes the debug flag to occasionally flip to it's default value of true.
var debug = '_flags' in opts
? opts._flags.debug
: true
This then causes UglifyJS to produce a source map:
if (min.map && min.map !== 'null') {
var map = convert.fromJSON(min.map)
// ... snip ...
this.queue('\n')
this.queue(map.toComment())
}
which then causes Browserify to remove the sourcemap (as it thinks it is out of debug mode) but leave the new line which is why we get strange results with the dedupe operation later.
So it would seem to be a Browserify issue at this stage. I need to check their issue tracker and see if the occasional passing through of opts._flags
is intended behaviour or not.
from uglifyify.
So I followed the transform logic through and there didn't seem to be a problem on Browserify's side but I noticed the opts
object persisted through runs and I remembered seeing this: https://github.com/hughsk/uglifyify/blob/621cfede/index.js#L17
Deleting the _flags
key breaks the debug logic in future file transforms. @hughsk do you know why you added the delete or is it safe to remove that line? I couldn't find anything in the commit logs for it.
from uglifyify.
Related Issues (20)
- Optional chaining support
- Update terser up to 4.8.1 HOT 1
- Switching from 3.0.4 to 4.0.0 results in TypeError: Cannot read property 'replace' of undefined while parsing file HOT 12
- command line usage does not work HOT 2
- (v4) `ignore` is not a supported option HOT 2
- (v4) How to use "extensions" (-x, --exts) with node HOT 2
- Add CHANGELOG.md HOT 4
- Add better tests HOT 2
- Uglifyify fails when calling uglify HOT 3
- Missing command line entry
- --ignore flag being ignored in Jenkins environment HOT 2
- New dependency name: uglify-es => terser #1 HOT 2
- Fatal error: `ignore` is not a supported option while parsing file: HOT 2
- Update to [email protected]
- Inlined sourcemaps
- Global flag is ignored
- beautify does not work; should be an output option
- update package extend to >2.0.2 to remove package vurnerability HOT 1
- Wrong CLI option for Source Maps in README.md
- SyntaxError: 'return' outside of function while parsing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uglifyify.