admin管理员组

文章数量:1418361

I have a library "xyz" which is currently being imported as a node module through npm registry.

Now, I want to add it as a library and expose it via global name "abc".

I want to use webpack configuration to achieve that.

So, I understand that this is the config i need to add to my webpack config?:

 "output": {
        "path": SHELL_PATH + filePath.dist,
        "libraryTarget": "var",
        "library": "abc"
    }

But, then how do i link abc to my xyz library so that the methods inside my abc library are exposed through global name "abc"?

What else do i need to do?

I have a library "xyz" which is currently being imported as a node module through npm registry.

Now, I want to add it as a library and expose it via global name "abc".

I want to use webpack configuration to achieve that.

So, I understand that this is the config i need to add to my webpack config?:

 "output": {
        "path": SHELL_PATH + filePath.dist,
        "libraryTarget": "var",
        "library": "abc"
    }

But, then how do i link abc to my xyz library so that the methods inside my abc library are exposed through global name "abc"?

What else do i need to do?

Share Improve this question edited Jan 11, 2018 at 11:33 Louis 152k28 gold badges286 silver badges329 bronze badges asked Nov 3, 2015 at 23:00 AshimaAshima 4,8346 gold badges41 silver badges64 bronze badges 1
  • Do you mean wrapping xyz library inside abc? Or modifying xyz library to be exposed as a global abc variable? – dreyescat Commented Nov 5, 2015 at 9:51
Add a ment  | 

1 Answer 1

Reset to default 4

An option could be just wrapping xyz inside abc library and expose abc library as a global variable.

webpack.config.js

module.exports = {
  entry: './index.js',
  output: {
    libraryTarget: 'var',
    library: 'abc',
    path: './dist',
    filename: 'abc.js'
  }
};

index.js

module.exports = {
  xyz: require('xyz')
};

if you want to access xyz fields through abc.xyz, or

module.exports = require('xyz');

if you want to export xyz fields through abc directly.

本文标签: