Giter Site home page Giter Site logo

christoffer-dropbox / tsconfig-paths-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dividab/tsconfig-paths-webpack-plugin

0.0 1.0 0.0 217 KB

Load modules according to tsconfig paths in webpack.

License: MIT License

TypeScript 86.95% JavaScript 13.05%

tsconfig-paths-webpack-plugin's Introduction

tsconfig-paths-webpack-plugin

npm version code style: prettier MIT license

Use this to load modules whose location is specified in the paths section of tsconfig.json when using webpack. This package provides the functionality of the tsconfig-paths package but as a webpack plug-in.

How to install

NOTE: If you are using webpack 4 you need to use version >= 3.0.0 (which is aso backwards compatible with webpack 3).

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

or

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

How to use

In your webpack config add this:

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

module.exports = {
  ...
  resolve: {
    plugins: [new TsconfigPathsPlugin({ /*configFile: "./path/to/tsconfig.json" */ })]
  }
  ...
}

Notice that the plugin is placed in the resolve.plugins section of the configuration. tsconfig-paths-webpack-plugin is a resolve plugin and should only be placed in this part of the configuration. Don't confuse this with the plugins array at the root of the webpack configuration object.

Typescript support

This package has typescript typings included. If your webpack config is using typescript, you can use this syntax to import the default export:

import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";

Or you can use this syntax to import the named export:

import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";

Options

configFile (string) (default='tsconfig.json')

Allows you to specify where to find the TypeScript configuration file.

You may provide

  • just a file name. The plugin will search for the filename using the built-in logic in the tsconfig-paths package. The search will start at cwd.
  • a relative path to the configuration file. It will be resolved relative to cwd.
  • an absolute path to the configuration file.

The use of cwd as default above is not optimal but we've found no better solution yet. If you have a suggestion please file an issue.

extensions (string[]) (default=[".ts", ".tsx"])

An array of the extensions that will be tried during resolve. Ideally this would be the same as the extensions form the webpack config but it seems resolver plug-ins does not have access to this infomration so you need to specify it again for the plugin.

baseUrl (string) (default=undefined)

This allows you to override the baseUrl found in tsconfig.json. The baseUrl specifies from which directory paths should be resolved. So this option enabled you to resolve from anhother directory than the one where tsconfig.json is located. This can be useful if you want to use webpack with tsc --watch instead of a typescript loader. If this option is undefined then the baseUrl from tsconfig.json will be used.

silent (boolean) (default=false)

If true, no console.log messages will be emitted. Note that most error messages are emitted via webpack which is not affected by this flag.

logLevel (string) (default=warn)

Can be info, warn or error which limits the log output to the specified log level. Beware of the fact that errors are written to stderr and everything else is written to stderr (or stdout if logInfoToStdOut is true).

colors (boolean) (default=true)

If false, disables built-in colors in logger messages.

logInfoToStdOut (boolean) (default=false)

This is important if you read from stdout or stderr and for proper error handling. The default value ensures that you can read from stdout e.g. via pipes or you use webpack -j to generate json output.

How to test

To run the provided example:

yarn example

Prior work

This project uses work done in the awesome-typescript-loader.


tsconfig-paths-webpack-plugin's People

Contributors

darlanalves avatar jbboehr avatar jonaskello avatar nayni 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.