简体   繁体   中英

SVGO config file

With svgo 1.3.2 I used to run this command:

svgo --pretty --disable={removeUnusedNS,removeUselessDefs,removeUselessStrokeAndFill} file.svg -o file.min.svg

I updated to svgo 2.3.0 and now I get:

error: unknown option '--disable={removeUnusedNS,removeUselessDefs,removeUselessStrokeAndFill}'

So I tried to create a svgo.config.js like this:

const { extendDefaultPlugins } = require('svgo');
module.exports = {
  plugins: extendDefaultPlugins([
    {
      name: 'removeUnusedNS',
      active: false
    },
    {
      name: 'removeUselessDefs',
      active: false
    },
    {
      name: 'removeUselessStrokeAndFill',
      active: false
    }
  ])
}

but I just get the error:

Error: Cannot find module 'svgo'

Require stack: C:\Users\jpprade\Documents\vrac\svgo.config.js C:\Users\jpprade\AppData\Roaming\npm\node_modules\svgo\lib\svgo-node.js C:\Users\jpprade\AppData\Roaming\npm\node_modules\svgo\lib\svgo\coa.js C:\Users\jpprade\AppData\Roaming\npm\node_modules\svgo\bin\svgo

  • at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
  • at Function.Module._load (internal/modules/cjs/loader.js:686:27)
  • at Module.require (internal/modules/cjs/loader.js:848:19)
  • at require (internal/modules/cjs/helpers.js:74:18)
  • at Object. (C:\Users\jpprade\Documents\vrac\svgo.config.js:1:34)
  • at Module._compile (internal/modules/cjs/loader.js:955:30)
  • at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
  • at Module.load (internal/modules/cjs/loader.js:811:32)
  • at Function.Module._load (internal/modules/cjs/loader.js:723:14)
  • at Module.require (internal/modules/cjs/loader.js:848:19)

svgo is install (globaly)

How can I run svgo with those 3 plugins disabled using to config file (or not)?

Thanks !

What is the output when you run svgo -v ?

It is possible that you are inside a project that has an older version as a dependency which takes precedence over the global svgo package.

You can try require using the absolute path to svgo 2.3.0. For instance mine was like that require('/home/nili/.nvm/versions/node/v14.16.1/lib/node_modules/svgo');

I think it could also be in /usr/local/lib/node_modules/svgo if you installed it as root.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM