Skip to content

How to import image in js files? #80

Answered by webdiscus
mybardaklar asked this question in Q&A
Discussion options

You must be logged in to vote

Now please try the fixed fork.
It works!

See the changes in:

  • webpack.common.js
{
  test: /\.(png|jpe?g|webp)/,
  oneOf: [
	// use responsive-loader in JS file
	{
		issuer: /\.(js|ts)$/,
		type: 'javascript/auto', // <== mega important for usage in JS
		use: {
			loader: 'responsive-loader',
			options: {
				name: 'assets/img/[name].[hash:8]-[width]w[ext]',
			},
		},
	},
	// use responsive-loader in CSS, Pug
	{
		type: 'asset/resource', // <== mega important for usage in Pug/CSS
		use: {
			loader: 'responsive-loader',
			options: {
				name: 'assets/img/[name].[hash:8]-[width]w[ext]',
			},
		},
	},
  ],
},
  • src/app/app.js
// ==> load the source image as an object via 'responsive-loa…

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@webdiscus
Comment options

@mybardaklar
Comment options

@webdiscus
Comment options

@webdiscus
Comment options

Answer selected by mybardaklar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants