Skip to content

Instantly share code, notes, and snippets.

@samtgarson
Last active September 24, 2017 09:57
Show Gist options
  • Save samtgarson/6cce2b7df9f5ba6c5b0ccf722c3fe588 to your computer and use it in GitHub Desktop.
Save samtgarson/6cce2b7df9f5ba6c5b0ccf722c3fe588 to your computer and use it in GitHub Desktop.
Vue support for prettier
yarn prettier --print-width 80 --no-semi --single-quote --parser parse5 --write example.vue
<template>
<example>
<p>{{ code }}</p>
<ul>
<li v-for="item in array">{{ item }}</li>
</ul>
</example>
</template>
<script>
export default {
name: 'example',
data: () => ({ array: [1, 2, 3] }),
props: {
code: {
type: String,
required: true
}
}
}
</script>
<style>
.example {
background: red;
}
li {
list-style-type: none;
}
</style>
<template>
<example>
<p>{{ code }}</p>
<ul>
<li v-for="item in array">{{ item }}</li></ul>
</example>
</template>
<script>
export default {
name: 'example',
data: () => ({ array: [1, 2, 3] }),
props: {
code: { type: String,
required: true
}
}
}
</script>
<style>
.example {
background: red;
}
li {
list-style-type: none
}
</style>
@samtgarson
Copy link
Author

samtgarson commented Sep 24, 2017

The command seems to work correctly for the <script> section, however:

  • all line breaks are removed from the <template> section
  • a semicolon is added to the end of the <style> section.
  • new lines have been inserted at the top of the file

I'm not sure if prettier supports indented syntax Sass and Pug or not so that could be the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment