Permalink
Browse files

Create sample in-repo addon to explain how browser specific imports f…

…rom app need to work in FastBoot
  • Loading branch information...
kratiahuja committed Jul 7, 2017
1 parent 243fd47 commit 8874fe35575ddfa8d3f63dd9b3b7e65aa2b7dc68
Showing with 569 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +6 −0 bower.json
  3. +1 −0 jsconfig.json
  4. +52 −0 lib/fastboot-import/index.js
  5. +12 −0 lib/fastboot-import/package.json
  6. +491 −0 lib/fastboot-import/yarn.lock
  7. +6 −1 package.json
View
@@ -7,6 +7,7 @@
# dependencies
/node_modules
/bower_components
/lib/fastboot-import/node_modules
# misc
/.sass-cache
View
@@ -0,0 +1,6 @@
{
"name": "sample-in-repo-fastboot",
"dependencies": {
"slick-carousel": "1.6.0"
}
}
View
@@ -0,0 +1 @@
{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]}
@@ -0,0 +1,52 @@
/* eslint-env node */
'use strict';
const Funnel = require('broccoli-funnel');
const Merge = require('broccoli-merge-trees');
const fastbootTransform = require('fastboot-transform');
const path = require('path');
const existSync = require('exists-sync');
module.exports = {
name: 'fastboot-import',
/*isDevelopingAddon: function() {
return true;
}*/
/**
* Hook to read all browser specific libraries from bower and wrap them up with FastBoot check.
* They by default are under the vendor tree.
*
* @param {Broccoli} tree
*/
treeForVendor(tree) {
let trees = [];
if (tree) {
trees.push(tree);
}
const app = this._findHost();
const assetDir = path.join(this.project.root, app.bowerDirectory, 'slick-carousel', 'slick');
if (existSync(assetDir)) {
// Funnel the browser lib from bower with providing destDir as the lib (this is optional). If you don't
// provide `destDir` it will default to `vendor/yourlib.js`. If you provide destDir it will default to:
// `vendor/destDirName/yourlib.js`
const browserTrees = fastbootTransform(new Funnel(assetDir, {
files: ['slick.js'],
destDir: 'slick'
}));
trees.push(browserTrees);
}
return new Merge(trees);
},
included(app) {
this._super.included(app);
// import the above library that was merged with the vendor trees. In browser the library will be eval'd and run
// In fastboot, the library will not be eval'd
app.import('vendor/slick/slick.js');
}
};
@@ -0,0 +1,12 @@
{
"name": "fastboot-import",
"keywords": [
"ember-addon"
],
"dependencies": {
"broccoli-funnel": "^1.2.0",
"broccoli-merge-trees": "^2.0.0",
"exists-sync": "^0.0.4",
"fastboot-transform": "^0.1.1"
}
}
Oops, something went wrong.

0 comments on commit 8874fe3

Please sign in to comment.