Search code examples
internet-explorer-11vue-cli-3

vue cli3 lib with IE11 support


According to the documentation (https://cli.vuejs.org/guide/build-targets.html#library), it's not clear to me how to integrate babel to make the lib built be IE11-friendly... I have to make a npm package from a Vue component.

My npm script in package.json is: vue-cli-service build --target lib src/MyComponent.vue

I've put a correct "browserslist" in package.json.

It seems that I have to use a babel.config.js with a preset.

Not sure of what to install as dev dependencies and what to configure...

Anyone has a working sample lib or some guidance, please?


Solution

  • Answering to myself :-) It was documented but at several places. So...

    • Add these dev dependencies:

    npm install --save-dev @vue/cli-plugin-babel @babel/preset-env

    • Add this dependency:

    npm install --save @babel/polyfill current-script-polyfill

    • In your main Vue file, import 'current-script-polyfill' before anything else
    • Indeed define a browserslist in package.json
    • Indeed have a babel.config.js with
        presets: [
          ['@vue/app']
        ]
      }
    

    Edit : now we use a .browserlistrc file instead of definition in package.json. Here is what we use, thanks for asking:

    > 1%
    last 2 versions
    not ie < 11