简体   繁体   English

typescript 未创建 dist 文件夹

[英]typescript not creating dist folder

trying to compose typescript project.试图组成 typescript 项目。 here is my project structure.这是我的项目结构。

rootdir
    |
    |-----src
    |      |----server.ts
    |      |----other folders
    |-----node_modules
    |-----tsconfig.json
    |-----package.json

tsconfig.json tsconfig.json

{
  "compilerOptions": {
    "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
    "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
    "resolveJsonModule": true,

    "outDir": "./dist" /* Redirect output structure to the directory. */,
    "rootDir": "./src" /* Specify the root directory of input files. Use to 

    /* Strict Type-Checking Options */
    "strict": true /* Enable all strict type-checking options. */,
    "noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,

    "esModuleInterop": true /* Enables emit interoperability between CommonJS 

    /* Advanced Options */
    "skipLibCheck": true /* Skip type checking of declaration files. */,
    "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
  },
  "include": ["./package.json"]
}

/dist folder is not getting created for me when I do npm run build. /dist 文件夹在我执行 npm 运行构建时没有为我创建。

 "build": "tsc --build tsconfig.json",

First: Your build command should be tsc --project tsconfig.json .第一:您的构建命令应该是tsc --project tsconfig.json The command you're currently using is trying to build your tsconfig.json file, instead of the actuall source code.您当前使用的命令正在尝试构建您的tsconfig.json文件,而不是实际的源代码。

Second: Your tsconfig isn't actually including any of your source code in the build.第二:您的 tsconfig 实际上并未在构建中包含您的任何源代码。 Change your include array to "incude": ["./src/**/*.ts"] .将您的include数组更改为"incude": ["./src/**/*.ts"] Your current include array is telling tsc to build your package.json file, instead of the actuall source code.您当前的包含数组告诉 tsc 构建您的package.json文件,而不是实际的源代码。

Try this one.试试这个。 I hope it will cover our case.我希望它能涵盖我们的案例。

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "resolveJsonModule": true,
    "outDir": "dist",
    "strict": true,
    "noImplicitAny": false,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM