灰烬快速启动/不导入node_modules脚本

时间:2018-09-24 12:55:55

标签: ember.js

我首先要指出我是从这里交叉张贴的:https://github.com/ember-fastboot/ember-cli-fastboot/issues/621 到目前为止,该问题尚未受到任何关注,因此我向更广泛的社区开放。

我正在尝试使ember-cli-slick快速启动兼容。 它使用来自node_modules的slick.js,如下所示:

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

app.import("node_modules/slick-carousel/slick/slick.js");

我正在尝试让treeforvendor工作,但运气不佳。 我在这里https://www.ember-fastboot.com/docs/addon-author-guide#third-party-dependencies中关注文档 但我怀疑它的目标是凉亭,而不是npm / node_modules。

treeForVendor(defaultTree) {        
    var browserVendorLib = new Funnel('node_modules/slick-carousel/slick/slick.js');    

    browserVendorLib = map(browserVendorLib, (content) => `if (typeof FastBoot === 'undefined') { ${content} }`);

    return new mergeTrees([defaultTree, browserVendorLib]);
  },

这会导致错误:

  

构建错误(西兰花持久性过滤器:映射器)

     

ENOTDIR:不是目录,scandir   'projectdir / tmp / broccoli_persistent_filtermapper-input_base_path-FOInixjr.tmp /'

我也尝试过

  treeForVendor(defaultTree) {        
    var map = require("broccoli-stew").map;
    var Funnel = require("broccoli-funnel");
    const mergeTrees = require('broccoli-merge-trees');

    let tree=new Funnel('node_modules/slick-carousel/slick/', {
      destDir: 'slick-carousel',
      files: ['slick.js']
    })

    tree = map(tree, (content) => `if (typeof FastBoot === 'undefined') { ${content} }`);


    return new mergeTrees([defaultTree, tree]);
  },

这至少可以构建..但是我又回到了Fastboot错误

  

ReferenceError:未在以下位置定义jQuery   projectfolder / tmp / broccoli_merge_trees-output_path-8cGO0zCl.tmp / assets / node_modules / slick-carousel / slick / slick.js:25:1

我仅使用import和treeforvendor函数创建了一个干净的,否则为空的Ember插件项目,以演示此问题。 https://github.com/MrChriZ/ember-slicker

1 个答案:

答案 0 :(得分:0)

我缺少几件事,也许附加指南可能更清晰。

首先,我认为渠道是目录路径而不是完整文件路径。在此之上,路径必须是完整的文件路径。 《 Fastboot加载项指南》中并没有立即明确指出。 所以看起来像这样:

const assetDir = path.join(this.project.root, 'node_modules', 'slick-carousel', 'slick');
       var browserVendorLib = new Funnel(assetDir, {
         files: ['slick.js'],
         destDir: 'slick'
       });    

你不能做的是

const assetDir = path.join(this.project.root, 'node_modules', 'slick-carousel', 'slick', 'slick.js);
var browserVendorLib = new Funnel(assetDir);

抛出:

  

ENOTDIR:不是目录

我相信是因为漏斗期望目录路径而不是文件路径。

第二个在包含的钩子Gaurav中正确地在Github上指出了导入语句需要更改以指向供应商目录。

所以对我来说,最终的解决方案是:

treeForVendor(defaultTree) {        
   var map = require("broccoli-stew").map;
   var Funnel = require("broccoli-funnel");
   const mergeTrees = require('broccoli-merge-trees');

   const assetDir = path.join(this.project.root, 'node_modules', 'slick-carousel', 'slick');
   var browserVendorLib = new Funnel(assetDir, {
     files: ['slick.js'],
     destDir: 'slick'
   });    

   browserVendorLib = map(browserVendorLib, (content) => `if (typeof FastBoot === 'undefined') { ${content} }`);

   return new mergeTrees([defaultTree, browserVendorLib]);
 },
 included: function(app) {
   this._super.included(app);

   app.import('node_modules' + '/slick-carousel/slick/slick.css');
   app.import('node_modules'+ '/slick-carousel/slick/slick-theme.css');
   app.import('node_modules' + '/slick-carousel/slick/fonts/slick.ttf', { destDir: 'assets/fonts' });
   app.import('node_modules' + '/slick-carousel/slick/fonts/slick.svg', { destDir: 'assets/fonts' });
   app.import('node_modules' + '/slick-carousel/slick/fonts/slick.eot', { destDir: 'assets/fonts' });
   app.import('node_modules' + '/slick-carousel/slick/fonts/slick.woff', { destDir: 'assets/fonts' });
   app.import('node_modules' + '/slick-carousel/slick/ajax-loader.gif', { destDir: 'assets' });

   // import the above library into vendor.js 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');
 }