file-loader 打包路径保持项目结构
file-loader作用
用来将文件原封不动地移动到dist目录中, dist目录由webpack配置中的webpack.config.output.path属性指定.
name参数及其内置变量
可以为file-loader指定name参数, 以指定文件存放到webpack.config.output.path目录下的哪个子路径中.
name参数可以使用以下内置变量:
[path][name][ext]
context参数
context参数影响name参数的内置变量[path], 如果不指定context参数, 那么默认是项目根目录.
由于源码一般存放在项目根目录下的src目录下, 因此一般指定context参数为src:
import 'file-loader?context=src&name=path_to_dist!path_to_file';
如何import
import path_of_testjs from 'file-loader?context=src&name=js/[path][name].[ext]!../lib/test.js';
浙公网安备 33010602011771号