Vue Phpstorm



Vue.js phpstorm. Follow edited Oct 4 '18 at 19:53. Asked Oct 4 '18 at 19:40. Hekumok Hekumok. 151 5 5 bronze badges. Settings mentioned by you should work; the only issue is that the code in. Browse other questions tagged javascript vue.js phpstorm webstorm or ask your own question. The Overflow Blog Podcast 324: Talking apps, APIs, and open source with developers from Slack. Mint: A new language designed for building single page applications. Featured on Meta. View Nicolas Vastrade’s profile on LinkedIn, the world’s largest professional community. Nicolas has 4 jobs listed on their profile. See the complete profile on LinkedIn and discover Nicolas’ connections and jobs at similar companies.

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 applied only to code inside template tags. Also decide on whether indentation should be uniform for all top-level tags or depend on the language used, for example, be HTML or Pug-specific.

Tabs and Indents

Specific to the language in the block

Select this option to have the contents of top-level tags indented in the language-specific style.

Same in the whole file

Select this option to to apply uniform indentation to the code inside all top-level tags in a file. Use the controls below to configure uniform indentation.

Use tab character
  • If this checkbox is selected, tab characters are used:

    • On pressing the Tab key

    • For indentation

    • For reformatting code

  • If the checkbox is cleared, PhpStorm uses spaces instead of tabs.

Smart tabs

An indentation consists of two parts. One part results from nesting code blocks, and the other part is determined by alignment.

  • If this checkbox is selected, the part that results from nesting contains both tabs and spaces (if necessary), while the part defined by alignment consists only of spaces.

  • If this checkbox is cleared, only tabs are used. This means that after reformatting a group of spaces that fits the specified tab size is automatically replaced with a tab, which may result in breaking fine alignment.

The Smart Tabs checkbox is available if the Use tab character checkbox is selected.

Tab sizeIn this field, specify the number of spaces that fits in a tab.
IndentIn this field, specify the number of spaces to be inserted for each indent level.
Continuation indent

In this field, specify the number of spaces to be inserted between the elements of an array, in expressions, method declarations, and method calls.

Keep indents on empty linesIf this checkbox is selected, PhpStorm retains indents on empty lines as if they contained some code. If the checkbox is cleared, PhpStorm deletes the tab characters and spaces on empty lines.
Indent children of top-level tag

By default, only the code inside template tags has initial indentation. If necessary, add other tags using commas as separators. For example, if you specify script in the field, the code inside all script tags gets initial indentation as shown in the Preview pane.

Spaces

Use this tab to specify where you want PhpStorm to insert spaces automatically. Select the checkboxes next to the description of relevant locations and check the results in the Preview pane.

Wrapping and braces

In this tab, customize the exceptions, brace placement and alignment options that PhpStorm will apply to various code constructs on reformatting the source code. Check the results in the Preview pane.

Alignment takes precedence over indentation options.

Visual guidesIn this field, specify multiple right margins. You can leave a default value or enter the number of spaces for your margin. If you want to specify several margins, enter numbers separated by comma.
Interpolations

In this area, select a wrapping style for interpolations and specify whether you want to have enclosing brackets {{ }} at a new line (default) or not.

If a JavaScript expression inside a Vue.js interpolation has line breaks, PhpStorm automatically starts this JavaScript expression from a new line and adds a new line after it.

Clear the New line after '{{' and the New line before '}}' checkboxes to change this default behavior.

These checkboxes do not affect JavaScript expressions without line breaks inside. For example, {{ foo }} will not be split automatically anyway.

Wrapping options

A wrapping style applies to various code constructs, specified in the left-hand pane (for example, method call arguments, or assignment statements).

  • Do not wrap- When this option is selected, no special wrapping style is applied, the nested alignment and braces settings are ignored.

  • Wrap if long- Select this option to wrap lines that go beyond the right margin with proper indentation.

  • Wrap always- Select this option to wrap all elements in lists so that there is one element per line with proper indentation.

  • Chop down if long- Select this option to wrap elements in lists that go beyond the right margin so that there is one element per line with proper indentation.

Set from

The link appears in the upper-right corner of the page, when applicable. Click this link and choose the language to be used as the base for the current language code style.

To return to the initial set of code style settings and discard the changes, click Reset.

PhpStorm integrates with the webpack module bundler. This support improves coding assistance in JavaScript files by taking into account webpack module resolution and resolve aliases.

In projects that consist of multiple modules with different webpack configurations, PhpStorm can automatically detect the relevant configuration file for each module and use the module resolution rules from it, see Specifying the webpack configuration file to use below.

For webpack version 2 and later, PhpStorm provides code completion and quick documentation look-up for options in webpack configuration files.

Before you start

Download and install Node.js.

Configuring webpack in PhpStorm

Add webpack to your package.json

  • Make sure webpack is listed in the dependencies or devDependencies object of your package.json.

    If webpack is missing, open the embedded Terminal (Alt+F12) and type:

    npm install --save-dev webpack

Create webpack configuration files

  • Create one or several configuration files depending on your project structure (New | JavaScript file ). Learn more from the webpack official website.

Specify the webpack configuration files to use

Based on the analysis of a webpack configuration file, PhpStorm understands the webpack configuration, resolves modules, and provides coding assistance in JavaScript files, see Resolving modules below.

In PhpStorm, you can choose between two configuration modes - automatic and manual.

With automatic configuration, PhpStorm auto-detects the relevant webpack configuration file for each JavaScript file.

With manual configuration, you specify the webpack configuration file to use in your project. Manual configuration is useful if the name of your webpack configuration file is not recognized by PhpStorm, see the list of recognized webpack config names below.

Phpstorm

Choose how to detect webpack configuration

  1. Open the Settings/Preferences dialog Ctrl+Alt+S and go to Languages and Frameworks | JavaScript | Webpack.

  2. Select one of the following options:

    • Automatic Webpack configuration: In this mode, for a JavaScript file, PhpStorm will first look for a webpack configuration file in the folder where this JavaScript file is located, then in its parent folder, and so on.

      As a result, if your project consists of multiple modules with different webpack configurations, each module will use the module resolution rules from its own webpack configuration file (if such config is found).

      PhpStorm recognizes JavaScript or TypeScript webpack configuration files with the following names and in the following order:

      • webpack.config.js/ webpack.config.ts

      • webpack.base.conf.js/ webpack.base.conf.ts

      • webpack.dev.conf.js/ webpack.dev.conf.ts

      • webpack.prod.conf.js/ webpack.prod.conf.ts

      • webpack.base.config.js/ webpack.base.config.ts

      • webpack.dev.config.js/ webpack.dev.config.ts

      • webpack.prod.config.js/ webpack.prod.config.ts

      • webpack.babel.js/ webpack.babel.ts

    • Manual Webpack configuration: In the Configuration file field, specify the location of the webpack config to use.

      In this mode, the resolution rules from the specified configuration file will be applied to all modules in your project.

      Select this option if the name of your webpack configuration file is not recognized by PhpStorm, see the list of recognized webpack config names above.

See also Getting Started on the webpack official website.

Editing a webpack configuration file

For webpack version 2 and later, PhpStorm provides code completion and documentation look-up in the configuration object of webpack configuration files. Code completion is provided on the fly. To view documentation for a symbol, press Ctrl+Q.

PhpStorm provides coding assistance in a webpack configuration file only if its name contains the webpack character string and webpack is listed in package.json.

Project security

When you open a webpack project, PhpStorm executes the webpack configuration file, which may contain some potentially malicious code. To avoid problems, when you open a project for the first time PhpStorm displays a warning and lets you decide on how to proceed.

If you click Skip, PhpStorm disables analysis of the webpack configuration in the current project. As a result, PhpStorm might not resolve some of the imports in the project or add imports that don't use resolution rules configured in the webpack configuration.

To re-enable analysis of the webpack configuration, open the Settings/Preferences dialog Ctrl+Alt+S, go to Languages and Frameworks | JavaScript | Webpack, and select automatic or manual detection for webpack configuration, see Specify the webpack configuration files to use above.

  • The notification is shown once for the whole project and applies to all webpack configurations in it.

  • Projects created from the PhpStorm New Project wizard are automatically considered trusted.

Phpstorm Vue Formatting

Trusted locations

You can configure what sources PhpStorm should consider safe.

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Build, Execution, Deployment | Trusted Locations.

  2. On the Trusted Locations page, create a list of local directories where the projects you consider trusted reside. Click OK to save the changes.

    PhpStorm loads projects from those locations without showing any security notifications.

Resolving modules

Phpstorm Vue 3

When you open a project or edit a webpack configuration file (either auto-detected or specified on Settings/Preferences | Languages and Frameworks | JavaScript | Webpack ), PhpStorm analyses the configuration in the background and, based on the received information, properly understands the project resolve roots and resolve aliases. Thanks to this understanding of the project configuration, PhpStorm provides more precise code completion for imports and exported symbols in JavaScript files. As a result, everything works fine without any steps from your side.

The image below illustrates module resolution in a project where react-color is an alias for the path './src/index.js'. PhpStorm properly resolves the import from react-color, provides navigation to it and completion for the exported symbols:

Phpstorm Vue Typescript

Debugging applications that use webpack

You can debug applications that use webpack same way as you debug any JavaScript client-side application, see Debugging React apps created with Create React App and Debugging Angular apps created with Angular CLI.