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

Vuecli 5.x support #185

Open
johnnyhwa opened this issue Mar 10, 2022 · 7 comments
Open

Vuecli 5.x support #185

johnnyhwa opened this issue Mar 10, 2022 · 7 comments

Comments

@johnnyhwa
Copy link

the loader not work in webpack5 environment

@CcrisS
Copy link

CcrisS commented Mar 17, 2022

try something like this:

config.module.rules.delete('svg')
config.module
  .rule('svg')
  .test(/\.(svg)(\?.*)?$/)
  .use('vue-loader')
  .loader('vue-loader')
  .end()
  .use('vue-svg-loader')
  .loader('vue-svg-loader')

@johnnyhwa
Copy link
Author

johnnyhwa commented Mar 18, 2022

try something like this:

config.module.rules.delete('svg')
config.module
  .rule('svg')
  .test(/\.(svg)(\?.*)?$/)
  .use('vue-loader')
  .loader('vue-loader')
  .end()
  .use('vue-svg-loader')
  .loader('vue-svg-loader')

@CcrisS Thanks, bro. It works
I think it's because the 'asset modules' in webpack 5

@johnnyhwa johnnyhwa reopened this Mar 18, 2022
@nirali35
Copy link

It doesn't work for me. @CcrisS are you able to help?

This is what my entire vue.config.js looks like.

module.exports = {
  chainWebpack: (config) => {
    config.module.rules.delete('svg')
    config.module
      .rule('svg')
      .test(/\.(svg)(\?.*)?$/)
      .use('vue-loader')
      .loader('vue-loader')
      .end()
      .use('vue-svg-loader')
      .loader('vue-svg-loader')
  },
}

@sidneygijzen
Copy link

This solution works for me.

@Deuscx
Copy link

Deuscx commented Apr 28, 2022

    const svgRule = config.module.rule('svg')
    svgRule.uses.clear()
      svgRule.oneOf("inline")
      .type('javascript/auto')
      .resourceQuery(/inline/)
      .use('vue-loader')
      .loader('vue-loader')
      .end()
      .use('vue-svg-loader')
      .loader('vue-svg-loader');

try this

@men232
Copy link

men232 commented May 14, 2022

I use this config for my project, the basic idea to import svg as a component by using query parameters, for example

Example:

import LogoIcon from "/img/logo.svg?vue-component";

vue.config.js

	chainWebpack: (config) => {
		const svgRule = config.module.rule('svg');

		// Remove regular svg config from root rules list
		config.module.rules.delete('svg');

		config.module.rule('svg')
			// Use svg component rule
			.oneOf('svg_as_component')
				.resourceQuery(/vue-component/)
				.test(/\.(svg)(\?.*)?$/)
				.use('babel-loader')
					.loader('babel-loader')
					.end()
				.use('vue-svg-loader')
					.loader('vue-svg-loader')
					.options({
						svgo: {
							plugins: [
								{ prefixIds: true },
								{ cleanupIDs: true },
								{ convertShapeToPath: false },
								{ convertStyleToAttrs: true }
							]
						}
					})
					.end()
				.end()
			// Otherwise use original svg rule
			.oneOf('svg_as_regular')
				.merge(svgRule.toConfig())
				.end();
	},

@linghengqian
Copy link

  • CC @damianstasik

  • I think this requires a documentation related PR?

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

7 participants