简体   繁体   English

Webpack 2从子目录导入

[英]Webpack 2 import from subdirectory

In webpack 2, I'd like to be able to specify subdirectories within specific npm packages to be used when importing them. 在webpack 2中,我希望能够在导入它们时使用特定npm包中的子目录。

Example: 例:

// Turn this:
import Module from '@orgscope/module';

// Into this:
import Module from '@orgscope/module/dist';

I imagine the resolve section of the config should be able to do what I want but after reading the documentation, I'm still not very clear on how I can achieve the above. 我想配置的解析部分应该能够做我想要的但是在阅读完文档后,我仍然不太清楚如何实现上述目标。

Update 1 更新1

Adding the package scope 添加包范围

You're absolutely right on using resolve section of webpack. 你完全正确使用webpack的resolve部分。 You can use it something like: 你可以使用它:

resolve: {
    alias: {
       'module': 'module/dist'
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM