Ember-CLI:找不到模块' broccoli-static-compiler'错误:找不到模块' broccoli-static-compiler'

时间:2014-06-05 18:20:32

标签: ember.js ember-cli

任何人都知道这个错误意味着什么?最重要的是:如何解决?

Cannot find module 'broccoli-static-compiler'Error: Cannot find module 'broccoli-static-compiler'

在安装ember-cli新项目并尝试运行ember server

之后,今天发生了这种情况

2 个答案:

答案 0 :(得分:5)

Broccoli Static Compiler

(1)安装所需的西兰花扩展:

npm install --save-dev broccoli-static-compiler
npm install --save-dev broccoli-merge-trees

(2)编辑 Brocfile.js

删除或评论此行:

module.exports = app.toTree();

添加(并修改以适应):

// require the static compiler
var pickFiles = require('broccoli-static-compiler');
// choose the static files - path usually: 'vendor/module/dist'
var iCanHasFiles = pickFiles('path/to/files', {
    srcDir: '/',
    // 'files' is optional for choosing some of the srcDir's content.
    // NB: Do not include directories here!
    files: ['file.js', 'file.css', 'file.woff'],
    destDir: '/assets/icanhasfiles'
});

// Merge the iCanHasFiles with the ember app tree
var mergeTrees = require('broccoli-merge-trees');
module.exports = mergeTrees([app.toTree(), iCanHasFiles]);

(3)其他JavaScript文件也可以通过此文件添加。它们必须插入 Brocfile.js 中的module.exports调用之上。

// after "bower install --save bower-module-name" (bower.io/search for name).
app.import('vendor/module/file.js');

Ember-cli和Bootstrap

(A)使用Bootstrap包含创建新项目 app-project 的说明:

ember new app-project
cd app-project
bower install --save bootstrap-sass-official
npm install --save-dev broccoli-sass
mv app/styles/app.css app/styles/app.scss

(B)打开 app / styles / app.scss ,然后更改导入路径:

@import 'vendor/bootstrap-sass-official/vendor/assets/stylesheets/bootstrap';

(C)要包含Glyphicons字体,请打开 Brocfile.js

// import the necessary modules:
var pickFiles = require('broccoli-static-compiler');
var mergeTrees = require('broccoli-merge-trees');

// at the bottom of the file, replace the "module.exports" line with:
// module.exports = app.toTree();

// Put the bootstrap fonts in the place that the bootstrap css expects to find them.
var bootstrapFonts = pickFiles('vendor/bootstrap-sass-official/vendor/assets/fonts/bootstrap', {
    srcDir: '/',
    destDir: '/assets/bootstrap'
});

// Merge the bootstrapFonts with the ember app tree
var mergeTrees = require('broccoli-merge-trees');
module.exports = mergeTrees([
    app.toTree(),
    bootstrapFonts
]);

(D)或者,对于经典的glyphicons(bootstrap 2.3等):

// if using glyphicons instead (bootstrap 2.3 etc):
var glyphicons = pickFiles('vendor/bootstrap-sass-official/vendor/assets/fonts/bootstrap', {
    srcDir: '/',
    files: [
        'glyphicons-halflings-regular.*',
    ],
    destDir: '/assets/bootstrap'
});

// Merge the glyphicons with the ember app tree
module.exports = mergeTrees([
    app.toTree(),
    glyphicons
]);

答案 1 :(得分:4)

这意味着ember serve无法找到Node.js包broccoli-static-compiler。 Broccoli为Ember CLI项目提供构建管道,broccoli-static-compiler是一个Broccoli插件,可以按原样将文件复制到构建输出。

我无法使用Ember CLI 0.0.280.0.29重现此内容,此 YOURPROJECT/node_modules/ember-cli/node_modules/。您安装了哪个版本的Ember CLI? (ember --version

您可以尝试通过从项目目录运行broccoli-static-compiler来为您的新项目本地安装npm install --save-dev broccoli-static-compiler