自定义模板
应用场景:webstorm在新建文件时,往往需要选择文件类型,如:js,vue等。自定义模板的好处在于不用每次新建一个文件都重写相同代码。
- 以下以新建一个
react模板
为例Ctrl+alt+s
打开设置- 搜索或找到
File and Code Templates
+
号新建模板name
:模板名称react,extension
文件后缀名:js【在新建file时,即会出现react可供选择】- 编写模板
import React from 'react';
class ${NAME} extends React.Component{
render() {
return()
}
}
export default ${NAME};
- 如上就是一个react组件模板,其中
${NAME}
是webstorm的模板变量(对应文件名),在每次新建文件时,${NAME}
会被替换成文件名
Webstorm模板变量
${PROJECT_NAME} - the name of the current project(当前项目名).
${NAME} - the name of the new file which you specify in the New File dialog box during the file creation.(文件名)
${USER} - the login name of the current user.(webstorm用户名)
${DATE} - the current system date.(当前日期)
${TIME} - the current system time.(当前时间)
${YEAR} - the current year.(当前年份)
${MONTH} - the current month.(当前月份)
${DAY} - the current day of the month.(当前日期)
${HOUR} - the current hour.(当前小时)
${MINUTE} - the current minute.(当前分)
${PRODUCT_NAME} - the name of the IDE in which the file will be created.
${MONTH_NAME_SHORT} - the first 3 letters of the month name. Example: Jan, Feb, etc.
${MONTH_NAME_FULL} - full name of a month. Example: January, February, etc.