1.0.9 • Published 4 years ago

gatsby-plugin-atl v1.0.9

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Awesome Typescript Loader plugin for Gatsby

Warning! awesome-typescript-loader is no longer supported, so this project is being abandoned as well.

Description

This plugin will integrate awesome-typescript-loader into the webpack config to enable typescript support in Gatsby. After ts files are compiled, they are then fed into the standard gatsby loaders.js() (babel-loader, etc...), to maintain compatibility.


How to install

  1. Include the plugin in your gatsby-config.js.
// gatsby-config.js
module.exports = {
  plugins: [
    ...,
    `gatsby-plugin-atl`
  ]
}
  1. Configure using any of awesome-typescript-loader's options

Available Options

  • ignoreAliases: This will disable the alias transformer used in the plugin
  • Any of the options used by awesome-typescript-loader can be used here.
    • There is no guarantee that all of these options will work with Gatsby.
    • For list of options that are available for this plugin, see the awesome-typescript-loader documentation at the following:

https://github.com/s-panferov/awesome-typescript-loader/#loader-options


Alias Transformation

By default, this plugin uses the npm package ts-transform-paths function, so that you can use aliases from your tsconfig.json.

https://github.com/OniVe/ts-transform-paths

If you want to exclude this functionality, then include the ignoreAliases boolean value in the plugin configuration in gatsby-config.js, like so:

// gatsby-config.js
module.exports = {
  ...
  plugins: [
    {
      resolve: 'gatsby-plugin-atl',
      options: {
        ignoreAliases: true
      }
    }
  ]
}

This is enabled by default to take some of the guesswork out getting your aliases working. The process actually replaces the aliases with the paths relative to the source file being processed, so there is no need to include aliases in your webpack config. This eliminates much of the maintenance.


Required Compiler Options

By default some compilerOptions options will be set for you, as a minimum configuration. Without these options set, there will usually be issues with the output that is fed to babel-loader, and the build will fail.

If these are not configured, then compilation tends to fail. These options are:

  • target: 'esnext'
  • module: 'esnext'
  • noEmit: true
  • moduleResolution: 'node'
  • lib: 'dom'
  • jsx: 'react'

Additional extensibility

If you want to take full control of the compilation process, you can use a custom compiler.

I usually prefer to use ttypescript (https://github.com/cevek/ttypescript), because it gives you access to some cool transformer features. To use ttypescript, first install it in your project

npm i -D ttypescript

Then set the configuration options in gatsby-config.js

// gatsby-config.js
module.exports = {
  ...
  plugins: [
    {
      resolve: 'gatsby-plugin-atl',
      options: {
        compiler: 'ttypescript'
      }
    }
  ]
}

ttypescript will use your tsconfig.json by default, which is another cool feature.

Just make sure you use these options in your tsconfig.json

{
  "module": "esnext",
  "target": "esnext",
  "noEmit": true,
  "moduleResolution": "node",
  "lib": ["dom"],
  "jsx": "react"
}
1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago