Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
multi-tsconfig-paths-webpack-plugin
Advanced tools
Use `paths` in tsconfig.json at each directories to let Webpack resolves files as expected.
Use paths
in tsconfig.json at each directory to let Webpack resolve files as expected. It's like a plugin for aliases, but it's more powerful in the monorepo scenario.
Install the plugin using the package manager.
npm i -D multi-tsconfig-paths-webpack-plugin
yarn add -D multi-tsconfig-paths-webpack-plugin
pnpm i -D multi-tsconfig-paths-webpack-plugin
Add the plugin to your Webpack configuration.
const { MultiTsconfigPathsWebpackPlugin } = require('multi-tsconfig-paths-webpack-plugin');
module.exports = {
resolve: {
plugins: [
new MultiTsconfigPathsWebpackPlugin({
glob: '../../**/tsconfig.json', // depends on your project structure
}),
],
},
};
In the monorepo scenario, you may have multiple tsconfig.json
files in different directories. Each tsconfig.json
file may have its own paths
configuration. This plugin will help you resolve the files as expected.
For example, here is the project structure:
project
├── packages
│ ├── sub
│ │ ├── src
│ │ │ ├── bar.ts
│ │ │ └── index.ts
│ │ └── tsconfig.json
│ └── main
│ ├── src
│ │ ├── foo.ts
│ │ └── index.ts
│ ├── webpack.config.js
│ └── tsconfig.json
└── tsconfig.json
All tsconfig.json
s have the same baseUrl
and paths
configuration:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
TypeScript respects the tsconfig.json
in all directories. It will resolve the files as expected:
/packages/main/src/index.ts
, if you write import ... from '@/foo'
, TypeScript resolves the file to /packages/main/src/foo.ts
./packages/sub/src/index.ts
, if you write import ... from '@/bar'
, TypeScript resolves the file to /packages/sub/src/bar.ts
.But Webpack aliases are globally set. If you set @
to /packages/main/src
, it will resolve all @
s to /packages/main/src
. The @/bar
will be resolved to /packages/main/src/bar.ts
, not /packages/sub/src/bar.ts
. That means even if you can Ctrl/Cmd + Click
to jump to the file in your IDE, there are still errors in Webpack.
This plugin will help you resolve the files as expected. If you don't use monorepo, you can still use this plugin as a replacement for setting config.resolve.alias
in Webpack config using tsconfig.json
manually.
Don't worry, if your import path is not in the paths
configuration, it will not be resolved by this plugin.
pnpm i
pnpm start # go to http://localhost:3000 and see the console
MIT
FAQs
Use `paths` in tsconfig.json at each directories to let Webpack resolves files as expected.
The npm package multi-tsconfig-paths-webpack-plugin receives a total of 0 weekly downloads. As such, multi-tsconfig-paths-webpack-plugin popularity was classified as not popular.
We found that multi-tsconfig-paths-webpack-plugin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.