assetgraph / assetgraph-builder Goto Github PK
View Code? Open in Web Editor NEWAssetGraph-based build system for web apps and web pages.
License: BSD 3-Clause "New" or "Revised" License
AssetGraph-based build system for web apps and web pages.
License: BSD 3-Clause "New" or "Revised" License
CSSO does minify better:
https://github.com/css/csso
The optimizepngs transform seems to make assetgraph lose track of the png relations.
When using --optimizepngs
in buildProduction
the resulting css links to the png assets with their original filename and not the md5 hashed filename in static.
This can be recreated in https://github.com/hojberg/cssarrowplease.git
Ideas:
pipeImageThroughChildProcessAndBuffer
thing.transforms.optimizePngs
and transforms.optimizeJpegs
shouldn't kick in if the same tool is already specified explicitly in the query string.@Munter, what do you think?
<!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
<div data-i18n="foo">Some <span>foo</span> thing</div>
{
"foo": {
"en": "Some {0} thing",
"da": "Some {0} {0} thing"
}
}
I'm pretty sure this will screw up because cloneNode
isn't used.
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 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.
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" />
Just roll it up with the rest of the bundled scripts.
Would also make it possible to switch to https://github.com/jrburke/almond in all projects that don't need a dynamic require.
I have a big project that breaks. Reduce to a test case and get it fixed.
look for the FIXME
Random idea for buildProduction:
Deduce the --root
-parameter from the topmost common parent directory of the given input HTML-files.
(Don't know if that makes sense in larger setups, though.)
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?
At least buildProduction
doesn't have an -h
/ --help
.
Could just be the same output as buildProduction --locale ...
gives you when default values don't match existing translations etc.
-ag-sprite-group
into a GET parameter so that different images mentioned in the same CSS rule can be added to different sprites<img src="foo.png?sprite=abc">
โ <img src="blank.png" style="background-image:url(sprite.png);background-position: ...">
Only if no urls are loaded using require.
This should probably be behind a command line switch as well.
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!
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.
passing --cdnroot //app.falconsocial.com
to buildProduction
fails
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'
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
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.
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...
/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).
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.
<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
var imgUrl = GETSTATICURL('images/test.png');
When building the above with CDN build, the image url doesn't get the CDN root prefixed.
If I reference an existing manifest file in my html document, will assetgraph-builder detect this, and modify the existing manifest or will it overwrite completely?
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
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:
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?
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
It would be nice to have a binary that could scrape a given remote web page so you could work on optimization locally.
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?
I would be nice with some guides for getting stared with the various parts of assetgraph. Eg.
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 {}
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.
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
Currently image post processing instructions are defined in -one-image-postprocess.
This has several drawbacks:
We should move the post processing instructions into the URL.
Discussion about cgi parametre syntax is appreciated
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. : (
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.