{"action":"created","issue":{"url":"https://api.github.com/repos/systemjs/systemjs/issues/1001","labels_url":"https://api.github.com/repos/systemjs/systemjs/issues/1001/labels{/name}","comments_url":"https://api.github.com/repos/systemjs/systemjs/issues/1001/comments","events_url":"https://api.github.com/repos/systemjs/systemjs/issues/1001/events","html_url":"https://github.com/systemjs/systemjs/issues/1001","id":124816618,"number":1001,"title":"Question: How to approach adding minification to handlebars plugin?","user":{"login":"MeoMix","id":1380995,"avatar_url":"https://avatars.githubusercontent.com/u/1380995?v=3","gravatar_id":"","url":"https://api.github.com/users/MeoMix","html_url":"https://github.com/MeoMix","followers_url":"https://api.github.com/users/MeoMix/followers","following_url":"https://api.github.com/users/MeoMix/following{/other_user}","gists_url":"https://api.github.com/users/MeoMix/gists{/gist_id}","starred_url":"https://api.github.com/users/MeoMix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MeoMix/subscriptions","organizations_url":"https://api.github.com/users/MeoMix/orgs","repos_url":"https://api.github.com/users/MeoMix/repos","events_url":"https://api.github.com/users/MeoMix/events{/privacy}","received_events_url":"https://api.github.com/users/MeoMix/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/systemjs/systemjs/labels/support","name":"support","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-04T18:55:41Z","updated_at":"2016-01-09T17:29:11Z","closed_at":null,"body":"Heya,\r\n\r\nI was looking into this a bit and posted on the Gitter channel, but thought it would be prudent to post a full-fledged question here.\r\n\r\nI'm hoping to add two features to the Handlebars plugin. I suspect one of them will be 'free' once I know how to do the other:\r\n\r\n- Add support for minification of templates using https://github.com/kangax/html-minifier\r\n- Add support for relative URL paths within templates.\r\n\r\nHere's what the Handlebars plugin currently looks like:\r\n\r\n```\r\n'use strict';\r\n\r\nimport Handlebars from 'handlebars';\r\n\r\nconst handlebarsRuntimePath = System.normalizeSync('handlebars/handlebars.runtime', __moduleName);\r\n\r\nexport function translate(load) {\r\n  var precompiled = Handlebars.precompile(load.source);\r\n  load.source = `module.exports = require('${handlebarsRuntimePath}').template(${precompiled});`;\r\n}\r\n```\r\n\r\nMy initial confusion arises from the use of `translate`. I've only worked with `css` and `jspm-loader-css` plugins thus far. Both of these plugins make use of `fetch` and `bundle` rather than `translate`. After reading the (sparse) [documentation](https://github.com/systemjs/systemjs/blob/master/docs/creating-plugins.md) I'm only slightly less confused. The docs don't mention bundle at all. They imply you need to use `translate` to inline into bundles, but that's what `bundle` does, right? So, I'm a bit lost there.\r\n\r\nRegardless, that's not the real issue.\r\n\r\nSo, the above code takes source, precompiles it, and overwrites source with a Handlebars template function using the precompiled html. It needs to do this before `bundle` because the template function will be used in development.\r\n\r\nWhen the `bundle` hook is ran... it's difficult and hacky to extract the precompiled HTML. I was thinking I could create a Map which maps some unique identifier (load.source...? module name?) to the precompiled HTML. Then, in `bundle`, I could minify the pre-compiled HTML and swap out the existing precompiled html in `load.source`... but that might have bugs in it and feels really ass-backwards.\r\n\r\nHow should I be approaching this? Should this be broken up into fetch/bundle? Thanks!\r\n\r\nCC @davis "},"comment":{"url":"https://api.github.com/repos/systemjs/systemjs/issues/comments/170261669","html_url":"https://github.com/systemjs/systemjs/issues/1001#issuecomment-170261669","issue_url":"https://api.github.com/repos/systemjs/systemjs/issues/1001","id":170261669,"user":{"login":"MeoMix","id":1380995,"avatar_url":"https://avatars.githubusercontent.com/u/1380995?v=3","gravatar_id":"","url":"https://api.github.com/users/MeoMix","html_url":"https://github.com/MeoMix","followers_url":"https://api.github.com/users/MeoMix/followers","following_url":"https://api.github.com/users/MeoMix/following{/other_user}","gists_url":"https://api.github.com/users/MeoMix/gists{/gist_id}","starred_url":"https://api.github.com/users/MeoMix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MeoMix/subscriptions","organizations_url":"https://api.github.com/users/MeoMix/orgs","repos_url":"https://api.github.com/users/MeoMix/repos","events_url":"https://api.github.com/users/MeoMix/events{/privacy}","received_events_url":"https://api.github.com/users/MeoMix/received_events","type":"User","site_admin":false},"created_at":"2016-01-09T17:29:11Z","updated_at":"2016-01-09T17:29:11Z","body":"I will! Going to take a look at this today.\n\nOn Sat, Jan 9, 2016 at 9:21 AM, Guy Bedford <notifications@github.com>\nwrote:\n\n> Let me know if you have any further questions here at all.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/systemjs/systemjs/issues/1001#issuecomment-170261229>.\n>\n"}}