diff --git a/rpg-docs/.gitignore b/rpg-docs/.gitignore index 0a2052ca..70af0f43 100644 --- a/rpg-docs/.gitignore +++ b/rpg-docs/.gitignore @@ -1,7 +1,6 @@ .meteor/local .meteor/meteorite .demeteorized -packages settings.json public/components nohup.out diff --git a/rpg-docs/packages/meteor-vulcanize/.versions b/rpg-docs/packages/meteor-vulcanize/.versions new file mode 100644 index 00000000..26911b9d --- /dev/null +++ b/rpg-docs/packages/meteor-vulcanize/.versions @@ -0,0 +1,3 @@ +differential:vulcanize@0.0.5 +meteor@1.1.6 +underscore@1.0.3 diff --git a/rpg-docs/packages/meteor-vulcanize/README.md b/rpg-docs/packages/meteor-vulcanize/README.md new file mode 100644 index 00000000..b4149d18 --- /dev/null +++ b/rpg-docs/packages/meteor-vulcanize/README.md @@ -0,0 +1,29 @@ +Vulcanize +============================================================================== +This package a meteor build plugin that wraps the [vulcanize](https://www.npmjs.com/package/vulcanize) npm package, which is used to process web components into a single output file. + +### Usage +1. Ensure all your components are located somewhere under your public directory. +2. Include an `imports.html` file anywhere available to the client, that contains the html imports that would normally go inside your `
` tag. + +```` + + + + + + +... + + + + + +... +```` + +- Running your app in development as usual will result in the contents of `imports.html` being added to your `` tag, resulting in multiple subsequent HTTP requests (good in development - debugging). + +- Running `meteor`, `meteor build`, `modulus deploy`, etc with the `VULCANIZE=true` environment variable set will result in all your html imports being vulcanized or concatenated into a single html import (good in production). The resulting file will be called `vulcanized.html`, which will be automatically added to your `` tag. For example, `VULCANIZE=true meteor`, `VULCANIZE=true modulus deploy`. + +- Setting the `CDN_PREFIX` environment variable will prepend the string to the beginning of the file path that is inserted into your HTML's `` tag. diff --git a/rpg-docs/packages/meteor-vulcanize/package.js b/rpg-docs/packages/meteor-vulcanize/package.js new file mode 100644 index 00000000..464b3682 --- /dev/null +++ b/rpg-docs/packages/meteor-vulcanize/package.js @@ -0,0 +1,15 @@ +Package.describe({ + name: 'thaum:vulcanize', + summary: 'Vulcanize', + version: '0.0.5', + git: 'https://github.com/Differential/meteor-vulcanize' +}); + +Package.registerBuildPlugin({ + name: 'vulcanize', + use: [], + sources: [ + 'vulcanize.js' + ], + npmDependencies: {'vulcanize': '0.7.11'} +}); diff --git a/rpg-docs/packages/meteor-vulcanize/versions.json b/rpg-docs/packages/meteor-vulcanize/versions.json new file mode 100644 index 00000000..dd13098b --- /dev/null +++ b/rpg-docs/packages/meteor-vulcanize/versions.json @@ -0,0 +1,20 @@ +{ + "dependencies": [ + [ + "meteor", + "1.1.3" + ], + [ + "underscore", + "1.0.1" + ] + ], + "pluginDependencies": [ + [ + "vulcanize", + {} + ] + ], + "toolVersion": "meteor-tool@1.0.35", + "format": "1.0" +} \ No newline at end of file diff --git a/rpg-docs/packages/meteor-vulcanize/vulcanize-tests.js b/rpg-docs/packages/meteor-vulcanize/vulcanize-tests.js new file mode 100644 index 00000000..c5623d89 --- /dev/null +++ b/rpg-docs/packages/meteor-vulcanize/vulcanize-tests.js @@ -0,0 +1,5 @@ +// Write your tests here! +// Here is an example. +Tinytest.add('example', function (test) { + test.equal(true, true); +}); diff --git a/rpg-docs/packages/meteor-vulcanize/vulcanize.js b/rpg-docs/packages/meteor-vulcanize/vulcanize.js new file mode 100644 index 00000000..ce452788 --- /dev/null +++ b/rpg-docs/packages/meteor-vulcanize/vulcanize.js @@ -0,0 +1,70 @@ +var vulcan = Npm.require('vulcanize'); +var crypto = Npm.require('crypto'); +var url = Npm.require('url'); + +var _ = Npm.require('underscore'); + +var handler = function(compileStep) { + var importsHtml = compileStep.read().toString('utf8'); + + if (process.env.VULCANIZE) { + log('Vulcanizing imports...'); + vulcanize(compileStep, importsHtml); + } else { + log('Adding all imports...'); + addImports(compileStep, importsHtml); + } + +}; + +var vulcanize = function(compileStep, importsHtml) { + + var vulcanOutputHandler = function(filename, data) { + + var filenameHash = crypto.createHash('md5').update(data).digest('hex'); + var filePath = '/vulcanized-' + filenameHash + '.html'; + + compileStep.addAsset({ + path: filePath, + data: data + }); + + if (_.isString(process.env.CDN_PREFIX)) { + filePath = url.resolve(process.env.CDN_PREFIX, filePath); + } + + compileStep.addHtml({ + section: 'head', + data: '' + }); + }; + + vulcan.setOptions({ + inputSrc: importsHtml, + outputHandler: vulcanOutputHandler, + abspath: 'public', + strip: true + }, function(error) { + if (error) { + log(error); + } else { + vulcan.processDocument(); + } + }); + +}; + +var addImports = function(compileStep, importsHtml) { + compileStep.addHtml({ + section: 'head', + data: importsHtml + }); +}; + +var log = function() { + args = _.values(arguments); + args.unshift("Vulcanize:"); + console.log.apply(this, args); +}; + +Plugin.registerSourceHandler("imports.html", handler);