38

TS Tranform to Inline JSON

 5 years ago
source link: https://www.tuicool.com/articles/hit/VVZvyyN
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ts-transform-json

Inline specific values from a JSON file or the whole JSON blob. For example:

import {version} from 'package.json'
// becomes
var version = '1.0.5'

// OR
import * as packageJson from 'package.json'
// becomes
var packageJson = {"version": "1.0.5", dependencies: {}}

Usage

First of all, you need some level of familiarity with the TypeScript Compiler API .

compile.ts & tests should have examples of how this works. The available options are:

isDeclaration?: boolean

Whether you're running this transformer in declaration files (typically specified in afterDeclarations instead of after in transformer list). This flag will inline types instead of actual value.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK