使用 tsconfig-paths-webpack-插件在 Webpack 中加载 tsconfig.json 路径

tsconfig-paths-webpack-插件允许在 Webpack 中加载模块,这些模块的位置在 tsconfig.json 文件的 "paths" 部分中指定。使用此插件可简化项目中的别名配置,因为插件会自动创建所需的别名条目。

安装

Webpack 4 及以上版本:

yarn add --dev tsconfig-paths-webpack-plugin

Webpack 3:

npm install --save-dev tsconfig-paths-webpack-plugin

使用

在 Webpack 配置中添加以下内容:

const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = {
  plugins: [new TsconfigPathsPlugin()]
};
zip 文件大小:107KB