webpack4 大纲概论-module-resolution(八)
https://v4.webpack.js.org/concepts/module-resolution/
解决方案,Module Resolution
解决方案是定位模块绝对位置的库,一个模块可以作为另一个模块的依赖项:
module-resolution
import foo from 'path/to/module';
或者:
require('path/to/module');
webpack解析规则(使用增强解析<enhanced-resolve>):
1,绝对定位:
import '/home/me/file'; import 'C:\\Users\\me\\file';
2,相对定位:
import '../src/file1'; import './file2';
3,模块路径(Module paths):
import 'module'; import 'module/lib/file';
用 resolve.modules 识别,resolve.alias 配置别名
指向文件:如果路径有扩展名则直接解析,如果没有,就使用 resolve.extensions 定义的规则解析
指向文件夹:如果有 package.json 文件,按照 resolve.mainFields 配置顺序查找 json文件中的路径;如果没有 package.json 文件,或者 resolve.mainFields 没有返回可用的路径,就查看 import/required 所需目录中是否有匹配的文件名;然后用 resolve.extensions 相似的方式解析。
webpack根据您的构建目标为这些选项提供了合理的默认值。
编译模式(watch mode),开启的时候,每个文件系统访问都被缓存;如果关闭了监视模式,则在每次编译之前清除缓存

浙公网安备 33010602011771号