2

If I use imports-loader, what does it mean exports=>false part in configuration? It should inject variable var exports = false, but I don't know when and why I need this variable.

module : {
    loaders : [
            {
                test : /eonasdan-bootstrap-datetimepicker/,
                loader : 'imports?define=>false,exports=>false,moment=moment'
            }]
}
cchamberlain
  • 17,444
  • 7
  • 59
  • 72
Matt
  • 8,195
  • 31
  • 115
  • 225

1 Answers1

4

Imports is for shimming third party code that is expecting global to be defined such as jQuery $ or AMD's define. The reason you might want to do this is because module bundlers often bundle to formats that both AMD and CommonJS understand aka universal module definition UMD format. When importing a UMD module it will first check to see if define (AMD) exists and then exports (CommonJS). Webpack has an easier time parsing CommonJS (nodes native format) so setting define to false explicitly tells webpack to not parse it as an AMD module.

UPDATE

It seems like they are likely disabling all module exports and defining moment as the moment js library. I would guess that the code in that library is extending the bootstrap datepicker control with features from moment.

cchamberlain
  • 17,444
  • 7
  • 59
  • 72
  • I know why we use `var define = false`, but I asked what is `var exports = false` – Matt Oct 30 '16 at 18:46
  • @Matt that would be disabling CommonJS [exports](https://www.sitepoint.com/understanding-module-exports-exports-node-js/) in this case. Usually when I use this module I read through the code I'm trying to import and adjust the imports string accordingly. – cchamberlain Oct 30 '16 at 19:16
  • It seems like they are defining those both as false to disable all module exports and setting references to moment to the moment library. The defines would get injected at the top of the code. – cchamberlain Oct 30 '16 at 19:20