Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
773 views
in Technique[技术] by (71.8m points)

visual-studio-code - 在VS Code上的Svelte中在脚本标签之前设置HTML(Set HTML Before Script Tags in Svelte on VS Code)

I am using the Svelte Plugin for vs code: https://marketplace.visualstudio.com/items?itemName=JamesBirtles.svelte-vscode

(我正在将Svelte插件用于vs代码: https ://marketplace.visualstudio.com/items?itemName=JamesBirtles.svelte-vscode)

I also have the eslint and prettier plugins installed:

(我还安装了eslint和更漂亮的插件:)

In addition, I have set up .eslintrc.js and .prettierrc files as follows:

(此外,我还设置了.eslintrc.js和.prettierrc文件,如下所示:)

// .eslintrc.js
module.exports = {
  env: {
    browser: true,
    es6: true
  },
  extends: ['prettier'],
  overrides: [
    {
      files: ['**/*.svelte'],
      processor: 'svelte3/svelte3'
    }
  ],
  parserOptions: {
    ecmaVersion: 2019,
    sourceType: 'module'
  },
  plugins: ['prettier', 'svelte3'],
  rules: {
    'prettier/prettier': 'error',
    'svelte3/lint-template': 2
  }
}

// .prettierrc
{
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true,
  "trailingComma": "es5",
  "plugins": [
    "svelte"
  ],
}

Now everything seems to work like it supposed to.

(现在一切似乎都按预期运行。)

But there is one functionality that I would like to change.

(但是我想更改一项功能。)

I would like to have my html on top of the style tags in my .svelte file (and, if possible, also on top of the script tags).

(我想将我的html放在我的.svelte文件中的样式标签之上(如果可能,也可以在脚本标签之上)。)

However, when I click on save, it automatically moves all of my html to the bottom of the file.

(但是,当我单击“保存”时,它将自动将所有html移至文件底部。)

How can I override this?

(如何覆盖呢?)

Thanks.

(谢谢。)

  ask by Moshe translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

prettier-plugin-svelte has a svelteSortOrder option , that can be added to your .prettierrc file.

(svelteSortOrder prettier-plugin-svelte具有svelteSortOrder 选项 ,可以将其添加到您的.prettierrc文件中。)

In your case, it would become:

(在您的情况下,它将变为:)

// .prettierrc
{
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true,
  "trailingComma": "es5",
  "plugins": [
    "svelte"
  ],

  "svelteSortOrder": "scripts-markup-styles"
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...