JetBrains / svg-sprite-loader

Webpack loader for creating SVG sprites.
MIT License
2.02k stars 270 forks source link

svg-baker-runtime uses ES6 code that needs to be transpiled #385

Closed sastraxi closed 4 years ago

sastraxi commented 4 years ago

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

This is a bug.

What is the current behavior?

svg-baker-runtime contains ES6 code that needs to be transpiled to run on targets that do not support ES6.

What is the expected behavior?

svg-baker-runtime has been properly transpiled in a build step to ES5.

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

Our application supports IE11, and we've had to add a manual transpilation step into our webpack config in order to make sure our final bundle contains fully backwards-compatible code. This is the only module that we have to do this for, and ideally this should be fixed upstream.

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)

The webpack rule (in our code) that fixes this and brings back support for IE11:

            ...
            test: /\.js$/,
            exclude: [
                /* don't transpile node_modules, except for svg-baker-runtime */
                /node_modules\/(?!svg-baker-runtime)/,
            ],
            ...
sastraxi commented 4 years ago

Just doing some more investigation here, and this has to do with how the code gets exported. I see now looking through the distribution that svg-baker-runtime/browser-sprite.js is properly transpiled, as expected. What works:

import BrowserSprite from 'svg-baker-runtime/browser-sprite'

What doesn't work:

import BrowserSprite from 'svg-baker-runtime'

It feels like this is because of main vs module:

  "main": "browser-sprite.js",
  "module": "src/browser-sprite.js",

Perhaps the trick here is to add "browser": "browser-sprite.js" as per https://github.com/webpack/webpack/issues/5756#issuecomment-504919312

kisenka commented 4 years ago

Shipped in svg-sprite-loader@4.2.5, please check