Phpstorm Vue

Posted on  by 



Code Style: Vue. The page is available only when the Vue.js plugin is enabled on the Settings/Preferences Plugins page as described in Managing plugins. Use this page to configure formatting options for Vue files. When you change these settings, the Preview pane shows how this will affect your code. Specify which top-level tags should have their content indented, by default, indentation is. Has anyone gotten PHPStorm (v10) to recognize.vue files? Mine compile down just fine, but I get pretty bad syntax errors littered all over the IDE. Reformat JavaScript/Vue/React code on save using JetBrains IDEs such as WebStorm, IntelliJ IDEA, PhpStorm, RubyMine, PyCharm. Michael (Daichi) Yanagi Dec 26, 2019 5 min read. Hey, I have got my.tpl files assigned as Smarty within the File Types section, which is correct. However I have got a Vue template within this file too, and of course i'm getting warnings saying Unknown HTML tag etc. Is there a way I can tell PHPStorm that a certain div or area should be syntax highlighted as VueJS?

Using Prettier in WebStorm

Use the Reformat with Prettier action (Opt-Shift-Cmd-P on macOS or Alt-Shift-Ctrl-P on Windows and Linux) to format the selected code, a file, or a whole directory.

Phpstorm Vue

To run Prettier on save in WebStorm 2020.1 or above, open Preferences | Languages & Frameworks | JavaScript | Prettier and enable the option Run on save for files.

By default, only JavaScript and TypeScript files will be formatted automatically. You can further configure what files will be updated using the glob pattern.

Don’t forget to install Prettier first.

To use Prettier in IntelliJ IDEA, PhpStorm, PyCharm, and other JetBrains IDEs, please install this plugin.

To run Prettier on save in older IDE versions, you can set up a file watcher following the instructions below.

Running Prettier on save using File Watcher

To automatically format your files using Prettier on save in WebStorm 2019.* or earlier, you can use a File Watcher.

Go to Preferences | Tools | File Watchers and click + to add a new watcher.

In Webstorm 2018.2, select Prettier from the list, review the configuration, add any additional arguments if needed, and click OK.

In older IDE versions, select Custom and do the following configuration:

  • Name: Prettier or any other name
  • File Type: JavaScript (or Any if you want to run Prettier on all files)
  • Scope: Project Files
  • Program: full path to .bin/prettier or .binprettier.cmd in the project’s node_module folder. Or, if Prettier is installed globally, select prettier on macOS and Linux or C:Usersuser_nameAppDataRoamingnpmprettier.cmd on Windows (or whatever npm prefix -g returns).
  • Arguments: --write [other options] $FilePath$
  • Output paths to refresh: $FilePathRelativeToProjectRoot$
  • Working directory: $ProjectFileDir$
  • Environment variables: add COMPILE_PARTIAL=true if you want to run Prettier on partials (like _component.scss)
  • Auto-save edited files to trigger the watcher: Uncheck to reformat on Save only.
Phpstorm vue code style

Using Prettier with ESLint

If you are using ESLint with eslint-plugin-prettier, use the Fix ESLint Problems action to reformat the current file – find it using Find Action (Cmd/Ctrl-Shift-A) or add a keyboard shortcut to it in Preferences | Keymap and then use it.

Make sure that the ESLint integration is enabled in Preferences | Languages & Frameworks | JavaScript | Code Quality Tools | ESLint.

Using Prettier as External Tool

Go to Preferences | Tools | External Tools and click + to add a new tool. Let’s name it Prettier.

Webstorm Vue Unknown Html Tag

  • Program: prettier on macOS and Linux or C:Usersuser_nameAppDataRoamingnpmprettier.cmd on Windows (or whatever npm prefix -g returns), if Prettier is installed globally
  • Parameters: --write [other options] $FilePath$
  • Working directory: $ProjectFileDir$

If Prettier is installed locally in your project, replace the path in Program with $ProjectFileDir$/node_modules/.bin/prettier on macOS and Linux or $ProjectFileDir$node_modules.binprettier.cmd on Windows. Pro auto clicker download free.

Press Cmd/Ctrl-Shift-A (Find Action), search for Prettier, and then hit Enter.

Phpstorm view json

It will run Prettier for the current file.

You can add a keyboard shortcut to run this External tool configuration in Preferences | Keymap.

After a long time, I wanted to show you another quick tip. At the moment I work a lot with InertiaJS, built by Jonathan Reinink. It allows you to create fully client-side rendered, single-page apps. It makes a lot of fun, but there was one thing that has always been annoying me. At least if you're using Laravel Mix.

If you take a look at the demo project PingCRM, there is a file called webpack.mix.js. You will find something like this:

This allows you to import components directly from the resources/js directory like so:

Phpstorm View Json

What sucks now is, that you can not use PhpStorm autocompletion when you hover over the path, press cmd and click to jump to that file as you always do. This is because PhpStorm doesn't know how to resolve that.

The solution

But there is a solution of course. And it's quite easy.

Phpstorm Vue 3

Create a separate webpack file and extract that webpack configuration to that file. You end up something like this:

webpack.config.js

The only thing you have to do now is to tell Laravel Mix to use that webpack configuration instead of the inline-configuration. You should end up with this in your webpack.mix.js: Starcraft brood war free.

The last step is to tell PhpStorm there is a webpack configuration that can be used. Because PhpStorm only accepts webpack configuration in this case, the above steps have been necessary.

Go to the settings and define your new created webpack.config.js file there and you're done. It takes a little bit of time until PhpStorm recognizes it.

If everything worked paths like '@/Shared/Logo' should now be resolved by PhpStorms autocompletion and let you jump directly into that file.





Coments are closed