🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

gatsby-plugin-typescript

Package Overview
Dependencies
Maintainers
1
Versions
602
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-plugin-typescript - npm Package Compare versions

Comparing version

to
1.0.0-alpha13

48

gatsby-node.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _stringify = require("babel-runtime/core-js/json/stringify");

@@ -15,10 +11,7 @@

exports.resolvableExtensions = resolvableExtensions;
exports.modifyWebpackConfig = modifyWebpackConfig;
exports.preprocessSource = preprocessSource;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _typescript = require("typescript");
var _require = require("typescript"),
transpileModule = _require.transpileModule;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var test = /\.tsx?$/;

@@ -31,12 +24,12 @@ var compilerDefaults = {

function resolvableExtensions(ctx) {
module.exports.resolvableExtensions = function () {
return [".ts", ".tsx"];
}
};
function modifyWebpackConfig(ctx) {
var config = ctx.args.config,
compilerOptions = ctx.pluginOptions.compilerOptions;
module.exports.modifyWebpackConfig = function (_ref, _ref2) {
var config = _ref.config;
var compilerOptions = _ref2.compilerOptions;
// CommonJS to keep Webpack happy.
var copts = (0, _assign2.default)(compilerDefaults, compilerOptions, {
var copts = (0, _assign2.default)({}, compilerDefaults, compilerOptions, {
module: "commonjs"

@@ -47,4 +40,2 @@ });

var opts = { compilerOptions: copts, transpileOnly: true };
// Load TypeScript files with ts-loader. This'll need to be installed (along with TypeScript)
// in the project directory.
config.loader("typescript", {

@@ -54,12 +45,11 @@ test,

});
}
};
function preprocessSource(ctx) {
var _ctx$args = ctx.args,
contents = _ctx$args.contents,
filename = _ctx$args.filename,
compilerOptions = ctx.pluginOptions.compilerOptions;
module.exports.preprocessSource = function (_ref3, _ref4) {
var contents = _ref3.contents,
filename = _ref3.filename;
var compilerOptions = _ref4.compilerOptions;
// overwrite defaults with custom compiler options
var copts = (0, _assign2.default)(compilerDefaults, compilerOptions, {
var copts = (0, _assign2.default)({}, compilerDefaults, compilerOptions, {
target: "esnext",

@@ -69,3 +59,3 @@ module: "es6"

// return the transpiled source if it's TypeScript, otherwise null
return test.test(filename) ? (0, _typescript.transpileModule)(contents, { compilerOptions: copts }).outputText : null;
}
return test.test(filename) ? transpileModule(contents, { compilerOptions: copts }).outputText : null;
};
{
"name": "gatsby-plugin-typescript",
"version": "1.0.0-alpha12-alpha.e1f27e45",
"version": "1.0.0-alpha13",
"description": "Adds TypeScript support for Gatsby layouts and pages.",

@@ -10,2 +10,3 @@ "author": "Kyle Mathews <mathews.kyle@gmail.com>",

"dependencies": {
"ts-loader": "^2.0.3",
"typescript": "^2.2.1"

@@ -12,0 +13,0 @@ },

@@ -5,27 +5,33 @@ # gatsby-plugin-typescript

## Install
`yarn add gatsby-plugin-typescript`
`yarn add gatsby-plugin-typescript typescript`
## How to use
1. Include the plugin in your `gatsby-config.js` file.
2. Write your components in TSX or TypeScript.
3. You're good to go.
1. Add `tsconfig.json` file on your root directory.
1. Write your components in TSX or TypeScript.
1. You're good to go.
`gatsby-config.js`
```javascript
// in gatsby-config.js
plugins: [
// no configuration
`gatsby-plugin-typescript`,
// custom configuration
{
resolve: `gatsby-plugin-typescript`,
options: {
// compilerOptions are passed directly to the compiler
compilerOptions: {
target: `esnext`,
experimentalDecorators: true,
jsx: `react`
}
}
}
]
```
`tsconfig.json`
```json
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "esnext",
"jsx": "react",
"lib": ["dom", "es2015", "es2017"]
},
"include": [
"./src/**/*"
]
}
```