简体   繁体   中英

How can I make my ember cli addon supply a vendor tree

I am trying to make my addon supply vendor'd data to the app using it. The library is CKEditor (a customized version generated from the CKEditor builder). I know I can use the addon blueprint to add a bower dependency but since CKEditor is customized I can't use bower to download that same version in the consuming app. I've used the treeForPublic and broccoli funnel to copy from my addon vendor folder the whole ckeditor folder to the app public folder (this is required by ckeditor). My only issue is that the consuming app also needs to have the ckeditor folder in its vendor folder or it won't build because the watcher can't find it. I was with the impression that if the addon was moving the folder to the public destination and was also importing js/css files in the included hook the original vendor'd folder was not needed by the final app. Have I understood it wrong or can I do this without duplicating my ckeditor folder between the addon and the app ?

here is what I have so far :

included: function(app) {
    this._super.included(app);

    app.import('vendor/ckeditor_custom/ckeditor.js');
    app.import('vendor/ckeditor_custom/styles.js');
    app.import('vendor/ckeditor_custom/lang/fr.js');
    app.import('vendor/ckeditor_custom/skins/minimalist/editor.css');
},

contentFor: function(type, config) {
    if (type === 'vendor-prefix') {
        return "window.CKEDITOR_BASEPATH = 'assets/ckeditor/';";
    }
},

treeForPublic: function (tree) {
    var ckeditorTree = new Funnel('vendor/ckeditor_custom/', {
        srcDir: '/',
        exclude: ['**/.DS_Store','**/*.md'],
        destDir: 'assets/ckeditor'
    });

    return BroccoliMergeTrees([tree, ckeditorTree]);
},

treeForVendor: function (tree) {
    var ckeditorTree = new Funnel('vendor/ckeditor_custom/', {
        srcDir: '/',
        exclude: ['**/.DS_Store','**/*.md'],
        destDir: 'ckeditor_custom'
    });

    return ckeditorTree;
},

Thanks for the help!

Give this a whirl:

var path = require('path');
var mergeTrees = require('broccoli-merge-trees');
var concat = require('broccoli-concat');

module.exports = {
  name: 'myaddon',

  treeForVendor: function(tree) {
    var trees = [tree];

    var ckeditorTree = path.join('bower_components', 'ckeditor_custom');

    trees.push(concat(ckeditorTree, {
      inputFiles: [
        'ckeditor.js',
        'styles.js',
        'lang/fr.js'
      ],
      outputFile: '/ckeditor.js'
    }));

    trees.push(concat(ckeditorTree, {
      inputFiles: [
        'skins/minimalist/editor.css'
      ],
      outputFile: '/ckeditor.css'
    }));

    return mergeTrees(trees);
  },

  included: function included(app) {
    this.app = app;
    app.import('vendor/ckeditor.js');
    app.import('vendor/ckeditor.css');
  }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM