一、找到安装HBuilderX的目录,修改beautifier.js文件;
比如:D:\HBuilderX\plugins\format\node_modules\js-beautify\js\src\css\beautifier.js
1)先备份文件beautifier.js文件;
2)请把附件压缩包解压,找到beautifier.js文件;
修改方法:
1、修改 this.eatWhitespace(true) 为 this.eatWhitespace()
去除参数 true 则 清除空格但不插入换行
2、去除或注释掉 this._output.add_new_line();
不插入换行
修改
...} else if (this._ch === '{') {
[294] this.eatWhitespace(); 去除参数true
[295] // this._output.add_new_line(); 注释掉
} else if (this._ch === '}') {
...
[298] // this._output.add_new_line(); 注释掉
...
[314] this.eatWhitespace(); 去除参数true
...
} else if (this._ch === ';') {
...
[362] this.eatWhitespace(); 去除参数true
...
[369] this._output.add_new_line(); 注释掉
}
2、工具(T) --> 插件配置 --> 找到 jsbeautify 点击下方的 “打开文件jsbeautifyrc.js进行配置”:
在 options 里面 加
module.exports = {
parsers: {
...
},
options: {
...
"css": {
"newline_between_rules": false,
"selector_separator_newline": false,
"preserve_newlines": false
}
}