如何 运行 我的节点脚本作为 ember 的构建任务之一?
How to run my node script as one of the ember's build tasks?
我正在 ember 应用程序中工作。据我了解,它使用 Broccoli 构建应用程序。我有一个要求,我需要在构建过程开始之前通过 运行 节点脚本处理应用程序中的一些文件。现在我单独 运行 节点脚本,然后启动 ember 服务器。实现它的正确方法是什么?我可以将其作为 ember 构建过程中的任务之一吗? node文件应该放在目录的什么地方维护?
好吧,一个解决方案是利用 in-repo addon,因为插件挂钩提供了很多额外的定制点,比我知道的要多于 ember-cli-build.js
(据我所知) .
If you want to go beyond the built in customizations or want/need more
advanced control in general, the following are some of the hooks
(keys) available for your addon Object in the index.js file. All hooks
expect a function as the value.
includedCommands: function() {},
blueprintsPath: // return path as String
preBuild:
postBuild:
treeFor:
contentFor:
included:
postprocessTree:
serverMiddleware:
lintTree:
在你的情况下,preBuild
听起来像门票:
This hook is called before a build takes place.
您可以 require()
来自 index.js
的任何文件
我会推荐一个 in-repo addon that implements preBuild
or postBuild
Ember CLI Addon hooks. Addon hooks are badly documented but there are some usage examples by other addons. E.g. ember-cli-deploy-build-plus
uses postBuild
钩子来从构建输出中删除一些文件。
一个更高级的选项是实施 broccoli plugin and using that one in a treeFor*
hook. This makes especially sense if your custom script needs to add / remove files from the build. ember-cli-addon-docs
是该用法的一个很好的例子。
一个更简单的解决方案可能是在 return app.toTree();
之前的某处从 ember-cli-build.js 中的构建脚本调用一个函数
let my_build_script = require('./lib/my-build-script.js');
await my_build_script();
return app.toTree();
这种方法的一些缺点包括:
- 它不会 运行 作为许多并行进程之一,如果这在您的机器上可行的话。
- 它不会 运行 与构建的其余部分异步,相反,您必须等到它完成才能开始构建。
您可能必须将您的构建脚本修改为 return 一个您可以调用的函数,并在它完成时让它 return 一个承诺。
我正在 ember 应用程序中工作。据我了解,它使用 Broccoli 构建应用程序。我有一个要求,我需要在构建过程开始之前通过 运行 节点脚本处理应用程序中的一些文件。现在我单独 运行 节点脚本,然后启动 ember 服务器。实现它的正确方法是什么?我可以将其作为 ember 构建过程中的任务之一吗? node文件应该放在目录的什么地方维护?
好吧,一个解决方案是利用 in-repo addon,因为插件挂钩提供了很多额外的定制点,比我知道的要多于 ember-cli-build.js
(据我所知) .
If you want to go beyond the built in customizations or want/need more advanced control in general, the following are some of the hooks (keys) available for your addon Object in the index.js file. All hooks expect a function as the value.
includedCommands: function() {},
blueprintsPath: // return path as String
preBuild:
postBuild:
treeFor:
contentFor:
included:
postprocessTree:
serverMiddleware:
lintTree:
在你的情况下,preBuild
听起来像门票:
This hook is called before a build takes place.
您可以 require()
来自 index.js
我会推荐一个 in-repo addon that implements preBuild
or postBuild
Ember CLI Addon hooks. Addon hooks are badly documented but there are some usage examples by other addons. E.g. ember-cli-deploy-build-plus
uses postBuild
钩子来从构建输出中删除一些文件。
一个更高级的选项是实施 broccoli plugin and using that one in a treeFor*
hook. This makes especially sense if your custom script needs to add / remove files from the build. ember-cli-addon-docs
是该用法的一个很好的例子。
一个更简单的解决方案可能是在 return app.toTree();
let my_build_script = require('./lib/my-build-script.js');
await my_build_script();
return app.toTree();
这种方法的一些缺点包括:
- 它不会 运行 作为许多并行进程之一,如果这在您的机器上可行的话。
- 它不会 运行 与构建的其余部分异步,相反,您必须等到它完成才能开始构建。
您可能必须将您的构建脚本修改为 return 一个您可以调用的函数,并在它完成时让它 return 一个承诺。