Mutefish0/rollup-plugin-typescript-path-mapping(新しいタブで開きます)
主要言語: JavaScript
Resolving module path which applies typescript's path mapping rule
- star 数
- 2
- watcher 数
- 1
- fork 数
- 1
- issue 数
- 2
- 最終更新
- 2020/09/11
主要言語: JavaScript
Resolving module path which applies typescript's path mapping rule
DEPRECATED, use rollup-plugin-typescript instead.
Resolving module path which applies typescript's path mapping rule, see Path mapping in official doc
When we configure some path mapping rules in tsconfig.json, typescript compiler can resolve module paths correctly using the rule you just configured, however, typescript does not rewrite module path in emitted .js files, thus rollup could not resolve modules correctly when you try packing those emitted .js files. To solve this, you have to write another corresponding rule that rollup recognizes using some plugins.
When using this plugin, it can read the path mapping rule directly in tsconfig.json and adapte it to
rollup automatically, there is nothing else you need to do :)
$ npm install rollup-plugin-typescript-path-mapping
// rollup.config.js const rollupPluginTypescriptPathMapping = require('rollup-plugin-typescript-path-mapping') module.exports = { input: 'dist/main.js', output: { file: 'bundle.js', format: 'iife' }, plugins: [rollupPluginTypescriptPathMapping({ tsconfig: true })] }
there is some path mapping rules configured in tsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"base/*": ["src/base/*"],
"util/*": ["src/common/util/*"],
},
"outDir": "dist",
"rootDir": "src",
"module": "es2015",
"target": "es2015"
}
}then just rollup these files that typescript compiled
$ rollup -c
of course, you can manually configure rule
// rollup.config.js const rollupPluginTypescriptPathMapping = require('rollup-plugin-typescript-path-mapping') module.exports = { input: 'dist/main.js', output: { file: 'bundle.js', format: 'iife' }, plugins: [rollupPluginTypescriptPathMapping({ baseUrl: './', paths: { 'base/*': ['src/base/*'], 'util/*': ['src/common/util/*'], }, outDir: 'dist', rootDir: 'src' })] }