Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples to not account for Webpacks default images rule #142

Open
TrevinAvery opened this issue Jul 8, 2021 · 0 comments
Open

Examples to not account for Webpacks default images rule #142

TrevinAvery opened this issue Jul 8, 2021 · 0 comments

Comments

@TrevinAvery
Copy link

Webpack's default rule images conflicts with all of the provided examples. To get this to work (at least with a new project created by the vue-cli), you need to either place your new rule before the default rule, or delete the default rule. This detail should be added to the examples.

I don't know how to do this with the standard config, but with chainWebpack, it looks something like this:

module.exports = {
	chainWebpack: config => {
		config.module
			.rule('responsive-loader')
			.before('images')
			.test(/\.(jpe?g|png|webp)$/i)
			// if the import url looks like "some.png?srcset..."
			.resourceQuery(/srcset/)
			.use('responsive-loader')
			.loader('responsive-loader')
			.options({
				adapter: require('responsive-loader/sharp'),
				sizes: [320, 640, 960, 1200, 1800, 2400],
				placeholder: true,
				placeholderSize: 50,
			})
	},
}

Note the use of .before('images'). That part is key. Here is my StackOverflow post from when this caused me hours of pain, just in case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant