question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible to have image paths resolved using webpack's resolve.alias?

See original GitHub issue

It doesn’t look like this is currently supported by the loader, but please correct me if I’m wrong!

In my webpack.config.js

  resolve: {
        alias: {
            // Allow friendly reference to core modules
            "core": path.resolve(config.root, "../core")
        }
    },

https://webpack.github.io/docs/configuration.html#resolve-alias

I’m aliasing core to a path, so I can have shorter friendlier paths to the core across my application, this works fine in my js files.

As it stands my images still need relative paths, to reference common assets in the core:

<img src="../../../core/symbols/image.svg">

If the resolve.alias were factored into path resolving, this could been simplified to:

<img src="core/symbols/image.svg">

Would this be possible?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
dmackermancommented, Oct 12, 2016

Have you tried using the ~ character in your paths to respect aliases? ie:

<img src="~images/something.png" />

This works for us. We’re using Webpack 2.

0reactions
itsashis4ucommented, Apr 24, 2017

@dmackerman Didn’t work for me in the .js file, worked in .scss file

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve | webpack
When enabled, symlinked resources are resolved to their real path, not their symlinked location. Note that this may cause module resolution to fail...
Read more >
How to Create a Path Alias in Webpack - Bitovi
Open your Webpack.config.js file. · If it's not already there, add a resolve property to the configuration object and make it an empty...
Read more >
Webpack resolve.alias does not work with typescript?
This solved my problem: we were using a custom module syntax which defined aliases to files other than index . Renaming the files...
Read more >
Folder aliases using webpack • Today I Learned - Graffino
If the location of any of the folders defined with aliases ever changes, you no longer need to update all the imports -...
Read more >
Webpack Aliases Keep My Code Sane - DEV Community ‍ ‍
How to resolve relative paths cleanly in JavaScript and TypeScript by using webpack aliases. Tagged with javascript, webpack, typescript, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found