Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference files globally in VS Code (JS)

I have a website that I am using Grunt to concat files. I am wondering if there is currently some way to reference my Bower packages in all of my JS files as I use those packages within my files.

Example: I include 'moment' as a Bower package and then when I reference 'moment' in my JS file within VS Code I get a warning that 'moment' does not exist. This is annoying because I know it exists globally and would like to be able to manually reference it for code completion (and to get rid of the warning).

like image 666
Uxonith Avatar asked Apr 29 '15 23:04

Uxonith


People also ask

How do you search globally in VS Code?

VS Code allows you to quickly search over all files in the currently opened folder. Press Ctrl+Shift+F and enter your search term.

How do I see all references in VS Code?

The Find All References command is available on the context (right-click) menu of the element you want to find references to. Or, if you are a keyboard user, press Shift + F12.

How do you reference a file in JavaScript?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.


1 Answers

You can omit the warning by adding the following to the top of your sources:

/*global moment*/

You can also create a globals.js file, add all those global definitions to it and reference it from your sources like this:

/// <reference path="global.js" />
like image 143
João Moreno Avatar answered Sep 19 '22 13:09

João Moreno