Code Monkey home page Code Monkey logo

assetgraph-builder's Introduction

AssetGraph-builder

NPM version Build Status Coverage Status Dependency Status

AssetGraph-based build system (mostly) for single-page web applications.

Looking for a Grunt integration? Try grunt-reduce

Quick start

Conventional

npm install -g assetgraph-builder
buildProduction path/to/your/index.html -o path/to/output/directory
docker run --rm -it  -v "$(pwd)":/app/ -w /app/ assetgraph/assetgraph-builder path/to/your/index.html -o path/to/output/directory

Congratulations, you just optimized your web page!

Features

  • Requires no build manifest. All information about your project is gathered from the HTML/CSS/JavaScript itself. Just tell it where to find your HTML file(s), and it will find the referenced JavaScript, CSS, etc.
  • Reads your web application from one directory, manipulates and optimizes it, then writes the resulting build to a separate directory with everything included.
  • Supports a multitude of asset/relation types, even shortcut icons, AlphaImageLoader images, conditional comments, fonts linked via @font-face { src: url(...) }, .htc files linked via CSS behavior properties.
  • Bundles JavaScript and CSS.
  • Discovers and optimizes Web Workers and Service Workers.
  • Removes duplicate images, JavaScript, CSS, etc.
  • Supports automatic optimization and custom processing of images using pngquant, pngcrush, optipng, jpegtran, sharp, and GraphicsMagick.
  • Minifies/packs JavaScript, CSS, and HTML (uses UglifyJS, cssnano, jsdom, and html-minifier).
  • Supports the the require.js optimizer and systemjs-builder.
  • Sprites background images (see assetgraph-sprite).
  • Inlines CSS background-images less than 8192 bytes and provides an alternative stylesheet for older IE versions via conditional comments.
  • Inlines CSS and JavaScript with total size less than 4096 bytes to reduce HTTP requests.
  • Adds a cache manifest to each HTML page if --manifest is specified.
  • Renames JavaScript, CSS, images etc. to a 10-char MD5 prefix + the original extension so they can be served with a far-future expiry time.
  • Helps getting your static assets on a CDN by rewriting the references to them (controlled by the --cdnroot switch).
  • Updates an existing Content-Security-Policy meta tag to reflect the changes that happened during the build procedure, including hashing of inline scripts and stylesheets.
  • Very customizable, the entire build script is only around 100 lines of code due to the reliance on high level AssetGraph transforms.
  • Automatically adds rel="noopener" to cross domain anchors opening in new windows (The performance benefits of rel=noopener)

Installation

Optional first step: To take full advantage of the image processing and optimization features, you need several libraries and command line utilities installed. On Ubuntu you can grab them all by running:

sudo apt-get install -y graphicsmagick inkscape

Or on OS X, with homebrew:

# Image manipulation
brew install graphicsmagick
brew install vips --with-webp --with-graphicsmagick

# SVG rengering with Inkscape
brew cask install xquartz
brew cask install inkscape

# Export PKG_CONFIG_PATH to make Inkscape work. Put this in your .profile or .bashrc
export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig

Then make sure you have node.js and npm installed, then run:

$ npm install -g assetgraph-builder

Now you'll have the buildProduction script in your PATH.

Usage

$ buildProduction -o outputPath [--root webrootPath] [startingAssets]

Assetgraph needs a web root to resolve URLs correctly. If you pass in the --root option assetgraph will use it, otherwise it will take a best guess based on your startingAssets.

The -o option tells assetgraph-builder where to write the built files to. If the directory does not exist it will be created for you.

Your startingAssets can be one or more file paths or minimatch patterns, which will be used as the starting point of assetgraphs automatic discovery process. The default is index.html, but you might also want to add any file here that is not linked to by your website, but still has to be a part of the build, for example robots.txt, .htaccess or 404.html. If one or more files are missing from your build, check that you are actually linking to them. If you are not, and it is by design, then you should add these files as input paths in startingAssets.

There are many more options to assetgraph-builder. We suggest you consult the help with buildProduction -h.

Example usage

Build a single page application:

buildProduction -o path/to/production --root path/to/dev path/to/dev/index.html

This will load path/to/dev/index.html, follow all local relations to JavaScript, CSS, etc., perform the above mentioned optimizations, then output the result to the directory path/to/production.

Create a CDN-enabled build:

buildProduction -o path/to/production --root path/to/dev path/to/dev/index.html \
                --cdnroot http://xxxxxx.cloudfront.net/static/cdn

This will produce a build that assumes that the contents of path/to/production/static/cdn are available at http://xxxxxx.cloudfront.net/static/cdn. We recommend putting the entire contents of path/to/production online and pointing your CloudFront (or other CDN provider) distribution at the root of your origin server. As long as you serve /static and everything below it with a far-future expires, you won't need to touch your CDN config or manually upload anything to your CDN provider.

Specifying which browsers to support

It's highly recommended that you tell buildProduction which browsers you need to support via the --browsers switch. It draws its syntax from the browserslist module and governs a wide range of tweaks and hacks, for example:

  • Whether the screw IE8 option is passed to UglifyJS.
  • The set of browsers autoprefixer is instructed to support, if autoprefixer is available.
  • Whether to add fallback stylesheets referenced via conditional comments when images are inlined in CSS (due to IE7 not supporting data: urls and IE8's 32 KB data: url limit).

The default is to support all browsers, which will cause a heavier build, especially when IE8 and below are included and inlining of CSS images is active (which it is by default). If you're lucky enough that you don't need to support those browsers, you can add --browsers ">0%, not ie <= 8" and avoid those hacks.

Replacing require.js with almond.js on build

Simply add a data-almond-attribute to the script tag that has require.js as its source. The value should be the path to almond.js like so:

<script
  data-main="app/main"
  data-almond="path/to/almond.js"
  src="path/to/require.js"
></script>

When you do this you should not use require as an external script loader, since almond does not support this.

Working with a Content Security Policy

If you add the --contentsecuritypolicy switch and one or more of your HTML files contain a CSP in a meta tag such as:

<meta
  http-equiv="Content-Security-Policy"
  content="default-src 'self'; script-src foo.com"
/>

it will be read and updated to reflect the changes that were made during the build. This includes whitelisting your CDN, adding image-src data: if images are inlined, and generating hashes for inline scripts and stylesheets if your policy does not allow 'unsafe-inline'.

You can extract the resulting CSPs from the build and add it to your web server's config, or use something like express-extractheaders to also send the CSP as a response header.

We encourage a workflow like this so that the CSPs of your project are also in effect in your development setup, as that will help catch bugs early.

Tip: If you want to use inline scripts and stylesheets in your development setup, yet don't want to allow 'unsafe-inline' in your policy, you can use a nonce in development:

<!DOCTYPE html>
<html>
  <head>
    <meta
      http-equiv="Content-Security-Policy"
      content="script-src 'nonce-yeah', style-src 'nonce-yeah'"
    />
    <style rel="stylesheet" nonce="yeah">
      body {
        color: red;
      }
    </style>
  </head>
  <body>
    <script nonce="yeah">
      alert('Hello');
    </script>
  </body>
</html>

buildProduction --contentsecuritypolicy will upgrade the nonce to a hash token if the scripts and stylesheets are still inline when the bundling/externalization steps have been carried out.

Sub resource integrity

The --subresourceintegrity switch will make buildProduction add an integrity attribute to every <script src=...> and <link rel="stylesheet" href=...> that points at an asset that is part of the build. Note that this excludes references to assets that are already located on a CDN, or indeed any http:// url. If you want to lock down such dependencies, please use the bundled addIntegrityToForeignRelations tool or compute the hash yourself and add it to your development HTML manually, for instance:

<script src="https://code.jquery.com/jquery-2.2.3.min.js"
     integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo="</script>

The reason why this isn't automated is that buildProduction cannot know if a given external resource might change in the future, thus breaking your production build.

Excluding assets from your build

If you want buildProduction to avoid including specific assets, paths or entire parts of your page, you can use the --exclude option.

This could come in handy if you have multiple different sections on your site, where assetgraph-builder only handles a subset of them. If the assetgraph-builder covered section of site links to sections that it shouldn't handle, this is where you use --exclude

--exclude can be used multiple times in the same command line to specify more than one pattern.

Exclude patterns are always prefixed with process.cwd(), making the path addressable in the same manner as the entry point arguments.

You may use * for wildcards.

Image optimization and processing

The buildProduction switch --optimizeimages turns on automatic lossless optimization of all images of the relevant type in the graph.

Additionally, you can specify individual processing instructions for each image using custom GET parameters. For example you might want to reduce the palette of an image to a specific number of colors or apply a specific compression level:

<img src="myImage.png?pngquant=37" />
<img src="myOtherImage.png?optipng=-o7&amp;pngcrush=-rem+tEXT" />

The image processing is supported everywhere you can refer to an image, including background-image properties in CSS, shortcut icon links etc.

Additionally, all GraphicsMagick operations (as exposed by the gm module) are supported:

body {
  background-image: url(foo.png?resize=500 + 300&flip&magnify&pngcrush);
}

These are especially useful for responsive images:

<img
  srcset="
    bar.jpg                                                1024w,
    bar.jpg?resize=600                                      600w,
    bar.jpg?resize=500&amp;gravity=Center&amp;crop=300+300  300w
  "
  sizes="(min-width: 768px) 50vw, 100vw"
/>

They work in JavaScript too:

var img = document.querySelector('.responsive-image');
img.setAttribute(
  'srcset',
  'baz.gif'.toString('url') +
    ' 500w, ' +
    'baz.gif?resize=300'.toString('url') +
    ' 300w'
);
picturefill({ elements: [img] }); // reload if you're using Picturefill

This allows you to only check your original images into version control and have your build system create the scaled/processed/derived ones dynamically.

The processing instructions are executed using the same engine that powers express-processimage and livestyle with the --processimage switch. You can use one of those to have the image processing instructions applied on your development setup.

License

AssetGraph-builder is licensed under a standard 3-clause BSD license -- see the LICENSE-file for details.

assetgraph-builder's People

Contributors

alexjeffburke avatar cybear avatar danielruf avatar depfu[bot] avatar greenkeeperio-bot avatar gustav-olsen-groupone avatar gustavnikolaj avatar guybedford avatar munawwar avatar munter avatar mwoc avatar noahlaux avatar papandreou avatar salomvary avatar saulshanabrook avatar silvenon avatar sunesimonsen avatar tenzer avatar

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  avatar  avatar  avatar  avatar

assetgraph-builder's Issues

Image identity lost on image postprocessing

If I have two selectors using tha same background image and I set postproccessing instructions on both of them, assetgraph will make two copies of the image.

Possible solutions:

  • Keep identity and run all transforms in order
  • Warn about multiple transforms on the same image

buildProduction doesn't understand UMD

When defining a module in a cross module compatible way using https://github.com/umdjs/umd buildProduction builds requirejs modules wrong.

This module:

(function (root, factory) {
    if (typeof module !== "undefined") {
        module.exports = factory();
    } else if (typeof root.define === 'function' && define.amd) {
        define(factory);
    } else {
        root.one = root.one || {};
        root.one.validation = factory();
    }
}(this, function () {
    return true;
}));

is built into:

(function(root, factory) {
    if (typeof module !== "undefined") {
        module.exports = factory();
    } else if (typeof root.define === "function" && define.amd) {
        define(factory);
    } else {
        root.one = root.one || {};
        root.one.validation = factory();
    }
})(this, function() {
    return true;
});

define("vendor/test", function() {});

Since there are more end more modules out there targeting multiple module definitions and falling back to vanilla js using the factory pattern, this is a showstopper when using vendor modules.

ping @papandreou

buildProduction --version without previous content-version element

When running buildProduction on html that hasn't been generated by buildDevelopment, the meta tag describing the current version ends up being <meta http-equiv="Content-Version" content="/production" />

Where there should have been a version number there is nothing.

any advice on handling dynamic html fragments?

first of all, this tool is freaking sweet. thanks for releasing it!

I'm wondering how I handle the sections of html that are loaded dynamically. For example, in my single page app when a user views a new page the front end requests an html template from the server, renders it, and fetches the resources (mostly images) used in the template. But because this happens at run time assetgraph-builder never picks up these linkages and so all of my sub pages are still llinking to resources served from my web server. Any ideas on how to fix this?

It's not a huge problem because most of the resources load on the first page anyway. It would just be super nice if 100% of my static content was hitting the cdn.

thanks again for awesome software!

Make buildProduction independent og buildDevelopment

Currently buildDevelopment and buildProduction populate the graph in different ways.

buildProduction assumes that buildDevelopment has already added script and css includes from one.include into the html, and is told to ignore these inclusions.

It would be nice if buildProduction wasn't chained to buildDevelopment

If buildProduction followed JavaScriptOneInclude, JavaScriptExtJsRequire and JavaScriptCommonJsRequire relations during population and the build was based on the output of buildDevelopment, wouldn't assetgraph notice that the assets are identical and merge them?

https://github.com/One-com/assetgraph-builder/blob/master/bin/buildDevelopment#L36-39
https://github.com/One-com/assetgraph-builder/blob/master/bin/buildProduction#L145-146

calling buildProduction on front end using requirejs fails

I've tried running assetgraph-builder against my requirejs backed code. I've run into some build problems:

Here is my the line from my index.html which includes require.js:

<script src="/js/vendor/requirejs/require.js" data-main="/js/app"></script>

According to requirejs documentation, the basePath should now be set to /js. Instead it seems like it's being set to the index.html directory (I'm assuming it's just using what I set for --outroot.) Here's some parts of my requirejs config (from /js/app.js):

# sets the require.js configuration for the application
require.config {
    paths:
        backbone         : 'vendor/backbone-amd/backbone' 
        deepmodel        : 'vendor/deep-model'
        ...
}

My project directory structure:

|- dist/
|- public/
   |- index.html
   `- js/
      |- app.js
      `- vendor/
         |- backbone-amd/
         |  `- backbone.js
         |- deep-model.js
         `- requirejs/
            `- require.js

My build command:

cd projectdir
buildProduction --outroot dist/ --root public/ public/index.html

Here are some of the errors I'm seeing:

file:///root/hellosprout/public/vendor/backbone-amd/backbone.js: ENOENT, open '/root/hellosprout/public/vendor/backbone-amd/backbone.js'
Including assets:
    file:///root/hellosprout/public/js/app.js

file:///root/hellosprout/public/vendor/deep-model.js: ENOENT, open '/root/hellosprout/public/vendor/deep-model.js'
Including assets:
    file:///root/hellosprout/public/js/models/cart.js

assetgraph-builder breaks absolute paths for css and js resources

My site has a deep hierarchy of paths, so I use absolute paths In my index.html:

<link href="/css/style.css" rel="stylesheet">
<script src="/js/vendor/modernizr/modernizr.js"></script>

I run buildProduction --outroot dist/ --root public/ public/index.html
which generates an index.html file that contains this:

<link rel="stylesheet" href="static/f01f97329c.css" /
<script src="static/8b4984bcd4.js">

Notice how my absolute paths have been turned into relative paths? This breaks my site when I'm viewing a page that isn't at the root level. For example, http://foo.com works, but http://foo.com/bar breaks because it expects the resources to be in /bar/static

However, the image references are still preserved as being absolute:

<img src="/static/3c7df4a3bc.png" alt="HelloSprout" title="HelloSprout" style="background:#fff" />

Strange errors when missing dependencies

When forgetting to install all the dependencies to run assetgraph (say, pngquant), it results in a Error: EPIPE, Broken Pipe:

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
Error: EPIPE, Broken pipe
    at Socket._writeImpl (net.js:159:14)
    at Socket._writeOut (net.js:444:25)
    at Socket.write (net.js:377:17)
    at pipeThroughChildProcessAndBuffer (.../node_modules/assetgraph-builder/node_modules/assetgraph/lib/transforms/postProcessBackgroundImages.js:22:24)
    at .../node_modules/assetgraph-builder/node_modules/assetgraph/lib/transforms/postProcessBackgroundImages.js:42:13
    at proceed (.../node_modules/assetgraph-builder/node_modules/assetgraph/lib/transforms/postProcessBackgroundImages.js:103:13)
    at applyFilters (.../node_modules/assetgraph-builder/node_modules/assetgraph/lib/transforms/postProcessBackgroundImages.js:111:5)
    at Function.<anonymous> (.../node_modules/assetgraph-builder/node_modules/assetgraph/lib/transforms/postProcessBackgroundImages.js:147:17)
    at Function.<anonymous> (.../node_modules/assetgraph-builder/node_modules/seq/index.js:238:28)
    at action (.../node_modules/assetgraph-builder/node_modules/seq/index.js:76:11)
make: *** [http-pub-production] Error 1

Ideally, this should be converted into a friendly reminder that forgetful developers should install all the dependencies...

is there a way to force assetgraph-builder to process script tags as html templates?

I'm using backbonejs in one of my apps, and have several script tags that contain html templates. Here's an example of one of the template scripts, embedded in my index.html:

<script type="text/template" id="about-template">
        <h1>welcome back, <%- username %>!
        <img src="img/icn-logo.png" class="whim-logo" alt="logo" />
</script>

in my backbone view, I basically load this as you might expect:

data = $('#about-template').html()
template = _.template data
$('#about').html @template( { username: 'mike' } )

Is there some way I can use the GETSTATICURL to cause these references to be satisfied?

I'm sorry to keep flooding you folks with github issues. : (

[email protected] is throwing a fatal error

0.001 secs: registerRequireJsConfig
0.005 secs: registerLabelsAsCustomProtocols

/usr/lib/node_modules/assetgraph-builder/bin/buildProduction:280
            throw err;
                  ^
TypeError: loadAssets transform: Parameter 'url' must be a string, not undefined
    at Url.parse (url.js:118:11)
    at urlParse (url.js:112:5)
    at Object.urlResolve [as resolve] (url.js:402:10)
    at Object.urlTools.resolveUrl (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/util/urlTools.js:178:24)
    at Object.requireJsConfig.resolveUrl (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/transforms/registerRequireJsConfig.js:37:29)
    at Html.extendWithGettersAndSetters.findOutgoingRelationsInParseTree (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/assets/Html.js:244:71)
    at Html.outgoingRelations (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/assets/Asset.js:538:44)
    at Html.extendWithGettersAndSetters.populate (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/assets/Asset.js:583:17)
    at AssetGraph._.extend.addAsset (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/AssetGraph.js:161:15)
    at /usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/transforms/loadAssets.js:37:44
assetgraph-builder optimization failed. code: 8

Missing copyright header in minified javascript

Thanks for a great tool!

When i run

./node_modules/assetgraph-builder/bin/buildProduction --outroot dir \
  --root anotherdir --version `git log --pretty=format:'%h' -n 1` -less true 

Everything works as expected except for that I don't the copyright headers is stript from the minified js file. Is this by design (are there a way to get the copyright headers?) If not I would regard this as an bug.

why is upgrading from 1.4.0 to 1.4.1 breaking my deployment?

When I run assetgraph-builder with 1.4.1 or 1.4.2, I see this error in my output:

3.544 secs: populate
0.001 secs: fixBaseAssetsOfUnresolvedOutgoingRelationsFromHtmlFragments
0.064 secs: populate
0.001 secs: removeRelations
0.000 secs: removeRelations
0.004 secs: convertCssImportsToHtmlStyles

/usr/lib/node_modules/assetgraph-builder/bin/buildProduction:274
            throw err;
                  ^
Error: buildProduction transform: externalizeRelations transform: recomputeBaseAssets: Couldn't find base asset for [HtmlImage/98: [Html/2 file:///root/bytesamurai/web/public/templates/landing.html] => /img/preview/tab-slide1.png]
    at AssetGraph._.extend.recomputeBaseAssets (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/AssetGraph.js:424:27)
    at Array.forEach (native)
    at AssetGraph._.extend.recomputeBaseAssets (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/AssetGraph.js:421:55)
    at JavaScript.url (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/assets/Asset.js:453:37)
    at module.exports (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/transforms/externalizeRelations.js:8:33)
    at Array.forEach (native)
    at externalizeRelations (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/transforms/externalizeRelations.js:6:44)
    at _.extend._runTransform.callbackCalled (/usr/lib/node_modules/assetgraph-builder/node_modules/assetgraph/lib/AssetGraph.js:648:21)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

and here is my build command:

shell.exec 'buildProduction --optimizeimages --outroot '+tmp_dir+' --root web/public web/public/index.html web/public/te
mplates/landing.html web/public/templates/features.html web/public/templates/support.html --cdnroot '+cdn_host

What gives? This is really, really bad. I'm assuming that the API has changed between 1.4.0 and 1.4.1 in a breaking way?

You guys really need to follow semantic versioning carefully. http://semver.org
patch numbers are intended to be patches. You can't destabilize your API in a patch release.

Translation inserts whitespaces

I have the following html

                                <label for="login-email"><span data-i18n="email">Email</span>:</label>

This builds into

<label for="login-email">
                  Email
:</label>

Somewhere along the way in the build process two newlines and an indentation got added to the html.

I am assuming this is caused by the html being prettyprinted along the way, then translated, then minified, but since the span is replaced with a textnode the minifier can't make assumtions on collapsing white spaces.

Ideally these whitespaces should not be there. And I can't make head or tails of the number of them. I indented with 32 spaces and the reult is indented by 18

buildProduction doesn't complain about no input files

In the help text to buildProduction (eg. run without parameters), htmlFile(s) are considered mandatory:

node ./node_modules/.bin/buildProduction --root <inputRootDirectory> --outroot <dir> [options] <htmlFile(s)>

But the program doesn't complain when no files are given. It just work through an empty graph.

I believe adding a .demand(1) in the optimist-chain will suffice.

--cdnroot can't contain protocol relative urls

passing --cdnroot //app.falconsocial.comto buildProductionfails

From my Makefile:

CDN:=//app.falconsocial.com/static

production/%.html: http-pub/%.html.template $(DEPS) node_modules/.bin/buildProduction
    rm -rf $(@D)
    buildProduction \
        --root $(<D) \
        --outroot $(@D) \
        --optimizepngs \
        --version $(VERSION) \
        --asyncscripts \
        --locale $(LOCALE) \
        --cdnroot $(CDN) \
        --cdnoutroot $(@D)/static \
        $<

Assetgraph fails with: Error: EACCES, mkdir '/app.falconsocial.com'

Knockout templates included twice

buildProduction gives me this error:

Error: bundleRequireJs: More than one of the loaded Knockout.js templates have the file name samples.ko, so they will overwrite each other in the ko.externalTemplateEngine.templates hash. Please disambiguate by changing at least one of the file names.

The reason is that I'm depending on knockout templates using the requirejs tpl!-notation.
Two different views depend on the same template. So it's not a name clash. Assetgraph just doesn't seem to realize that the two templates are the same file.

--locale kills 'nobundle' attribute

<!doctype html>

<html>
    <head>
        <script nobundle="nobundle">
            // navigation timing script
            var foo = new Date();
        </script>
    </head>

    <body>
        <script src="application.js"></script>

        <script nobundle="nobundle">
            // navigation timing script
            var bar = new Date();
        </script>
    </body>
</body>

Building the above with buildProduction --locale en_US bundles the script with the nobundle attribute

Adapt spriting syntax/features to match transforms.processImages

  • Turn -ag-sprite-group into a GET parameter so that different images mentioned in the same CSS rule can be added to different sprites
  • Explore whether this syntax change makes the spriting applicable to sprite images referred to from eg. HTML. Eg. <img src="foo.png?sprite=abc"> โ‡’ <img src="blank.png" style="background-image:url(sprite.png);background-position: ...">
  • Find out whether to reintroduce the possibility of processing sprited images after they have been generated

Move image postrprocessing instructions to image url

Currently image post processing instructions are defined in -one-image-postprocess.

This has several drawbacks:

  • Only CSS images can be post processed
  • Elements may contain multiple backgrounds that shouldn't have identical postprocessing

We should move the post processing instructions into the URL.

Requirements

  • CGI parametres (dynamic images are 404 on file systems anyway, and this would enable middleware to show the post processed image in developmetn mode)
  • buildProduction should remove all the cgi parametres it understands when post processing
  • The same image referenced several time with identical post processing should be treated as one image
  • The same image with different postprocessing should be split into two different images and throw a command line warning
  • -one-image-postprocess should be deprecated
  • Order of cgi parametres should be significant

Discussion about cgi parametre syntax is appreciated

relations pointing to non-existing assets should not be added to the manifest file and shouldn't break the build process

I have a special case in my index.html file; there is one javascript that is specified as:

<script src="user"></script>

this points at a purposely non-existent static file, which forces it to be loaded from the API. so there is no file named 'user' in my assets directory. This causes buildProduction to break.

What I need is a way to provide some hinting and tell assetgraph builder "leave this one alone in the index.html file. just ignore it."

any ideas?

Localize CSS

Clone the asset for each locale and remove or keep CSS rules whose selectors match on <html lang="...">.

For American English that would turn

html[lang="en"] .myThing { width: 123px; }

into

.myThing { width: 123px; }

... but for non-English locales the rule would be removed.

Maybe also add a syntax for localizing the content property.

Any other ideas?

How to not combine inline script tags?

<head>
  <script>
    // 1
  </script>
<head>

<body>
  <script>
    // 2
  </script>
</body>

becomes:

<head>
  <script>
    // 1
    // 2
  </script>
<head>

<body>
</body>

I think there should be an option to cancel this behaviour.

Is there a workaround?

Any pointers on where to look to implement a fix.

Thanks loads

Guides for getting started

I would be nice with some guides for getting stared with the various parts of assetgraph. Eg.

  • Getting started with a basic static site.
  • Using LESS in development/production.
  • ...

Missing less dependency

/home/munter/git/falcon-client-html/node_modules/assetgraph-builder/node_modules/assetgraph/lib/transforms/compileLessToCss.js:12
        throw new Error('transforms.compileLessToCss: The "less" module is req
              ^
Error: transforms.compileLessToCss: The "less" module is required. Please run "npm install less" and try again (tested with version 1.2.1).

assetgraph-builder installation fails on windows7 due to canvas dependency

I'm trying to install assetgraph-builder on windows7 but the installation fails due to failure to install canvas (error text below). I understand canvas is required for assetgraph-sprite and it can't be installed on windows as it needs native compilation. Can the assetgraph-sprite dependency be made optional so that the rest of the build system can be used on windows?

[email protected] preinstall C:\Users\omkar.patil\AppData\Roaming\npm\node_modules\assetgraph-sprite\n
ode_modules\canvas
node-waf configure build

'node-waf' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! error installing [email protected]
npm ERR! error installing [email protected]

npm ERR! [email protected] preinstall: node-waf configure build
npm ERR! cmd "/c" "node-waf configure build" failed with 1
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the canvas package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure build
npm ERR! You can get their info via:
npm ERR! npm owner ls canvas
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (x86)\nodejs\nod
e_modules\npm\bin\npm-cli.js" "install" "-g" "assetgraph-sprite"
npm ERR! cwd C:\work\workspaces\sublime\coffeescript\gnie
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] preinstall: node-waf configure build
npm ERR! message cmd "/c" "node-waf configure build" failed with 1
npm ERR! errno {}

Create a saveWebpage binary

It would be nice to have a binary that could scrape a given remote web page so you could work on optimization locally.

file not found errors for a couple js scripts when calling buildProduction

Here is my command:

buildProduction --optimizeimages --outroot '+tmp_dir+' --root web/public web/public/index.html  --cdnroot '+cdn_host

And here's the output:

0.000 secs: registerRequireJsConfig
0.002 secs: registerLabelsAsCustomProtocols
0.127 secs: loadAssets
file:///root/whim/web/public/user.js: ENOENT, open '/root/whim/web/public/user.js'
Including assets:
    file:///root/whim/web/public/index.html

file:///root/whim/web/public/underscore.js: ENOENT, open '/root/whim/web/public/underscore.js'
Including assets:
    file:///root/whim/web/public/js/vendor/backbone-deep-model-0.8.0.js

file:///root/whim/web/public/backbone.js: ENOENT, open '/root/whim/web/public/backbone.js'
Including assets:
    file:///root/whim/web/public/js/vendor/backbone-deep-model-0.8.0.js

1.974 secs: populate
0.001 secs: removeRelations
0.000 secs: removeRelations
0.001 secs: convertCssImportsToHtmlStyles
0.006 secs: externalizeRelations
0.003 secs: mergeIdenticalAssets
0.093 secs: processImages
assetgraph-sprite: Canvas not found, skipping
0.000 secs: spriteBackgroundImages
0.679 secs: processImages
0.010 secs: inlineKnockoutJsTemplates
0.011 secs: bundleRequireJs
0.000 secs: removeDuplicateHtmlStyles
0.009 secs: bundleRelations
0.021 secs: bundleRelations
0.000 secs: removeNobundleAttribute
0.146 secs: inlineCssImagesWithLegacyFallback
0.168 secs: minifyAssets
0.000 secs: removeAssets
0.001 secs: removeAssets
2.351 secs: compressJavaScript
0.164 secs: inlineRelations
0.004 secs: inlineAngularJsTemplates
0.002 secs: inlineKnockoutJsTemplates
0.000 secs: setAsyncOrDeferOnHtmlScripts
0.000 secs: omitGetStaticUrlFunctionCall
0.000 secs: inlineRelations
0.051 secs: moveAssetsInOrder
5.811 secs: buildProduction
0.004 secs: writeAssetsToDisc
0.030 secs: writeAssetsToDisc
      Html  1   3.1 KB
       Png  5   8.8 KB
       Gif  1  12.2 KB
       Xml 19  91.0 KB
       Css  2  48.0 KB
JavaScript  2 136.3 KB
    Total: 30 299.5 KB
0.001 secs: writeStatsToStderr

I see 3 errors. The first one is expected because web/public/user.js is intentionally missing from my static resources (forces it to be pulled from API at run time)

However the two other errors seem strange. (backbone.js and underscore.js)

I have these 2 files in my public/ directory:

public/
|- js/
    `- vendor/
        |- backbone-0.9.2.min.js
        `- underscore-1.3.3.min.js

and here are my script declarations in index.html:

<script src="js/vendor/underscore-1.3.3.min.js"></script> 
<script src="js/vendor/backbone-0.9.2.min.js"></script>

any idea why this is happening?

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.