Reputation: 991
I am working in an ember application. From what I understood, it builds the application using Broccoli. I have a requirement where I need to process some files in the application by running a node script before the building process starts. Now I am running the node script separately and then I start the ember server. What is the right way to achieve it? Can I make it as one of the tasks during ember build process? Where should I maintain the node file in the directory?
Upvotes: 2
Views: 622
Reputation: 12796
A simpler solution may be to call a function from your build script in ember-cli-build.js somewhere before return app.toTree();
let my_build_script = require('./lib/my-build-script.js');
await my_build_script();
return app.toTree();
Some disadvantages to this approach include:
You will likely have to modify your build script to return a function you can call and have it return a promise when it is complete.
Upvotes: 0
Reputation: 6338
I would recommend an 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
hook to remove some files from build output.
An more advanced option would be implementing a 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
is a great example for that usage.
Upvotes: 1
Reputation: 8724
Well one solution would be to leverage an in-repo addon since the addon hooks provide alot of extra points for customization than I'm aware than ember-cli-build.js
does (as far as I'm aware).
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:
In your case, preBuild
sounds like the ticket:
This hook is called before a build takes place.
You can require()
whatever files you need to from index.js
Upvotes: 1