tomblachut / svelte-intellij

Svelte components in WebStorm and friends
MIT License
485 stars 38 forks source link

Imports from webpack alias not working? #211

Closed david1602 closed 3 years ago

david1602 commented 3 years ago

Our webpack.config.js looks a little like this (trimmed down of course)

module.exports = {
    resolve: {
        mainFields: ['svelte', 'module', 'browser', 'main'],
        extensions: ['.ts', '.mjs', '.svelte', '.js'],
        alias: {
            '@components': path.resolve(__dirname, 'src', 'shared', 'components'),
            '@shared': path.resolve(__dirname, 'src', 'shared'),
        },
    },
}

And that components folder has an index.ts file that exports an object with various components in it. Looking somewhat like export {Button, Checkbox, Col, Dropdown, Form, Row}. These components come from an external dependency and are re-exported here. If we write any custom components, it's also importing from '../../../shared/components/name.svelte rather than @components/name. Is it possible to get that working? I read that there were problems with node modules in a different issue, so I'm not sure if there's a potential misconfiguration on our end, or it just isn't possible with the plugin.

We're using the most recent version of IntelliJ Ultimate.

Please let me know if I could provide any further information to potentially resolve the issue.

vgpechenkin commented 3 years ago

Hi. IDEA uses tsconfig to resolve aliase. Add paths and baseUrl

"paths": {
            "lib/*": ["src/lib/*"],
        } 
tomblachut commented 3 years ago

Hello @david1602, sorry for delayed reply, I was off.

custom components [...] importing

Unfortunately for now that part is not respecting aliases, so nothing wrong on your end. It's high on todo list 🙂

To add to @vgpechenkin, for other imports, if you use JS instead of TS you need to replace tsconfig with equivalent jsconfig.

tomblachut commented 3 years ago

Related to #61