gpt4 book ai didi

node.js - 使用 prettier 自动格式化代码,onchange 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 23:55:50 24 4
gpt4 key购买 nike

每当文件发生变化时,我想用更漂亮的方式格式化文件。所以我运行这个命令来实现这一点

onchange '**/*.js' -- prettier --write {{changed}}

当通过终端运行、监听文件更改并格式化它时,这绝对可以正常工作。

但是当我将此命令添加为 package.json 中的 npm 脚本并使用 npm run prettier-watch

执行它时

它开始监听更改,但在文件更改时不会格式化代码。

package.json

{
"name": "pwa-svelte-rollup-template",
"private": true,
"scripts": {
"start": "run-p serve autobuild",
"serve": "sirv public --dev",
"build": "rollup -c",
"autobuild": "rollup -c -w",
"clean": "rimraf public/bundle.*",
"prettier-watch": "onchange '**/*.js' -- prettier --write {{changed}}"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.2",
"babel-jest": "^24.8.0",
"eslint": "^6.1.0",
"eslint-config-standard": "^13.0.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.14.0",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"node-sass": "^4.12.0",
"npm-run-all": "^4.1.5",
"onchange": "^6.0.0",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"rollup": "^1.17.0",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.1",
"rollup-plugin-livereload": "^1.0.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-svelte": "^5.1.0",
"rollup-plugin-terser": "^5.1.1",
"sirv-cli": "^0.4.4",
"svelte": "^3.6.9",
"svelte-preprocess-sass": "^0.2.0"
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": "3.0.0"
}
]
],
"plugins": [
[
"@babel/plugin-proposal-class-properties"
]
],
"sourceMaps": true
},
"browserslist": [
"last 2 versions",
"not dead",
"not IE 11",
"not < 0.2%"
],
"eslintConfig": {
"extends": [
"standard"
],
"env": {
"browser": true,
"serviceworker": true,
"jest": true
},
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
},
"sourceType": "module"
}
},
"eslintIgnore": [
".cache",
"dist",
"node_modules"
]
}

如果我做错了什么,请告诉我

最佳答案

我也遇到了同样的问题。将您的 prettier-watch 脚本更改为 "onchange\"**/*.js\"-- prettier --write {{changed}}"

关于node.js - 使用 prettier 自动格式化代码,onchange 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57240369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com