Custom plug-ins (advanced)
First of all, we should make it clear that as a general program, there should not be too many private customization requirements in the core. If you want to list it behind gulp dev
Extract all html functions in the root directory, and want to pop up the browser window directly after gulp ftp
is uploaded successfully. Si believes that it is too intrusive and should not be used as an integrated function in a general workflow, so, We provide plug-in
function.
tmt-workflow
not only provides multiple common tasks, but also opens the callback interface for each common task. You only need to write the plug-in according to the node method, and you can design it according to your specific needs. The functions they want allow users to expand the tasks they want without reading the tmt-workflow
source code, which not only reduces the learning cost, but also reduces the coupling of the workflow.
Below, we use a simple example to illustrate how to use the Custom plug-in
function.
1. Configuration .tmtworkflowrc
//插件功能 //路径相对于 tasks/plugins 目录 "plugins": { "build_devAfter": ["TmTIndex"], //build_dev 任务执行后自动执行 "build_distAfter": [], //build_dist 任务执行后自动执行 "ftpAfter": ["ftp"] //ftp 任务执行后自动执行 },
is as above, each field attribute corresponds to each task, the plug-in is specified in the form of an array, and the plug-ins specified in the array are executed in sequence, as we give Our plugin is named TmTIndex
.
2. Create a new TmTIndex.js in the _tasks/plugins/
directory
var rd = require('rd'); var fs = require('fs'); var path = require('path'); //插件必需按 node 模块规范编写 module.exports = function (config) { // do some stuff ... }
As above, the plug-in only needs to be written according to the node module specification. can achieve the function you want.
As you can see, extending the plug-in only requires two steps. The specific functions you want to achieve can be customized according to specific needs.
We have internally expanded multiple customization requirements through plug-in functions. If you don’t understand anything, you can issue it at any time.