输出文件中的汇总Babel重复定义

时间:2018-11-14 14:32:26

标签: javascript npm babel rollup

我正在尝试对babel使用汇总,但是在输出文件中我得到了重复的定义:

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

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

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);

我的汇总配置

// 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'],
};

和与babel和汇总相关的package.json配置:

"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"
  }

当我在输出文件中仅使用没有babel的汇总时,只有“投影”的1个定义。

原始课程:

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);

我尝试使用先前版本的babel进行汇总,也尝试使用“外部帮助程序”插件,但仍然无法正常工作。

汇总和通天塔对我来说是新的。

由于这些重复的定义,当我将类型与instanceof运算符进行比较时,我得到了错误。为什么会有重复的定义,以及如何将babel配置为仅获得一个定义?

0 个答案:

没有答案