JetBrains / svg-sprite-loader

Webpack loader for creating SVG sprites.
MIT License
2.01k stars 271 forks source link

warning in ./src/assets/icons/home.svg Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders #478

Open huawuhe opened 2 years ago

huawuhe commented 2 years ago

Do you want to request a feature, report a bug or ask a question?

What is the current behavior?

What is the expected behavior?

If the current behavior is a bug, please provide the steps to reproduce, at least part of webpack config with loader configuration and piece of your code. The best way is to create repo with minimal setup to demonstrate a problem (package.json, webpack config and your code). It you don't want to create a repository - create a gist with multiple files

If this is a feature request, what is motivation or use case for changing the behavior?

Please tell us about your environment:

Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

huawuhe commented 2 years ago

const path = require("path"); module.exports = { publicPath: process.env.NODE_ENV === "production" ? "" : "/", outputDir: process.env.NODE_ENV === "production" ? "dist" : "devDist", lintOnSave: false, // 配置svg chainWebpack: (config) => { config.module.rules.delete("svg"); config.module .rule("svg-sprite-loader") .test(/.svg$/) .include.add(path.resolve("@/assets/icons")) .end() .use("svg-sprite-loader") .loader("svg-sprite-loader") .options({ symbolId: "icon-[name]", }); }, css: { loaderOptions: { scss: { prependData: @import "./src/styles/main.scss";, }, }, }, };

huawuhe commented 2 years ago

top is my code,lastly i change code at here, before: .include.add(path.resolve("@/assets/icons")) change: .include.add(path.resolve("src/assets/icons")) hope can help you