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 insideabc
? Or modifyingxyz
library to be exposed as a globalabc
variable? – dreyescat Commented Nov 5, 2015 at 9:51
1 Answer
Reset to default 4An 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.
本文标签:
版权声明:本文标题:javascript - Use Webpack library and libraryTarget configuration to set our custom library via global var - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745287856a2651606.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论