Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Add concat, compile and minify Grunt tasks #5776

Merged
merged 13 commits into from
Dec 5, 2013
Merged

Conversation

jasonsanjose
Copy link
Member

To test this branch:

  1. Run npm install to install the new grunt tasks
  2. Run grunt build to compile src to a new dist folder
  3. Hold the SHIFT key when opening a new Brackets window and select dist/index.html

Notes:

  • Change index.html to optionally include brackets.less vs compiled brackets.css via grunt less
  • Add new grunt build task to compile less and concat thirdparty libs, compile, minify and generate source map for brackets src/*/.js
  • Change main.js to be compatible with r.js
  • Minor changes to extensions and ShellAPI to account for new compile steps
  • Update .gitignore

Source Maps:

  • JavaScript source maps are supported as of brackets-shell for sprint 34
  • LESS source maps are not supported in brackets-shell (requires CEF with Chrome 30+). Source maps are generated and can be tested in Chrome. Verified on Chrome 31.

On my Mac, document.ready time is reduced from ~2.5s to ~1.4s, largely due to the compiled LESS code. Adding JavaScript minification brings document.ready time down to ~1.0s.

On Windows, we I go from ~3.8s to ~2.3s with LESS compiled only. ~2.0s with minification.

Still need to update brackets-shell packaging tasks.

This setup requires developers to install node and grunt to compile brackets.less to brackets.css. The other option would be to commit the compiled brackets.css to the repo. This would mean adding a 2nd generated file that I know of in addition to /src/config.json. We didn't pull the trigger on requiring node and grunt for contributors in the past so that the barrier to entry would stay low. Also, the payoff prior to now was not that great. I think we should reconsider changing the setup requirements for developers if we're averse to checking in compiled assets.

I have an old open pull request to port the dev env setup to Grunt here #4577.

UPDATE: This setup allows the current dev env setup to remain intact as far as dynamic LESS compilation. My prior assertion about requiring node+grunt no longer applies, and the case to require these tools for all developers is not as strong.

Open Questions

  1. Determine if extensions could rely on LESS mixins defined in brackets.less and whether or not it is desirable to so. --- ANSWER: No, trying to access variables and mixins does not work. Through our ExtensionUtils module, each .less file is compiled with it's own parser. Variables and mixins are only known to the parser created at startup time.

var promise, e = new Error(), stackDepth = e.stack.split("\n").length;

// Use E for Error so that uglify doesn't change this to simply Error()
var promise, E = Error, e = new E(), stackDepth = e.stack.split("\n").length;
Copy link
Member Author

Choose a reason for hiding this comment

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

This makes me think twice about minification. Without this, uglify essentially removes the new keyword, causing the error stack length to increase by 1, throwing off our logic here for detecting when a command is fired while Brackets is at a breakpoint. I vaguely remember @peterflynn having concerns just like this long long ago when it comes to JavaScript minification.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you measured the amount of time saved by minification vs. simply concatenating the files? I would guess that the big win is in concatenation, but I don't know for sure.

Regardless, if we want Brackets to work reasonably well in the browser, pursuing minification is likely worthwhile and as long as we don't need too many hacks like this, it seems reasonable.

(tangential aside: I've also wondered about us using Closure Compiler on our code, more for type checking than minification. It would be interesting to know if Closure Compiler does this same optimization. Of course, Closure Compiler is written in Java which is something of a drag.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, in my initial report I compared compiled LESS as the baseline, then added JS concat/minify. I can go back and compare concat and concat+minify separately.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's probably fine as is. We're going to want to properly support minified files because concat+minify+gzip is going to be less for the browser than just concat+gzip, I think.

@ghost ghost assigned dangoor Nov 1, 2013
@jasonsanjose
Copy link
Member Author

@dangoor I added source maps, but only for everything in our RequireJS root. Thirtparty libs are concatenated, but not minified. I hadn't tried out source maps in Chrome until now, but it seemed to work as advertised. The original files show up on a different node in the source tree labeled "(no domain)".

@dangoor
Copy link
Contributor

dangoor commented Nov 15, 2013

Awesome. Sounds like a good time to try this out and get to familiarizing myself with it.

@dangoor
Copy link
Contributor

dangoor commented Dec 4, 2013

Following your steps in the description, grunt fails because it can't find a build-config task:

grunt build
Warning: Task "build-config" not found. Use --force to continue.

Aborted due to warnings.

@dangoor
Copy link
Contributor

dangoor commented Dec 4, 2013

Just to make sure I know what we're going for here: the intention is that we continue developing Brackets as we have been, but when we go to ship it, we'll be shipping the bits from dist?

@dangoor
Copy link
Contributor

dangoor commented Dec 4, 2013

I merged master in (fixing the conflict in .gitignore). I also pulled down your brackets-shell branch, and merged master in there.

I removed the reference to build-config so that I could run grunt build. I had what appeared to be an acceptable dist directory. I built brackets-shell, fired it up and pointed it at dist/index.html. It's failing somewhere in startup for me (nothing in the window, menus aren't set up).

@jasonsanjose
Copy link
Member Author

Might be a conflict with the build.prop merge for the release branch. I'll take a look. Thanks!

@jasonsanjose
Copy link
Member Author

Yes, we can continue developing and running brackets without a build step in our development environment. We will only pick up the dist folder in a non-dev-env or when explicitly chosen.

@jasonsanjose
Copy link
Member Author

@dangoor can you try again now that I fixed the merge conflict. That should work, but if it doesn't you can also try the jasonsanjose/minify branch in brackets-shell and run grunt full-build there. Assuming you're on the jasonsanjose/yeoman branch in www, it will build the shell and copy www into the staging folder.

@dangoor
Copy link
Contributor

dangoor commented Dec 4, 2013

@jasonsanjose Yep, it works now (just using standard brackets-shell)! It did feel zippy starting up.


<link rel="stylesheet" type="text/css" href="thirdparty/CodeMirror2/lib/codemirror.css">
<!--(if target dev)><!-->
Copy link
Contributor

Choose a reason for hiding this comment

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

wow. that's pretty subtle... the dev target isn't commented out but the dist one is. Luckily, we don't have bunches of code that looks like this!

@dangoor
Copy link
Contributor

dangoor commented Dec 4, 2013

Looks good. I'm going to familiarize myself with a couple of the grunt bits here that I'm unfamiliar with and do some testing in the morning. It will likely be ready for merging then.

I do like how this preserves our current development experience and provides a way to speed up startup time for most users. This does mean that we'll need to be sure we test our builds well given that they will be a bit more different from our development environment than they are today.

@jasonsanjose
Copy link
Member Author

@dangoor let me know if I can help clarify anything or add comments.

'htmlmin',
'requirejs',
'concat',
/*'cssmin',*/
Copy link
Contributor

Choose a reason for hiding this comment

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

where are these two here but commented out? should they just be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, they can be removed. I'll follow up with another pull.

@dangoor
Copy link
Contributor

dangoor commented Dec 5, 2013

I don't think any additional comments are needed... Making sense of a Gruntfile requires understanding how Grunt itself works and also what the tasks do. This Gruntfile does quite a bit without a lot of code which is good but also a bit more opaque.

Everything looks fine from the testing I did this morning.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants