Reputation: 391
I want to generate a single sprite svg file from multiple svg files.would like to use webpack for it.am unable to get the sprite svg created whatsoever.
I have tried with webpack 5 first. but it didn't work since the svg-sprite-loader doesn't support it yet. so downgraded to webpack 4.
Here's my webpack config:
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
module.exports = {
output: {
path: path.join(__dirname, "build"), // the bundle output path
publicPath: 'build/',
filename: "bundle.js", // the name of the bundle
},
plugins: [
new HtmlWebpackPlugin({
template: "src/index.html", // to import index.html file inside index.js
}),
new SpriteLoaderPlugin()
],
devServer: {
port: 3030, // you can change the port
},
module: {
rules: [
{
test: /\.(js|jsx)$/, // .js and .jsx files
exclude: /node_modules/, // excluding the node_modules folder
use: {
loader: "babel-loader",
},
},
{
test: /\.(sa|sc|c)ss$/, // styles files
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.svg$/,
use: [
{
loader: 'svg-sprite-loader',
options: {
extract: true,
publicPath: '/static/'
}
},
'svgo-loader'
]
}]
}
};
whatsoever, sprite file is not created. public path static is also not created. Can someone help please?
Here's my package.json
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack --config webpack.config.js --mode development",
"build": "webpack --mode production",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"styled-components": "^6.1.8"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.10.4",
"babel-loader": "^8.2.2",
"css-loader": "^3.2.0",
"html-webpack-plugin": "^4.5.2",
"sass": "^1.26.10",
"sass-loader": "^8.0.2",
"style-loader": "^1.0.0",
"svg-sprite-loader": "^4.1.3",
"svgo-loader": "^4.0.0",
"url-loader": "^2.3.0",
"webpack": "^4.47.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.15.2"
}
}
Upvotes: 0
Views: 243