我刚刚用 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/