admin管理员组文章数量:1410712
Let's assume, we do have few js libs, that installed into our bundle. And, for some reason, I need to use a library from node_modules of a library. I can do import it via
import thing from 'somelib/node_modules/thing';
And I want to do just:
import thing from 'thing';
But behind the scenes, webpack will know - the path should be 'somelib/node_modules/thing'
How can I change/override a specific import path in my webpack config file, so my node will bring me a package from the destination that I want?
Let's assume, we do have few js libs, that installed into our bundle. And, for some reason, I need to use a library from node_modules of a library. I can do import it via
import thing from 'somelib/node_modules/thing';
And I want to do just:
import thing from 'thing';
But behind the scenes, webpack will know - the path should be 'somelib/node_modules/thing'
How can I change/override a specific import path in my webpack config file, so my node will bring me a package from the destination that I want?
Share Improve this question edited Dec 4, 2018 at 15:20 Maksym Labutin 5711 gold badge8 silver badges17 bronze badges asked Dec 4, 2018 at 15:01 WebArtisanWebArtisan 4,23612 gold badges47 silver badges66 bronze badges3 Answers
Reset to default 3I think you are looking for resolve.alias
https://webpack.js/configuration/resolve/#resolve-alias
In your webpack config, specify the resolve.modules
This example from the webpack documentation adds the "src" folder.
module.exports = {
//...
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules']
}
};
Or if you really don't want this affecting your other entry points, you could create separate webpack configs. (They can still import settings from a primary file) that allows you to set resolve.aliases
and resolve.modules
independently for each entry point.
module.exports = {
//...
resolve: [
function() {
regexNpmPgkName.test(xxx) {
callback()
}
}
]
};
本文标签: javascriptWebpack change import path for a specific packageStack Overflow
版权声明:本文标题:javascript - Webpack change import path for a specific package - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744936529a2633221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论