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.

How do I migrate file-loader with postTransformPublicPath to asset?

See original GitHub issue

We currently apply the following file-loader configuration:

{
	test: imageFileExtensions,
	loader: "file-loader",
	options: {
		name: "[path][name].[ext]",
		outputPath: url => getRelativeImagePath(url),
		publicPath: url => getRelativeImagePath(url),
		postTransformPublicPath: p => `__webpack_public_path__ + ${p}`
	}
}

According to the docs, migrating this loader with the asset module should look something like this:

{
	test: imageFileExtensions,
	type: "asset/resource",
	generator: {
		filename: "[path][name][ext]",
		outputPath: url => getRelativeImagePath(url),
		publicPath: url => getRelativeImagePath(url)
		// postTransformPublicPath???
	}
}

However, as the commented line indicates, there is no support for the postTransformPublicPath option in the asset module…

How would I proceed from here, any suggestions?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vankopcommented, Apr 21, 2022

there is no postTransformPublicPath alternative. webpack does __webpack_public_path__ + ${p} by default

0reactions
vankopcommented, Apr 21, 2022

e.g. you have webpack.config.js

module.exports = {
  output: { publicPath: "/public" },
  module: {
     rules: [
       {
         type: "asset",
         generator: {
             publicPath: "/public-asset"
         }
       }
     ]
  }
};

webpack will generate /public-asset for assets, if you need to respect output.publicPath you should pass generator.publicPath="/public/public-asset"


btw if you need to respect output.publicPath, you can just omit generator publicPath and outputPath options

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrate from file-loader with postTransformPublicPath to ...
I want to migrate file-loader to asset modules. file-loader is deprecated. I use this feature for CDN. postTransformPublicPath: (p) ...
Read more >
file-loader - webpack - JS.ORG
DEPRECATED for v5: please consider migrating to asset modules . The file-loader resolves import / require() on a file into a url and...
Read more >
A Note About Refactoring and Migrating a Project to ...
I tried to stop the Assets Module by following the document. It could be a way to avoid the problem. When using the...
Read more >
Untitled
(png|jpe?g|gif)$/i, loader: 'file-loader', options: { outputPath: (url, resourcePath, context) => { // `resourcePath` is original absolute path to asset ...
Read more >
Static Asset Handling
png during development, and become /assets/img.2d8efhg.png in the production build. The behavior is similar to webpack's file-loader . The difference is that ...
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