angular - 为 angular-cli 创建一个插件

标签 angular

我刚刚用 angular-cli 开始了一个新项目并且需要为该项目的特定需求实现一些插件。

我找到了表扬ng addon <addon-name> , 这是基于 ember-cli插件创建,但这实际上创建了一个 ember-cli 插件,它看起来与 angular-cli 完全不同。

因此,我在 angular-cli firebase 插件上启发了自己,并在 <my-project>/addons/i18n-json/index.js 中创建了这个文件。 .

'use strict';

var i18nJson = {
    name: 'i18n-json',
    description: 'Generate an i18n JSON file from a string properties file.',
    works: 'insideProject',

    availableOptions: [{
        name: 'input',
        type: String,
        default: 'i18n/i18n.properties',
        description: 'i18n properties file'
    }, {
        name: 'output',
        type: String,
        default: 'dist/i18n/i18n.json',
        description: 'new JSON file to be generated with i18n strings'
    }],

    run: function(options, rawArgs) {
        console.log(1111, 'i18n-json', 'run'); // XXX
    }
};

module.exports = {
    name: 'i18n-json',

    includedCommands: function() {
        return {
            'i18n-json': i18nJson
        }
    }
};

然后,添加"addons/i18n-json"angular-cli.json的“插件”部分。

问题:ng命令无法识别它。

尝试了全局安装的脚本和 ./node_modules/.bin/ng但现在到了这个地步,我仍然不明白为什么它没有任何反应。

有人知道吗?

最佳答案

当我在 CLI 的 1.0.0-beta.17 版本中输入 ng addon help 时,我得到:

您不能在 angular-cli 项目中使用 addon 命令。


但是,请在此处查看@David Bulté 的回答:

Check the sections '3d party lib installation' and 'global lib installation' on the Angular-CLI Wiki:

App Creation Using Template

ng new my-todo-app --template=simple-todo

ng serve

Using A Template Library

ng new my-todo-app

# Could be ng use`` as well.

ng install complex-todo-addon

ng generate todo routes/+todo

Thirdparty Installation

ng new my-todo-app

ng install sass


可能相关的问题在这里:

关于angular - 为 angular-cli 创建一个插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38344051/

相关文章:

javascript - 路由子菜单元素 Angular 2

html - 如何更改 md-tab-header 的颜色?

typescript - 如何使用 typescript 检查 Angular2 版本

angular - 将参数传递给组件。是否使用括号

angular - 收到错误类型错误 : Cannot read property 'valid' of undefined for Angular 5 template form

javascript - Angular 绑定(bind)到 View 上的函数会导致对数据服务的无限调用

angular - ActivatedRoute 不会在路线更改时更新子路线数据

Angular Promise 不记录未捕获的异常

angular - 如何将 Highcharts 渲染为以 id 作为容器的 div - Angular?

javascript - 如果持续时间小于 1 小时或更长,如何添加条件 ngClass