Comments (8)
According to webpack documentation: rule.use
must be a list not an object. Here: https://webpack.js.org/configuration/module/#rule-use. So you should change your loader config to:
{
test: /\.svg$/,
include: path.resolve(__dirname, "src/images"),
use: [{
loader: SvgStorePlugin.loader,
options: {
name: "svgs/sprite.svg",
iconName: argv.mode === "development" ? "[name]" : "[name]-[hash:5]"
}
}]
}
from external-svg-sprite-loader.
For anyone else running into this issue and struggling to resolve it:
ALL of your rules, not just the rules for this plugin, need to have an array for the use
parameter. While the Webpack documentation does say it should be an array or a function, it actually still accepts an object (as of webpack v4.28.4), but that will cause this loader to error.
from external-svg-sprite-loader.
Thanks @bensampaio, that solved my problem! However, I swear that my Webpack build was previously working correctly, using the use: {}
syntax. I upgraded from Webpack 4.19.1
to 4.25.1
at the same time that I upgraded external-svg-sprite-loader
from 3.4.1
to 4.0.1
, so maybe something changed with Webpack. At any rate, it looks like I was using use
incorrectly, so thanks for alerting me to the problem. Also, thank you for this great loader!
from external-svg-sprite-loader.
Holy moly, sorry totally missed that.. that fixed it!!! Thank you!
from external-svg-sprite-loader.
It still keeps throwing the "TypeError: loaders is not iterable" error for me :
TypeError: loaders is not iterable
at SvgStorePlugin.injectSpritesIntoRules (../node_modules/external-svg-sprite-loader/lib/SvgStorePlugin.js:177:35)
at SvgStorePlugin.apply (../node_modules/external-svg-sprite-loader/lib/SvgStorePlugin.js:51:14)
at webpack (../node_modules/webpack/lib/webpack.js:51:13)
...
Running webpack 4.41.2
My abbreviated webpack.config.js
:
const SvgStorePlugin = require('external-svg-sprite-loader')
const webpackBaseConfig = function(env) {
return {
module: {
rules: [
{
test: /\.svg$/,
include: path.resolve(__dirname, "../src/imgs/icons"),
use: [{
loader: SvgStorePlugin.loader,
options: {
name: "icons-sprite.svg"
}
}]
}
]
},
plugins: [
new SvgStorePlugin(),
]
}
}
Should this have been fixed or am I doing something not right?
from external-svg-sprite-loader.
@rekker the plugin searches in your webpack rules for occurrences of SvgStorePlugin.loader
so it could be that the problem is in another rule in your config. Can you share the complete config?
from external-svg-sprite-loader.
Sure thing:
// Require Webpack
const webpack = require('webpack')
// Node's built-in path module, which prevents file path issues between operating systems
// Use NodeJS helper module to define correct absolute file reference paths
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
//const ExtractTextPlugin = require('extract-text-webpack-plugin');
// Generates an HTML5 file for you that includes all your webpack bundles in the body using script tags
const HtmlWebpackPlugin = require('html-webpack-plugin')
// const RobotstxtPlugin = require('robotstxt-webpack-plugin').default;
const WebpackNotifierPlugin = require('webpack-notifier')
//const SpriteLoaderPlugin = require('svg-sprite-loader/plugin')
const SvgStorePlugin = require('external-svg-sprite-loader')
//const SVGSpritemapPlugin = require('svg-spritemap-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin')
const devMode = process.env.NODE_ENV !== 'production'
// MAIN WEBPACK CONFIGURATION
const webpackBaseConfig = function(env) {
return {
// Location of the index.js file
// Where Webpack's begins it module compilation process
entry: {
// File containing our custom code
global: './src/javascripts/global.js',
// File containing our custom routes
router: './src/javascripts/router.js',
// File containing code from third party libraries
vendor: ['jquery', 'picturefill', 'svg4everybody', 'slick-carousel']
},
// Newly compiled file configuration
output: {
// Save location of the newly compiled output file
path: path.resolve(__dirname, '../web/build'),
// What to call the newly compiled output file
// [name] will be replaced with the entry objects key value.
filename: '[name].config.base.js',
// Path webpack will reference for looking for public files. Important for dynamic codesplitting
publicPath: 'build/'
},
// Module Rules Systems => Configuration for webpack loaders
module: {
rules: [
{
test: /\.svg$/,
include: path.resolve(__dirname, "../src/imgs/icons"),
use: [{
loader: SvgStorePlugin.loader,
options: {
name: "icons-sprite.svg"
}
}]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
},
{
test: /\.(png|jpg|jpeg)$/,
exclude: /node_modules/,
use: [
{
loader: 'url-loader',
options: {
limit: 25000, // less 25k
name: 'assets/images/[name].[ext]'
}
},
{
loader: 'image-webpack-loader'
}
]
}
]
},
// Don't follow/bundle these modules, but request them at runtime from the environment
// externals: {
// Modernizr: 'modernizr'
// },
// Plugins => Configure webpack plugins
plugins: [
// The DefinePlugin allows you to create global constants which can be configured at compile time.
// Note: process.env.NODE_ENV is set within npm "scripts"
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
//new SpriteLoaderPlugin(),
new SvgStorePlugin(),
//new SVGSpritemapPlugin(),
//new CopyWebpackPlugin([
// { from: './templates', to: 'static-templates' }
//], { ignore: [
//'./web/static-templates/_webpack.templates/_webpack.template.wrapper.twig'
//]
//}),
// Generates an HTML5 file for you that includes all your webpack bundles in the body using script tags
// NOTE: Add excludeChunks: ['fallback']
new HtmlWebpackPlugin({
template: './src/webpack.templates/_webpack.template.wrapper.twig',
filename:
'../../templates/_webpack.templates/_webpack.template.wrapper.twig'
}),
new WebpackNotifierPlugin({alwaysNotify: true})
]
}
}
module.exports = webpackBaseConfig
from external-svg-sprite-loader.
I think the problem is your babel-loader
configuration. As I mentioned above in this thread, according to the webpack docs, use
is meant to be an array. It seems to work as an object but that is not documented so I don't know wether that's by coincidence or intended. This plugin traverses your config based on the multiple use cases described in the webpack docs. Since I would rather not make the traversing more complex I suggest you change your babel-loader
config to this:
{
test: /\.js$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}]
},
Webpack docs of use
: https://webpack.js.org/configuration/module/#ruleuse
My previous comment on this subject for reference: #58 (comment)
from external-svg-sprite-loader.
Related Issues (20)
- Clearer errors when trying to use the latest version with Webpack 4
- Duplicated IDs in icon sprite
- angular13 not generate sprite file
- It doesn't work with webpack 5 cache=filesystem
- SVGO Options HOT 4
- Odd behavior when generating a manifest file HOT 8
- consistency with others loaders in manifest.json HOT 4
- Error when defining Rule.use as a function HOT 2
- Using `webpack-chain` breaks default options HOT 1
- It doesn't generate svg sprite HOT 17
- The module removes "fill" attribute when converting to symbol HOT 2
- Alternative (simpler) way to address the images inside the sprite (no math) HOT 1
- deprecation warning for chunk.files in webpack 5 HOT 1
- The sprite status is blocked: origin (webpack --mode production) HOT 23
- Can't run in storybook
- Deprecation warning for Chunk.modulesIterable
- Breaks with [email protected] HOT 3
- SvgStorePlugin fails if there are any other unrelated errors in the build HOT 1
- Support and compatibility with Webpack 4 regarding mini-css-extract-plugin HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from external-svg-sprite-loader.