Rollup Babel duplicate definitions in output file

Viewed 524

I'm trying to use rollup with babel but in output file I got duplicate definitions:

 var Projection =
  /*#__PURE__*/
  function () {
    /**
     * @param {Options} options Projection options.
     */
    function Projection(options) {
      _classCallCheck(this, Projection);

      /**
       * @private
       * @type {string}
       */
      this.code_ = options.code;

and

var Projection$1 = function Projection(options) {
    /**
     * @private
     * @type {string}
     */
    this.code_ = options.code;

    /**
     * Units of projected coordinates. When set to `TILE_PIXELS`, a
     * `this.extent_` and `this.worldExtent_` must be configured properly for each
     * tile.
     * @private
     * @type {module:ol/proj/Units}
     */
    this.units_ = /** @type {module:ol/proj/Units} */ (options.units);

My rollup config

// Rollup configuration for the full build

const path = require('path');
import noderesolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import {uglify} from 'rollup-plugin-uglify';
import sourcemaps from 'rollup-plugin-sourcemaps';
import babel from 'rollup-plugin-babel';
import alias from 'rollup-plugin-alias';
import minify from 'rollup-plugin-babel-minify';

const prod = process.env.BUILD === 'production';
const cesiumSource = 'node_modules/cesium/Source';
//const cesiumSource = 'Source/Cesium';
const olSource = 'ol_build/openlayers/src/ol';

const plugins = [
  noderesolve(),
  commonjs(),
];

// const uglifyPlugin = uglify({
    // compress: {
      // sequences: false, // workaround uglify bug with sequences
      // drop_console: true
    // }
  // });

const babelPlugin =  babel({
    babelrc: false,
    presets: [["@babel/preset-env", { modules: false }]],
    exclude: ['node_modules/**']
    // externalHelpers: true,
    // plugins: ["@babel/external-helpers"]
    // runtimeHelpers: true,
    // plugins: ["@babel/plugin-transform-runtime"]
});

const aliasPlugin = alias({
    ol: path.resolve(__dirname, olSource),
    Cesium: path.resolve(__dirname, cesiumSource)
  });

if (prod) {
  //plugins.push(uglifyPlugin);
  //plugins.push(minify);
}

plugins.push(babelPlugin);
plugins.push(aliasPlugin);
plugins.push(sourcemaps());

export default {
  input: './dist/index.js',
  output: [
    {file: prod ? './dist/ol.js' : './dist/ol-debug.js', format: 'iife', sourcemap: true}
  ],
  plugins
  //external: ['ol'],
};

and package.json config related to babel and rollup:

"devDependencies": {
    "@babel/core": "^7.1.2",
    "@babel/preset-env": "^7.1.0",
  "rollup": "0.65.2",
    "rollup-plugin-babel": "^4.0.3",
    "rollup-plugin-babel-minify": "^6.1.1",
    "rollup-plugin-commonjs": "9.1.6",
    "rollup-plugin-node-resolve": "3.4.0",
    "rollup-plugin-sourcemaps": "0.4.2",
    "rollup-plugin-uglify": "5.0.2",

 "dependencies": {
    "rollup-plugin-alias": "^1.4.0"
  }

When I use only rollup without babel in output file there is only 1 definition of "Projection".

Original class:

class Projection {

  /**
   * @param {Options} options Projection options.
   */
  constructor(options) {
    /**
     * @private
     * @type {string}
     */
    this.code_ = options.code;

    /**
     * Units of projected coordinates. When set to `TILE_PIXELS`, a
     * `this.extent_` and `this.worldExtent_` must be configured properly for each
     * tile.
     * @private
     * @type {import("./Units.js").default}
     */
    this.units_ = /** @type {import("./Units.js").default} */ (options.units);

I tried use previous version of babel for rollup and also tried use "external-helpers" plugin but still not work.

Rollup and babel are new for me.

Because of those duplicate definitions I got false when compare types with instanceof operator. Why there are duplicate definitions and how configure babel to get only one definition?

0 Answers
Related