Git Product home page Git Product logo

piler's Introduction

Piler

Build Status

Feature highlights

  • Minify and concatenate JS and CSS for fast page loads
  • Tag rendering
  • Namespaces
  • Transparent preprocessor
  • Push CSS changes to the browser using Socket.IO
  • Easy code sharing with server

Awesome Asset Manager for Node.js

Piler allows you to manage all your JavaScript and CSS assets cleanly and directly from code. It will concatenate and minify them in production and it takes care of rendering the tags. The idea is to make your pages load as quickly as possible.

So why create a yet another asset manager? Because Node.js is special. In Node.js a JavaScript asset isn't just a pile of bits that are sent to the browser. It's code. It's code that can be also used in the server and I think that it's the job of asset managers to help with it. So in Piler you can take code directly from your Javascript objects, not just from JavaScript files. Copying things from Rails is just not enough. This is just a one reason why Piler was created.

Server-side code:

clientjs.addOb({BROWSER_GLOBAL: {
    aFunction: function() {
        console.log("Hello I'm in the browser also. Here I have", window, "and other friends");
    }
}});

You can also tell Piler to directly execute some function in the browser:

clientjs.addExec(function() {
    BROWSER_GLOBAL.aFunction();
    alert("Hello" + window.navigator.appVersion);
});

Currently Piler works only with Express, but other frameworks are planned as well.

Piler is written following principles in mind:

  • Creating best possible production setup for assets should be as easy as including script/link to a page.
  • Namespaces. You don't want to serve huge blob of admin view code for all anonymous users.
  • Support any JS- or CSS-files. No need to create special structure for your assets. Just include your jQueries or whatever.
  • Preprocessor languages are first class citizens. Eg. Just change the file extension to .coffee to use CoffeeScript. That's it. No need to worry about compiled files.
  • Use heavy caching. Browser caches are killed automatically using the hash sum of the assets.
  • Awesome development mode. Build-in support for pushing CSS changes to browsr using Socket.IO.

Full example Express 2.x

var createServer = require("express").createServer;
var piler = require("piler");

var app = createServer();
var clientjs = piler.createJSManager();
var clientcss = piler.createCSSManager();

app.configure(function() {
    clientjs.bind(app);
    clientcss.bind(app);

    clientcss.addFile(__dirname + "/style.css");

    clientjs.addUrl("http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js");
    clientjs.addFile(__dirname + "/client/hello.js");
});

app.configure("development", function() {
    clientjs.liveUpdate(clientcss);
});

clientjs.addOb({ VERSION: "1.0.0" });

clientjs.addExec(function() {
    alert("Hello browser" + window.navigator.appVersion);
});

app.get("/", function(req, res){
    res.render("index.jade", {
        layout: false,
        js: clientjs.renderTags(),
        css: clientcss.renderTags()
    });
});

app.listen(8080);

Full example Express 3.x

var express = require('express'),
    http = require('http'),
    piler = require("piler"),
    app = express();

var clientjs = piler.createJSManager();
var clientcss = piler.createCSSManager();
var srv = require('http').createServer(app);

app.configure(function(){

    clientjs.bind(app,srv);
    clientcss.bind(app,srv);

    clientcss.addFile(__dirname + "/style.css");

    clientjs.addUrl("http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js");
    clientjs.addFile(__dirname + "/client/hello.js");
});

app.configure("development", function() {
    clientjs.liveUpdate(clientcss);
});

clientjs.addOb({ VERSION: "1.0.0" });

clientjs.addExec(function() {
    alert("Hello browser" + window.navigator.appVersion);
});

app.get("/", function(req, res){
    res.render("index.jade", {
        layout: false,
        js: clientjs.renderTags(),
        css: clientcss.renderTags()
    });
});

srv.listen(8080);

index.jade:

!!! 5
html
  head
    !{css}
    !{js}
  body
    h1 Hello Piler

Namespaces

The example above uses just a one pile. The global pile.

If you for example want to add big editor files only for administration pages you can create a pile for it:

clientjs.addFile("admin", __dirname + "/editor.js");
clientjs.addFile("admin", __dirname + "/editor.extension.js");

This will add file editor.js and editor.extension.js to a admin pile. Now you can add that to your admin pages by using giving it as parameter for renderTags.

js.renderTags("admin");

This will render script-tags for the global pile and the admin-pile. js.renderTags and css.renderTags can take variable amount of arguments. Use js.renderTags("pile1", "pile2", ....) to render multiple namespaces

Piling works just the same with css.

Sharing code with the server

Ok, that's pretty much what every asset manager does, but with Piler you can share code directly from your server code.

Let's say that you want to share a email-validating function with a server and the client

function isEmail(s) {
  return !! s.match(/.\w+@\w+\.\w/);
}

You can share it with addOb -method:

clientjs.addOb({MY: {
   isEmail: isEmail
   }
});

Now on the client you can find the isEmail-function from MY.isEmail.

addOb takes an object which will be merged to global window-object on the client. So be careful when choosing the keys. The object can be almost any JavaScript object. It will be serialized and sent to the browser. Few caveats:

  1. No circural references
  2. Functions will be serialized using Function.prototype.toString. So closures won't transferred to the client!

Pattern for sharing full modules

This is nothing specific to Piler, but this is a nice pattern which can be used to share modules between the server and the client.

share.js

(function(exports){

  exports.test = function(){
       return 'This is a function from shared module';
  };

}(typeof exports === 'undefined' ? this.share = {} : exports));

In Node.js you can use it by just requiring it as any other module

var share = require("./share.js");

and you can share it the client using addFile:

clientjs.addFile(__dirname + "./share.js");

Now you can use it in both as you would expect

share.test();

You can read more about the pattern from here

Logging

Sometimes it is nessesary to control pilers output based on the system environment your running your application in. In default mode Pilers logger will output any information it has by using the "console" javascript object. The following example shows how to configure a custom logger

Logger interface

The basic logger facility implements the following methods.

exports.debug    = console.debug
exports.notice   = console.log
exports.info     = console.info
exports.warn     = console.warn
exports.warning  = console.warn
exports.error    = console.error
exports.critical = console.error

Inject a custom logger

The following example injects "winston", a multi-transport async logging library into pilers logging mechanism.

var piler = require('piler');
var logger = require('winston');
// [More logger configuration can take place here]

global.js = js = piler.createJSManager({ outputDirectory: assetTmpDir , "logger": logger});
global.css = css = piler.createCSSManager({ outputDirectory: assetTmpDir, "logger": logger});

More information about winston can be found here.

Awesome development mode!

Development and production modes works as in Express. By default the development mode is active. To activate production mode set NODE_ENV environment variable to production.

Live CSS editing

This is really cool! You don't want to edit CSS at all without this after you try it!

Because Piler handles the script-tag rendering it can add some development tools when in development mode.

Using Express you can add Live CSS editing in development mode:

app.configure("development", function() {
   clientjs.liveUpdate(clientcss);
});

This is similar to Live.js, but it does not use polling. It will add Socket.IO which will push the CSS-changes to your browser as you edit them.

If your app already uses Socket.IO you need to add the io-object as second parameter to liveUpdate:

var io = require('socket.io').listen(app);
clientjs.liveUpdate(clientcss, io);

Script-tag rendering

In development mode every JS- and CSS-file will be rendered as a separate tag.

For example js.renderTags("admin") will render

clientjs.addFile(__dirname + "/helpers.js");
clientjs.addFile("admin", __dirname + "/editor.js");
clientjs.addFile("admin", __dirname + "/editor.extension.js");

to

<script type="text/javascript" src="/pile/dev/_global/1710d-helpers.js?v=1317298508710" ></script>
<script type="text/javascript" src="/pile/dev/admin/3718d-editor.js?v=1317298508714" ></script>
<script type="text/javascript" src="/pile/dev/admin/1411d-editor.extension.js?v=1317298508716" ></script>

in development mode, but in production it will render to

<script type="text/javascript"  src="/pile/min/_global.js?v=f1d27a8d9b92447439f6ebd5ef8f7ea9d25bc41c"  ></script>
<script type="text/javascript"  src="/pile/min/admin.js?v=2d730ac54f9e63e1a7e99cd669861bda33905365"  ></script>

So debugging should be as easy as directly using script-tags. Line numbers will match your real files in the filesystem. No need to debug huge Javascript bundle!

Examples

Visit this directory to see a simple example using ExpressJS 2.x.

This example uses ExpressJS 3.x a custom logger (winston) and a global socket.io instance together with Piler.

API summary

Code will be rendered in the order you call these functions with the exception of addUrl which will be rendered as first.

createJSManager and createCSSManager

Can take an optional configuration object as an argument with following keys.

var jsclient = piler.createJSManager({
    outputDirectory: __dirname + "/mydir",
    urlRoot: "/my/root"
});

urlRoot

Url root to which Piler's paths are appended. For example urlRoot "/my/root" will result in following script tag:

<script type="text/javascript" src="/my/root/min/code.js?v=f4ec8d2b2be16a4ae8743039c53a1a2c31e50570" ></script>

outputDirectory

If specified Piler will write the minified assets to this folder. Useful if you want to share you assets from Apache etc. instead of directly serving from Piler's Connect middleware.

JavaScript pile

addFile( [namespace], path to a asset file )

File on filesystem.

addUrl( [namespace], url to a asset file )

Useful for CDNs and for dynamic assets in other libraries such as socket.io.

addOb( [namespace string], any Javascript object )

Keys of the object will be added to the global window object. So take care when choosing those. Also remember that parent scope of functions will be lost.

You can also give a nested namespace for it

clientjs.addOb({"foo.bar": "my thing"});

Now on the client "my thing" string will be found from window.foo.bar.

The object will be serialized at the second it is passed to this method so you won't be able modify it other than between server restarts. This is usefull for sharing utility functions etc.

Use res.addOb to share more dynamically objects.

addExec( [namespace], Javascript function )

A function that will executed immediately in browser as it is parsed. Parent scope is also lost here.

addRaw( [namespace], raw Javascript string )

Any valid Javascript string.

CSS pile

These are similar to ones in JS pile.

addFile( [namespace], path to a asset file )

CSS asset on your filesystem.

addUrl( [namespace], url to a asset file )

CSS asset behind a url. Can be remote too. This will be directly linked to you page. Use addFile if you want it be minified.

addRaw( [namespace], raw CSS string )

Any valid CSS string.

Supported preprocessors

JavaScript

For JavaScript the only supported one is CoffeeScript and the compiler is included in Piler.

CSS

CSS-compilers are not included in Piler. Just install what you need using npm.

  • Stylus with nib (npm install stylus nib)
  • LESS (npm install less)

Adding support for new compilers should be easy.

Feel free to contribute!

Installing

From npm

npm install piler

Source code

Source code is licenced under The MIT License and it is hosted on Github.

Changelog

v0.4.2 - 2013-04-16

  • Fixes to work with ExpressJS 3.x
  • Unit test fixes
  • Make console output configurable

v0.4.1 - 2012-06-12

  • Add getSources
  • Put cache key to resource url instead of query string

v0.4.0 - 2012-06-17

  • Remove Dynamic Helpers.

Dynamic Helpers where an Express 2.0 only API. This makes Piler more framework agnostic and it will work with Express 3.0. This also removes support for response object functions. We'll add those back if there is a need for them (open up a issue if you miss them!) and we'll find good framework agnostic way to implement them.

v0.3.6 - 2012-06-17

  • Bind all production dependency versions

v0.3.5 - 2012-06-17

  • Fix LESS @imports
  • Fix Stylus without nib
  • Use path module for Windows compatibility

v0.3.4 - 2012-03-29

  • Fix Stylus @imports

v0.3.3 - noop

v0.3.2 - 2011-12-11

  • Workaround compiler bug in CoffeeScript

v0.3.1 - 2011-11-17

  • Fix CSS namespaces

v0.3.0 - 2011-10-13

  • Rename to Piler
  • Really minify CSS
  • Implemented res.addOb
  • Implement outputDirectory and urlRoot options.
  • addOb can now take nested namespace string and it won't override existing namespaces.

Contact

Questions and suggestions are very welcome

piler's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

piler's Issues

Piler is incompatible with Express 3.0

Scenario:

  • Run Piler with Express 3.0

Steps to repro:

  • Setup an arbitrary project that uses Express 3.0 and Piler
  • Try to run project

Expected result:

  • Running project

Actual result:

  • Node crashes, since "Object function app(req, res){ app.handle(req, res); } has no method 'dynamicHelpers'" in piler.coffee

Problem:

  • Classes CSSManager and JSManager each contain a function that relies on app.dynamicHelpers
  • app.dynamicHelpers does not exist any longer in Express 3.0

Solution:

  • Replace app.dynamicHelpers by app.locals.use
  • See akoenig/express-lingua#9 as example how to support both Express 2.x and 3.x

Note:

  • I would have fixed it myself if I had been able to handle the coffeescript part accordingly :-(

background-image in css doesn't load

Hi piler Team!

I used piler in nodejs with express & pile. I loaded one css file using addFile. In this file, I used background-image. But it seems it didn't load.

Appreciate any help!!!! Thanks!

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

upcoming 1.0.0

Achieve stable code, a lot of breaking API changes to come

How to add more attributes (ex: media query for link tag)?

Hi epeli,

How can I add more attributes for css and js. For example I want to add something like this:

<link rel='stylesheet' media='screen and (min-width: 701px) and (max-width: 900px)' href='css/medium.css'>

Using piler force me to add media query inside the css file because I cannot customize the attributes.

Need ability to turn off random .js names / paths in dev mode.

When debugging complicated JS scripts, sometimes it's necessary to put in a breakpoint in the browser and refresh the page to hit that breakpoint. With Pilar the names change every time you refresh (even in debug mode) making it impossible to debug certain scenarios because the browser loses track of the js file.

I can see why Pilar does that: to ensure non-cached files during development. Chrome lets you turn off caching while in debug mode as it is, making the random name bit an issue instead of a blessing.

An ideal solution would be to have a function on the JSManager called "staticNames(true | false)" or something allowing us to toggle that behavior.

Piler installation error

Hello, when i add piler to my package.json and do a npm install I get:

npm http 200 https://registry.npmjs.org/csso/-/csso-1.2.18.tgz
npm ERR! Error: ENOENT, chmod '/Users/daslicht/node/fileServer/node_modules/deployd/bin/dpd'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Darwin 12.4.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/daslicht/node/fileServer
npm ERR! node -v v0.10.13
npm ERR! npm -v 1.3.2
npm ERR! path /Users/daslicht/node/fileServer/node_modules/deployd/bin/dpd
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/daslicht/node/fileServer/npm-debug.log
npm ERR! not ok code 0

What am I missing ?

global-#{ @getTagKey() }.css v global.css?v=#{ @getTagKey() }

Can Piler create Rails asset pipeline file names e.g.:

global-908e25f4bf641868d8683022a5b62f54.css

The ones piler seems to be outputting are:

global.css?v=908e25f4bf641868d8683022a5b62f54

From http://guides.rubyonrails.org/asset_pipeline.html

The query string strategy has several disadvantages:

  1. Not all caches will reliably cache content where the filename only differs by query parameters.
    Steve Souders recommends, β€œβ€¦avoiding a querystring for cacheable resources”. He found that in this case 5-20% of requests will not be cached. Query strings in particular do not work at all with some CDNs for cache invalidation.
  2. The file name can change between nodes in multi-server environments.
    The default query string in Rails 2.x is based on the modification time of the files. When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request.
  3. Too much cache invalidation
    When static assets are deployed with each new release of code, the mtime of all these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed.
    Fingerprinting fixes these problems by avoiding query strings, and by ensuring that filenames are consistent based on their content.

Thanks Dale

[Performance] Cache minified files between restart in production

Could it be possible to add a caching feature to Piler in order to not minify again files that didn't changed (maybe using sha1 to check for changes) between server restart in production.

I've got a nodejs server in production that takes more than two minutes to minify all the files when it starts, caching files will be a huge performance boost for piler and should contribute to its wide usage inside the nodejs community.

In HTML5 <script> type is optional

In HTML5 the type attribute is optional on the script tag, but required for HTML 4. It think it would be nice to not use the atttribute by default but rather have a configurable property, eg: useTypeAttribute (Boolean).

var js = pile.createJSManager({ useTypeAttribute: true }); // default: false

CSS LiveUpdate Issue

Hello,

I have the following:

var srv = http.createServer(app).listen(app.get('port'), function(){
    var io = require('socket.io').listen(srv);
    app.configure(function(){
        clientjs.bind(app,srv);
        clientcss.bind(app,srv);
        app.configure("development", function() {
            clientjs.liveUpdate(clientcss);
        });
        clientjs.liveUpdate(clientcss, io);

        clientcss.addUrl("http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css");
        clientjs.addUrl("http://code.jquery.com/jquery-1.9.1.js");
        clientjs.addUrl("http://code.jquery.com/ui/1.10.3/jquery-ui.js");
    });

My browser console outputs:

CSS updater is active. Waiting for connection... 
CSS updater has connected 

But if I change my style.css the changes do not get reflected.
Any Idea?

Issue on windows with filepath routing in npm package.

Hi there,

with the current NPM version 0.3.4 on windows it looks like that the route for scripts in development environment are not proberly escaped. There for the scripts can not be resolved by the router. For example:

If I got my styles under:

c:\Users\pirsig\Documents\testpiler\style_css_5bbe7db683.css

My development route to that script looks like this:

/pile/dev/global.file-c:\Users\pirsig\Documents\testpiler\style_css_5bbe7db683.css?v=1336723429467

And this fails to resolves. I patched piler.coffee to escape ":" and "" in paths by modifying the following block to look like this:

    if @type  in ["file", "module"]
      filename = _.last @filePath.split("/")
      filename = filename.replace /\./g, "_"
      filename = filename.replace /\-/g, "_"
      filename = filename.replace ":", "_"
      filename = filename.replace /\\/g, "_"
      hash = filename + "_" + hash

I would provide a pull request but the problem is that the master branch has it already fixed and there is no stable branch with the actual source code that could be bugfixed.

Also if this is fixed: #15 the current npm version of piler will start working perfect on windows.

Best,

Alex

Add Functions to add Arrays of Files or Urls

First thing first - nice project.

This is only a suggestion not a issue! But would be nice if you could add functions to pass in an array of files instead of file by file.

eg:

    clientcss.addFiles(optionalPrefixForAll, [fileOne, fileTwo])

With latest libraries, functions renderStyleTags and renderScriptTags are undefined in the example template

This is the result of making a request from an actual browser:

TypeError: undefined is not a function
    at Object.render (/Users/raimo/proj/node_modules/jade/lib/jade.js:202:5)
    at ServerResponse.render (/Users/raimo/proj/node_modules/express/lib/express/view.js:334:22)
    at Object.<anonymous> (/Users/raimo/proj/ex.js:29:9)
    at param (/Users/raimo/proj/node_modules/connect/lib/connect/middleware/router.js:146:21)
    at pass (/Users/raimo/proj/node_modules/connect/lib/connect/middleware/router.js:162:11)
    at Object.router [as handle] (/Users/raimo/proj/node_modules/connect/lib/connect/middleware/router.js:168:7)
    at next (/Users/raimo/proj/node_modules/connect/lib/connect/index.js:218:15)
    at Object.handle (/Users/raimo/proj/node_modules/piler/lib/piler.coffee:449:68)
    at next (/Users/raimo/proj/node_modules/connect/lib/connect/index.js:218:15)
    at Object.handle (/Users/raimo/proj/node_modules/piler/lib/piler.coffee:449:68)

$ npm ls

    npm WARN [email protected] package.json: bugs['web'] should probably be bugs['url']
    /Users/raimo/proj
    β”œβ”€β”¬ [email protected]
    β”‚ └── [email protected]
    β”œβ”€β”¬ [email protected]
    β”‚ └── [email protected]
    β”œβ”€β”¬ [email protected]
    β”‚ β”œβ”€β”€ [email protected]
    β”‚ └── [email protected]
    β”œβ”€β”¬ [email protected]
    β”‚ β”œβ”€β”€ [email protected]
    β”‚ β”œβ”€β”€ [email protected]
    β”‚ β”œβ”€β”€ [email protected]
    β”‚ └── [email protected]
    └── [email protected]

$ cat ex.js

    var createServer = require("express").createServer;
    var pile = require("piler");
    var app = createServer();
    var js = pile.createJSManager();
    var css = pile.createCSSManager();
    app.configure(function() {
        js.bind(app);
        css.bind(app);
        css.addFile(__dirname + "/style.css");
        js.addUrl("http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js");
        js.addFile(__dirname + "/client/hello.js");
    });
    app.configure("development", function() {
        js.liveUpdate(css);
    });
    js.addOb({ VERSION: "1.0.0" });
    app.get("/", function(req, res){
        res.render("index.jade", { layout: false });
    });
    app.listen(8080); 

$ cat views/index.jade

    !!!! 5
    html
      head
        !{renderStyleTags()}
        !{renderScriptTags()}
      body
        h1 Hello Piler
        #container !{body}

Feedback on 0.6.0 branch

For 1.0.0 discussion, go here #54

https://github.com/epeli/piler/tree/0.6.0

See if anything breaks. minor versioning should not break anything.

Upcoming changes:
#0.6.0 - 2014-06-12

  • Fixed tests to run on any environment
  • Fixed tests for using new jade and express >=3.x conventions
  • Updated jQuery test version
  • Update dependencies
  • Updated minify.coffee
  • Added package.json scripts
  • Initial code coverage
  • Drop Node.js 0.8 support
  • Added debug module to all sources
  • use strict for quality of code
  • Forbid using of ECMAScript reserved words for namespaces in JS
  • Added graceful-fs for your open file descriptor uneaseness
  • Added cache for minified code, you may provide your own cache mechanism. It uses filesystem by default
  • Fix examples
  • Code cleanup
  • Expose BasePile for testing and augmenting
  • Started documenting code
  • Added functions for adding and removing compilers from Piler
  • Fix findCodeObByFilePath
  • Fix livecss
  • Fix Express response helper
  • Added volatile Pile (that can be reset on demand)

In Express 3 Piler fails silently

I don't understand CoffeeScript well enough to debug the following, I'm afraid. :(

In development mode Piler outputs nothing more than:

info: socket.io started
listening on 8001

No files are written to the out folder. Apparently no caching is taking place.

In production mode the console output is the same but here the rendered tags contain 'undefined' instead of a hash in the URI and the served 'files' are empty. Like so:

<link rel="stylesheet" href="/pile/min/undefined/global.css"  />
<script type="text/javascript"  src="/pile/min/undefined/global.js"  ></script>

I tested with [email protected] and [email protected].

Deprecation

It's advised that piler should not be used in new projects, there are plenty of solutions that deal with CSS, Javascript, and general assets bundling, that should be used for modern frontend workflows, in order preference:

  • Webpack
  • JSPM
  • Gulp / Grunt
  • Browserify
  • Duo

Adding an option to disable UglifyJS

Really nice lib!

The reason it'd be nice to disable uglifyJS is to prevent it from breaking code in production mode. The reason I'm asking is because I'm currently depending on CoffeeKup https://github.com/mauricemach/coffeekup for client-side rendering but as soon as UglifyJS "uglifies" my code, CoffeeKup breaks.
And I think it would be nice in other situations aswell, because currently you are pretty much screwed if you are using a 3rd party lib that doesn't support being "uglified".

Also... :)

The only way to have the css and the javascript files being minified right now is by running NODE_ENV=production, but it would be nice if this wasn't hard-coded so that you could serve minified css and js files in staging environments and such as well.

Abandoned?

This project looks great but there's not much activity, there's a few issues and pull requests which need sorting out.. I've never used coffee-script before so I can't be of much help but perhaps someone would like to help update this project if epeli doesn't want to?

Debugging scripts in development environment

The Tag is created with currentTime

  getTagKey: ->
    if @production
      @pileHash
    else
      new Date().getTime()

So everytime reloading the page a new tag is generated and the breakpoints get removed.

'global' could be a reserved keyword for namespaces

I found that if you use global as a namespace string, it will render the tags 2 times.

client_js.addUrl("global", "https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js");   

res.render("assets/js_asset", {
  layout: false,
  js: client_js.renderTags("global")
});

Will output :

<script type="text/javascript"  src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js"  ></script>
<script type="text/javascript"  src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js"  ></script>

You should forbid us to use this string as a namespace by warning it's a reserved keyword or even forbid it totally

CSS LiveUpdate will update only once (bug?)

For me, the CSS LiveUpdate will update only once per file. Also, in the example "Full example Express 3.x".
Has anyone else the same problem?

Operating System:
Mac OS X (Unix; Intel processor)
node.js v0.8.16

Passing parameters ?

Hi,
is it possible to pass parameters to a to be loaded js file ?

eg, I like to load 3 files which depend on each other ?

~Marc

PRODUCTION mode minification problem (Express 4.2.0)

In Production mode using express 4.2.0 no content is returned to client (the script tag is added but there is no content from the server), I followed the problem and found it in piller.coffee ln 315:

    listener.on "listening", =>
      @pileUp()

listener is either app or server, I passed (app = require('express')()) but @pileup never get called; seems like listener has no on "listening".
I fix it by removing the on event and directly calling @pileup and everything seems to be ok, I get a minificated versions of my files and the webpage works great.

    #listener.on "listening", =>
    #  @pileUp()
    @pileUp()

Any idea or comments?

New maintainers wanted!

Unfortunately I don't have the time to maintain this project anymore. Please contact me if you are interested!

Production url

Getting this with express 3 in production. Works in development. Thoughts?

<link rel="stylesheet" href="/pile/min/undefined/global.css"  />

SyntaxError: Unexpected token ; when requiring piler

  1. I have an existing project using Express, and I installed piler in that project: 'npm install piler'
  2. Next I created a file testpiler.js with only the line 'var piler = require("piler");'
  3. I run the file 'nodemon testpiler.js'
  4. I get this error:

/Users/david.vismans/Documents/Aptana Studio 3 Workspace/Tetter/node_modules/piler/lib/livecss.coffee:87
var ;
^

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
SyntaxError: Unexpected token ;
at Module._compile (module.js:406:25)
at Object..coffee (/Users/david.vismans/Documents/Aptana Studio 3 Workspace/Tetter/node_modules/piler/node_modules/coffee-script/lib/coffee-script/coffee-script.js:21:21)
at Module.load (module.js:343:31)
at Function._load (module.js:302:12)
at require (module.js:355:19)
at Object. (/Users/david.vismans/Documents/Aptana Studio 3 Workspace/Tetter/node_modules/piler/lib/piler.coffee:610:21)
at Object. (/Users/david.vismans/Documents/Aptana Studio 3 Workspace/Tetter/node_modules/piler/lib/piler.coffee:636:4)
at Module._compile (module.js:411:26)
at Object..coffee (/Users/david.vismans/Documents/Aptana Studio 3 Workspace/Tetter/node_modules/piler/node_modules/coffee-script/lib/coffee-script/coffee-script.js:21:21)
at Module.load (module.js:343:31)

5 Dec 11:42:53 - [nodemon] app crashed - waiting for file change before starting...

Details:

  1. Running macos x 10.6.8
  2. Node version 0.4.12

Any idea?

CSSO css compression error

Compressing the css line:

background-image: radial-gradient(ellipse at center, rgb(90, 90, 255) 4%, #003 65%);

(through CSSO: the default css compressor in Piler) yields:

background-image: radial-gradient(ellipse at center,#5a5aff4%,#003 65%);

the rgb(...) is converted to a color has, but no space is permitted between that and the gradient block percentage.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.