-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add concat, compile and minify Grunt tasks #5776
Changes from all commits
86c003c
3b9c5c0
fabd7b0
f51764b
342d42d
b68d69c
a82ae3d
291d664
7fd497f
3bd69db
0332a1f
fe09112
ef1bac2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,152 @@ | |
module.exports = function (grunt) { | ||
'use strict'; | ||
|
||
// load dependencies | ||
require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', 'grunt-targethtml', 'grunt-usemin']}); | ||
grunt.loadTasks('tasks'); | ||
|
||
var common = require("./tasks/lib/common")(grunt); | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
pkg : grunt.file.readJSON("package.json"), | ||
clean: { | ||
dist: { | ||
files: [{ | ||
dot: true, | ||
src: [ | ||
'dist', | ||
'src/.index.html', | ||
'src/styles/brackets.css' | ||
] | ||
}] | ||
} | ||
}, | ||
copy: { | ||
dist: { | ||
files: [ | ||
{ | ||
'dist/index.html': 'src/.index.html' | ||
}, | ||
/* static files */ | ||
{ | ||
expand: true, | ||
dest: 'dist/', | ||
cwd: 'src/', | ||
src: [ | ||
'nls/{,*/}*.js', | ||
'xorigin.js', | ||
'dependencies.js', | ||
'thirdparty/requirejs/require.js', | ||
'LiveDevelopment/launch.html' | ||
] | ||
}, | ||
/* extensions and CodeMirror modes */ | ||
{ | ||
expand: true, | ||
dest: 'dist/', | ||
cwd: 'src/', | ||
src: [ | ||
'extensibility/**/*', | ||
'!extensions/default/*/unittest-files/**/*', | ||
'!extensions/default/*/unittests.js', | ||
'extensions/default/*/**/*', | ||
'thirdparty/CodeMirror2/addon/{,*/}*', | ||
'thirdparty/CodeMirror2/keymap/{,*/}*', | ||
'thirdparty/CodeMirror2/lib/{,*/}*', | ||
'thirdparty/CodeMirror2/mode/{,*/}*', | ||
'thirdparty/CodeMirror2/theme/{,*/}*', | ||
'thirdparty/i18n/*.js', | ||
'thirdparty/text/*.js' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need these for |
||
] | ||
}, | ||
/* styles, fonts and images */ | ||
{ | ||
expand: true, | ||
dest: 'dist/styles', | ||
cwd: 'src/styles', | ||
src: ['jsTreeTheme.css', 'fonts/{,*/}*.*', 'images/*', 'brackets.min.css*'] | ||
} | ||
] | ||
} | ||
}, | ||
less: { | ||
dist: { | ||
files: { | ||
"src/styles/brackets.min.css": "src/styles/brackets.less" | ||
}, | ||
options: { | ||
compress: true, | ||
sourceMap: true, | ||
sourceMapFilename: 'src/styles/brackets.min.css.map', | ||
outputSourceFiles: true, | ||
sourceMapRootpath: '', | ||
sourceMapBasepath: 'src/styles' | ||
} | ||
} | ||
}, | ||
requirejs: { | ||
dist: { | ||
// Options: https://github.com/jrburke/r.js/blob/master/build/example.build.js | ||
options: { | ||
// `name` and `out` is set by grunt-usemin | ||
baseUrl: 'src', | ||
optimize: 'uglify2', | ||
// TODO: Figure out how to make sourcemaps work with grunt-usemin | ||
// https://github.com/yeoman/grunt-usemin/issues/30 | ||
generateSourceMaps: true, | ||
useSourceUrl: true, | ||
// required to support SourceMaps | ||
// http://requirejs.org/docs/errors.html#sourcemapcomments | ||
preserveLicenseComments: false, | ||
useStrict: true, | ||
// Disable closure, we want define/require to be globals | ||
wrap: false, | ||
exclude: ["text!config.json"], | ||
uglify2: {} // https://github.com/mishoo/UglifyJS2 | ||
} | ||
} | ||
}, | ||
targethtml: { | ||
dist: { | ||
files: { | ||
'src/.index.html': 'src/index.html' | ||
} | ||
} | ||
}, | ||
useminPrepare: { | ||
options: { | ||
dest: 'dist' | ||
}, | ||
html: 'src/.index.html' | ||
}, | ||
usemin: { | ||
options: { | ||
dirs: ['dist'] | ||
}, | ||
html: ['dist/{,*/}*.html'] | ||
}, | ||
htmlmin: { | ||
dist: { | ||
options: { | ||
/*removeCommentsFromCDATA: true, | ||
// https://github.com/yeoman/grunt-usemin/issues/44 | ||
//collapseWhitespace: true, | ||
collapseBooleanAttributes: true, | ||
removeAttributeQuotes: true, | ||
removeRedundantAttributes: true, | ||
useShortDoctype: true, | ||
removeEmptyAttributes: true, | ||
removeOptionalTags: true*/ | ||
}, | ||
files: [{ | ||
expand: true, | ||
cwd: 'src', | ||
src: '*.html', | ||
dest: 'dist' | ||
}] | ||
} | ||
}, | ||
meta : { | ||
src : [ | ||
'src/**/*.js', | ||
|
@@ -144,16 +285,9 @@ module.exports = function (grunt) { | |
linux: "<%= shell.repo %>/installer/linux/debian/package-root/opt/brackets/brackets" | ||
} | ||
}); | ||
|
||
// load dependencies | ||
grunt.loadTasks('tasks'); | ||
grunt.loadNpmTasks('grunt-contrib-jasmine'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-jasmine-node'); | ||
|
||
// task: install | ||
grunt.registerTask('install', ['write-config']); | ||
grunt.registerTask('install', ['write-config', 'less']); | ||
|
||
// task: test | ||
grunt.registerTask('test', ['jshint:all', 'jasmine']); | ||
|
@@ -163,6 +297,24 @@ module.exports = function (grunt) { | |
// Update sprint number in package.json and rewrite src/config.json | ||
grunt.registerTask('set-sprint', ['update-sprint-number', 'write-config']); | ||
|
||
// task: build | ||
grunt.registerTask('build', [ | ||
'jshint:src', | ||
'jasmine', | ||
'clean', | ||
'less', | ||
'targethtml', | ||
'useminPrepare', | ||
'htmlmin', | ||
'requirejs', | ||
'concat', | ||
/*'cssmin',*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, they can be removed. I'll follow up with another pull. |
||
/*'uglify',*/ | ||
'copy', | ||
'usemin', | ||
'build-config' | ||
]); | ||
|
||
// Default task. | ||
grunt.registerTask('default', ['test']); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,18 +32,22 @@ | |
<!-- NOTE: All scripts must be external for Chrome App support: http://developer.chrome.com/apps/app_csp.html --> | ||
|
||
<!-- Warn about failed cross origin requests in Chrome --> | ||
<script type="application/javascript" src="xorigin.js"> | ||
</script> | ||
|
||
<!-- TODO (Issue #278): switch between runtime LESS compilation in dev mode and precompiled version --> | ||
<link rel="stylesheet/less" href="styles/brackets.less"> | ||
<script src="thirdparty/less-1.4.2.min.js"></script> | ||
<script src="thirdparty/mustache/mustache.js"></script> | ||
<!-- <link rel="stylesheet" href="brackets.min.css"> --> | ||
<script type="application/javascript" src="xorigin.js"></script> | ||
|
||
<link rel="stylesheet" type="text/css" href="thirdparty/CodeMirror2/lib/codemirror.css"> | ||
<!--(if target dev)><!--> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
<link rel="stylesheet" type="text/less" href="styles/brackets.less"> | ||
<!--<!(endif)--> | ||
<!--(if target dist)> | ||
<link rel="stylesheet" type="text/css" href="styles/brackets.min.css"> | ||
<!--<!(endif)--> | ||
|
||
<!-- JavaScript --> | ||
|
||
<!-- Pre-load third party scripts that cannot be async loaded. --> | ||
<!-- build:js thirdparty/thirdparty.min.js --> | ||
<script src="thirdparty/less-1.4.2.min.js"></script> | ||
<script src="thirdparty/mustache/mustache.js"></script> | ||
<script src="thirdparty/jquery-2.0.1.min.js"></script> | ||
<script src="thirdparty/CodeMirror2/lib/codemirror.js"></script> | ||
<script src="thirdparty/CodeMirror2/addon/fold/xml-fold.js"></script> | ||
|
@@ -59,6 +63,7 @@ | |
|
||
<!-- JS for CodeMirror search support --> | ||
<script src="thirdparty/CodeMirror2/addon/search/searchcursor.js"></script> | ||
<!-- endbuild --> | ||
|
||
</head> | ||
<body> | ||
|
@@ -70,7 +75,9 @@ | |
--> | ||
|
||
<!-- All other scripts are loaded through require. --> | ||
<!-- build:js main.js --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could see the change caused by the build:js for thirdparty.min.js, but the only difference I see here is that the attributes switched order... otherwise, the script tag seems exactly the same. What should this be doing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sets up configuration used by the requirejs (r.js) task. You're right that it sort of looks like a no-op though. Anyhow, the config is printed to the terminal:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, that's like magic voodoo. There's nothing in the Gruntfile that runs r.js (looks like usemin takes care of it). |
||
<script src="thirdparty/requirejs/require.js" data-main="main"></script> | ||
<!-- endbuild --> | ||
|
||
<!-- Verify that all dependencies are loaded. --> | ||
<script src="dependencies.js"></script> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,9 @@ define(function (require, exports, module) { | |
// which we have to return true (issue #3152). | ||
return (eventName === Commands.FILE_CLOSE_WINDOW); | ||
} | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
// This function should *only* be called as a top-level function. If the current | ||
// stack depth is > 2, it is most likely because we are at a breakpoint. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need this for finding the extension manager node domain.