rollup / rollup-plugin-commonjs

This module has moved and is now available at @rollup/plugin-commonjs / https://github.com/rollup/plugins/blob/master/packages/commonjs
MIT License
502 stars 126 forks source link

What does 'ignoreGlobal' do? #319

Closed oHaiyang closed 4 years ago

oHaiyang commented 6 years ago

Sorry for asking this question here. I do not quite understand how ignoreGlobal changes the behavior of the plugin.

Here is my code and config:

// src/index.js
export default function () {
  console.log(typeof global.setTimeout);
}
// rollup.conf.js
import commonjs from 'rollup-plugin-commonjs';

export default [
  {
    input: 'src/index.js',
    output: {
      name: 'Detector',
      file: 'bundle.js',
      format: 'umd',
    },
    plugins: [
      commonjs({
        ignoreGlobal: false,
      }),
    ],
  },
];

run rollup -c to get bundle.js:

(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  typeof define === 'function' && define.amd ? define(factory) :
  (global.Detector = factory());
}(this, (function () { 'use strict';

  function index () {
    console.log(typeof global.setTimeout);
  }

  return index;

})));

It looks nothing happened to the global variable used in the exported function. In my understanding, this option tells the plugin to deal with global used in code(somehow transform it?). Am I totally misunderstood?

aleclarson commented 6 years ago

This is a good question.

Running this test with ignoreGlobal enabled and disabled reveals that nothing changes.

So either the test is broken, or the feature is. :)

shellscape commented 4 years ago

Hey folks (this is a canned reply, but we mean it!). Thanks to everyone who participated in this issue. We're getting ready to move this plugin to a new home at https://github.com/rollup/plugins, and we have to do some spring cleaning of the issues to make that happen. We're going to close this one, but it doesn't mean that it's not still valid. We've got some time yet before the move while we resolve pending Pull Requests, so if this issue is still relevant, please @ me and I'll make sure it gets transferred to the new repo. :beer: