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.

FEATURE MISSING (this function is working with file-loader) Asset modules is only working with relative paths

See original GitHub issue

I have an output that is not in the / path, but instead, it is in /prod/webpack/. So the output is there. The problem:

    output: {
        path: buildDir,
        filename: '[name].[contenthash].js',
       // chunkFilename: '[name].[contenthash].js',
//        publicPath: '{{ app.url_subdir }}/webpack/',
        publicPath: `prod/webpack/`,
        assetModuleFilename: `assets/[hash][ext]`,
    },

So, if everything for the assets is relative generating paths it generates a css like this:

@font-face {
  font-family: 'Font Awesome 5 Brands';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url(prod/webpack/assets/89a52ae1d02b86d61439.eot);
  src: url(prod/webpack/assets/89a52ae1d02b86d61439.eot?#iefix) format("embedded-opentype"), url(prod/webpack/assets/c1210e5ebe4344da5083.woff2) format("woff2"), url(prod/webpack/assets/329a95a9172fdb2cccb4.woff) format("woff"), url(prod/webpack/assets/9e138496e8f1719c6ebf.ttf) format("truetype"), url(prod/webpack/assets/216edb96b562c79adc09.svg#fontawesome) format("svg");
}

So it generates the url: prod/webpack/assets/89a52ae1d02b86d61439.eot But given the CSS is already under a public path: prod/webpack/bundle.13123891f123.css

it tries to load a path like this: /prod/webpack/prod/webpack/assets/ada6e6df937f7e5e8b79.woff2

Before i could only fix it with file-loader useRelativePath: false, but in asset modules it has no option to use absolute, and it is not working, it generates false paths.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
alexander-akaitcommented, Jul 16, 2021

new URL('./path/to/script.js', import.meta.url) syntax, if you need URL of JS file

5reactions
alexander-akaitcommented, Jul 15, 2021

webpack 5 simplify many things so you don’t need many options now, it will just work out of box

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack 5 file-loader is deprecated, how we can solve this ...
FEATURE MISSING (this function is working with file-loader) Asset modules is only working with relative paths webpack/webpack#13796.
Read more >
Webpack 5 - Asset Module - Missing feature of url-loader
I wanted to switch to the webpack 5 asset module as recommended. Unfortunately I miss the function "postTransformPublicPath: (path: any) ...
Read more >
Static Asset Handling - Vite
Importing a static asset will return the resolved public URL when it is served: ... public paths (based on project root during dev)...
Read more >
Asset Modules - webpack
assetModuleFilename and works only with asset and asset/resource module types. Inlining assets. webpack.config.js const path = require('path'); module.exports = ...
Read more >
Webpack — Understanding the 'publicPath' mystery - Medium
So, this would work fine. But when we change it our actual path i.e. resolve('dist') , the webpack is still compiling and generating...
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