Closed arodionova closed 6 years ago
The API to make changes to webpack was changed for v2. You could submit a PR to that repo to upgrade the plugin
@KyleAMathews hey! I tried to change the code of that plugin but I couldn't. Could you please take a look at my code?
The original code of that plugin:
exports.modifyWebpackConfig = ({ config }, options = {}) => {
config.loader('url-loader', {
test: /\.(jpg|jpeg|png|gif|mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
loader: 'url',
query: {
limit: 10000,
name: 'static/[name].[hash:8].[ext]',
},
});
config.loader('svg-sprite', {
loader: 'svg-sprite-loader',
test: /\.svg$/,
query: options,
});
return config;
};
My version:
exports.onCreateWebpackConfig = ({ actions, loaders }, options = {}) => {
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.(jpg|jpeg|png|gif|mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
use: [
loaders.url({
limit: 10000,
name: 'static/[name].[hash:8].[ext]',
}),
],
},
{
test: /\.svg$/,
use: [
{
loader: require.resolve('svg-sprite-loader'),
options,
},
],
},
]
}
})
};
I got the config that looks properly but the plugin still doesn't work.
Is there anything wrong?
Hard to say without trying it out locally. Your code looks good but you should try submitting a PR in the repo for the plug-in and enlist the maintainer there's help upgrading the plug-in.
Thanks!
@oobidin I'd like to know your final solution to this issue. Thanks!
@ailuyao I've just created PR to the plugin repo.
https://github.com/marcobiedermann/gatsby-plugin-svg-sprite/pull/6
You can wait for the merge a bit or just use my piece of code inside you gatsby-node.js
or plugins
folder.
Description
I've been using gatsby-plugin-svg-sprite with previous Gatsby version. After migrating to v2 it stopped working. No svg sprite is cteated and no errors in log
Steps to reproduce
Expected result
After import svg sprite should be created and added to page. `Import Icon from './icon.svg' should import file object You could use to import it
Actual result
No sprite is created. `Import svg from './file.svg' imports only file path.
Environment
File contents (if changed)
gatsby-config.js
:package.json
:gatsby-node.js
: N/Agatsby-browser.js
: N/Agatsby-ssr.js
: N/A