Giter Site home page Giter Site logo

rockydd / rollup-plugin-typescript-path-mapping Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mutefish0/rollup-plugin-typescript-path-mapping

0.0 1.0 0.0 6 KB

Resolving module path which applies typescript's path mapping rule

JavaScript 100.00%

rollup-plugin-typescript-path-mapping's Introduction

rollup-plugin-typescript-path-mapping

DEPRECATED, use rollup-plugin-typescript instead.

Resolving module path which applies typescript's path mapping rule, see Path mapping in official doc

why?

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 :)

Installation

$ npm install rollup-plugin-typescript-path-mapping

Usage

// 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'
    })]
}

rollup-plugin-typescript-path-mapping's People

Contributors

mutefish0 avatar rockydd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.