Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpillora/compilejs
A mini Grunt.js for the browser
https://github.com/jpillora/compilejs
Last synced: about 1 month ago
JSON representation
A mini Grunt.js for the browser
- Host: GitHub
- URL: https://github.com/jpillora/compilejs
- Owner: jpillora
- Created: 2013-04-08T00:10:25.000Z (over 11 years ago)
- Default Branch: gh-pages
- Last Pushed: 2015-11-01T03:54:30.000Z (about 9 years ago)
- Last Synced: 2024-10-13T11:42:37.253Z (3 months ago)
- Language: CoffeeScript
- Size: 313 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Compile.js
=========### Summary
Compile.js is a GruntJS inspired JavaScript build tool for the browser.
Compile.js makes it easy to create front end custom build widgets for your open-source projects.### Features
* Fluent API
* HTTP GET Files Cross-domain
* XHR for same origin
* Compile.js JSONP proxy server for cross origin
* Trigger File Downloads
* Chromes a.download for instant
* Compile.js server POST replay for download for other browsers
* Provided tasks
* Auto-parallelisation### Download
Use the [Compile.js API Explorer](http://jpillora.com/compilejs/builder/index.html) to compile your own build of Compile.js (very meta)
### Usage
Minify your library with [UglifyJS2](https://github.com/mishoo/UglifyJS2)
``` javascript
$.compile
.fetch('lib', 'js/my-lib.js')
.run('uglify', {
src: 'lib',
dest: 'lib-min'
})
.download('lib-min');
```### Demos
* [Minify example](http://jpillora.com/compilejs/example/uglify.html)
* [Download example](http://jpillora.com/compilejs/example/download.html)
* [CoffeeScript example](http://jpillora.com/compilejs/example/coffee.html)
* [Concatenate example](http://jpillora.com/compilejs/example/concat.html)
* [Popup example](http://jpillora.com/compilejs/example/popup.html)### API
*Note: You can play with this API using the [Compile.js API Explorer](http://jpillora.com/compilejs/builder/index.html)*
#### `$.compile`.`get( name[s], callback( err, value[s] ) )`
Get a value
* `name[s]` - string or an array of strings
* `value[s]` - same type as `name[s]`
#### `$.compile`.`set( name, value )`
Set a value.
* `name` - string
* `value` - string#### `$.compile`.`fetch( name, url )`
Fetches a URL and
* `name` - string
* `url` - string*Note: `url` will be retrieved with an XHR request if it has the same origin as the current page, otherwise it will be retrieved using the Compile.js JSONP proxy server*
#### `$.compile`.`run( taskName, taskConfig )`
Runs the given task with the given config
* `taskName` - string
* `taskConfig` - object#### `$.compile`.`download( name )`
Downloads the value of `name` as `filename`
* `name` - string
* `filename` - string [optional] - defaults to "`name`.js"*Note: On browsers that do not support [anchor download attribute](http://caniuse.com/download), the download
will be forced by POSTing the contents of the file to the Compile.js POST replay server which
will just return the content though with the `Content-Disposition` header set.*#### `$.compile`.`popup( name )`
Open a small popup with the value of `name`
* `name` - string
*Warning: This will likely trigger a popup warning from most modern browsers*
#### `$.compile`.`log( callback ( string ) )`
#### `$.compile`.`error( callback ( string ) )`
#### `$.compile`.`warn( callback ( string ) )`Log, Error and Warning handlers
### Tasks
#### `$.compile`.`task( taskName, definition )`
Adds a new task
If `definition` is:
* a string, it will be treated as a script URL and attempt to load it.
* a function, it must have the signature `function(config, callback)`
* `config` will contain the object the user provides
* `config.src` *Note: the `src` property will be passed through `instance`.`get()` and
when this function is executed, `config.src` will be the the `value[s]`
associated with the `name[s]`*
* `callback` must be called when the task is complete* If `definition` is a object, it must contain a:
* `run` function - which matches the signature aboveand optional:
* `fetch` object - which map global names to URLs, missing globals will be fetched. *Useful for lazy loading dependancies.*
* `init` function - which will run once all URLs have been fetched.#### [Task list](https://github.com/jpillora/compilejs/tree/gh-pages/dist/tasks)
* Concat - [Built-in](https://github.com/jpillora/compilejs/blob/gh-pages/src/compile.coffee#L236)
* CoffeeScript - [compile.coffee-script.js](https://github.com/jpillora/compilejs/tree/gh-pages/dist/tasks/compile.coffee-script.js)
* Uglify - [compile.uglify.js](https://github.com/jpillora/compilejs/tree/gh-pages/dist/tasks/compile.coffee-script.js)
* *More to come...*Using the [Compile.js API Explorer](http://jpillora.com/compilejs/builder/index.html), you can build a custom version of Compile.js which includes a subset of these tasks.
#### Conceptual Overview
This library uses method chaining. There is no "create" method because a static verions of each chainable method is made which adds an extra step - creates an instance - then the corresponding instance method is called (Code is [here](https://github.com/jpillora/compilejs/blob/gh-pages/src/compile.coffee#L242)). Each instance has an event emitter. When you `get()`, an event listener will watch for the `name` to be set. When you `set()`, an event will be fired - triggering all listeners. This way, the order of operations will work itself out.
#### MIT License
Copyright © 2013 Jaime Pillora <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.