You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[scss] Consider custom aliases in module resolution #131954
Please read from tsconfig/jsconfig’s compilerOptions.paths—and perhaps other popular locations such as webpack.config’s resolve.alias—when providing IntelliSense features to SCSS/Sass files. For instance, if I specify:
…then I want to get IntelliSense features for this, such as cmd-clicking on the underlined import to jump to the relevant file. Currently if I do this, e.g. in:
src/components/Foo/Foo.scss
@import'~/globals';
.foo {
/* … */
}
…VS Code looks for src/components/Foo/~/globals, when I want it to look for src/globals, as I’ve set it up. (I understand that the tilde character already maps to node_modules in Sass, but this is a tilde + a forward slash, and the character could just as easily be @ or anything else.)
The presence of jsconfig.json file in a directory indicates that the directory is the root of a JavaScript Project. The jsconfig.json file specifies the root files and the options for the features provided by the JavaScript language service.
While the section on tsconfig doesn’t say exactly the same thing, it stands to reason that it serves a similar function to jsconfig but for TypeScript projects.
I only suggest these files because they are already being read by VS Code to modify its behavior. The configuration that actually impacts SCSS files in my workflows is webpack.config.js, but I know there are plenty of bundlers out there so maybe VS Code doesn’t want to play favorites, or go down a path of including OOTB support for every bundler.
Specifically, SCSS files are impacted if you use a loader that respects Webpack’s module resolution rules while following Sass imports. This is how webpack-contrib/sass-loader works, the most popular library for doing this in that ecosystem. For instance if you do this:
…then doing @import '~/foo' will reference module.exports.resolve.alias and resolve to @import '/path/to/src/foo.scss' (or /path/to/src/foo/index.scss, as the case may be), without any Sass-specific configuration. So the request here is to allow me to tell VS Code to resolve modules the same way that my bundler does. Currently there is a disconnect between the two, such that when I Cmd + click on a Sass import, it fails to bring me to the appropriate file—it looks for current-directory/~/foo and fails, bringing up an alert box about how it can’t find anything.
However, if I Cmd + click on an identically aliased path inside of JS/TS, it works, because VS Code looks at jsconfig/tsconfig’s compilerOptions.paths, where I have set ~/* to src/*.
tsconfig.json is the well-defined way of configuring a TypeScript projects.
From what I know, for scss there's no such standard. Getting the information out of webpack, or any other build script is hard and error prone. We might not understand the full webpack config or build script and we might confuse users with wrong results. That's why I don't think we should go that way. We might fix your use case but get it wrong for others.
And, as said, currently , all that would be good for it to get the link right. We don't do any loading of imports. If we were to do that, I agree this is a problem we would have to solve (e.g. by introducing a scss configuration file).
Activity
aeschli commentedon Aug 31, 2021
The built-in scss support does not load any imports. See #100217
The only thing we have is a link on the Import (A place for python bower components) (@import) that is aware of the
~to load from node modules.How does the tsconfig file impact a scss file? Isn't it only used for TypeScript?
HughxDev commentedon Aug 31, 2021
Martin Aeschlimann (@aeschli) It doesn’t necessarily, but it seems to be VS Code’s intent that
jsconfig/tsconfigare as much for the IDE as they are for the compiler. From the docs onjsconfig:While the section on
tsconfigdoesn’t say exactly the same thing, it stands to reason that it serves a similar function tojsconfigbut for TypeScript projects.I only suggest these files because they are already being read by VS Code to modify its behavior. The configuration that actually impacts SCSS files in my workflows is
webpack.config.js, but I know there are plenty of bundlers out there so maybe VS Code doesn’t want to play favorites, or go down a path of including OOTB support for every bundler.Specifically, SCSS files are impacted if you use a loader that respects Webpack’s module resolution rules while following Sass imports. This is how webpack-contrib/sass-loader works, the most popular library for doing this in that ecosystem. For instance if you do this:
webpack.config.js
…then doing
@import '~/foo'will referencemodule.exports.resolve.aliasand resolve to@import '/path/to/src/foo.scss'(or/path/to/src/foo/index.scss, as the case may be), without any Sass-specific configuration. So the request here is to allow me to tell VS Code to resolve modules the same way that my bundler does. Currently there is a disconnect between the two, such that when I Cmd + click on a Sass import, it fails to bring me to the appropriate file—it looks forcurrent-directory/~/fooand fails, bringing up an alert box about how it can’t find anything.However, if I Cmd + click on an identically aliased path inside of JS/TS, it works, because VS Code looks at
jsconfig/tsconfig’scompilerOptions.paths, where I have set~/*tosrc/*.aeschli commentedon Sep 1, 2021
tsconfig.jsonis the well-defined way of configuring a TypeScript projects.From what I know, for
scssthere's no such standard. Getting the information out of webpack, or any other build script is hard and error prone. We might not understand the full webpack config or build script and we might confuse users with wrong results. That's why I don't think we should go that way. We might fix your use case but get it wrong for others.And, as said, currently , all that would be good for it to get the link right. We don't do any loading of imports. If we were to do that, I agree this is a problem we would have to solve (e.g. by introducing a scss configuration file).
Closing as out of scope / won't fix.