Webpack (二) 自定义Loader
API文档
https://webpack.js.org/api/loaders/
Loader要素
- 资源内容
资源内容通过my-kotlin-loader.js导出的函数的形式参数传递进来.
function custom_loader(file_content) {
console.log({ '编译Kotlin': file_content }); // 需要处理的文件内容通过形式参数传递
}
module.exports = custom_loader;
- 资源路径
this.resourcePath及其查询字符串this.resourceQuery
import './main.kt?ok';
// this.resourcePath === 'C:\Users\Administrator\Desktop\node_loader\src\main.kt'
// this.resourceQuery === '?ok'
- 加载器的查询字符串
this.query
module: {
rules: [
{ test: /\.kt$/, use: path.resolve(DIR_SRC, 'my-kotlin-loader.js?main_function=main') }, // this.query === '?main_function=main'
]
}
- 请求字符串
this.request
this.request提供一个完整的请求URI描述:
console.log('请求', this.request);
// 请求 C:\Users\Administrator\Desktop\node_loader\src\my-kotlin-loader.js?main_function=main!C:\Users\Administrator\Desktop\node_loader\src\main.kt?ok
Github示例
https://github.com/develon2015/eg-My-Kotlin-Loader

浙公网安备 33010602011771号