【问题标题】:npm - Compile typescript files in npm build scriptnpm - 在 npm 构建脚本中编译 typescript 文件
【发布时间】:2016-07-18 08:36:53
【问题描述】:

我正在尝试仅使用 npm 创建构建脚本,而无需 grunt 或 gulp。

除了连接打字稿之外,大多数事情都在工作。

我可以编译单个 typescript 文件,但我有许多单独的文件需要连接然后编译。

我正在使用 concat-cli mobule,但它似乎没有连接文件,只是输出文件夹中的第一个文件。

连接打字稿文件的最佳方法是什么。

    {
      "name": "starter",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",

      "scripts": {
        "scss": "node-sass --output-style compressed -o src/assets/css src/assets/sass/main.scss",
        "compile:ts": "tsc --outDir ./src/assets/js/ --module commonjs ./src/app/**/*.ts",
        "concat:ts": "concat-cli --files src/app/**/*.ts --output dist/js/output.ts",
        "serve": "browser-sync start --server --files 'src/assets/css/, src/assets/js/*.js, **/*.html, !node_modules/**/*.html'",
        "watch:css": "onchange 'src/assets/sass/*.scss' -- npm run scss",
        "watch:js": "onchange 'src/app/**/*.js' -- npm run jshint",
        "watch:ts": "onchange 'src/app/**/*.ts' -- npm run concat:ts",
        "watch:all": "npm-run-all -p serve watch:css watch:js watch:images",
      },
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "browser-sync": "^2.13.0",
        "concat": "0.0.1-security",
        "concat-cli": "^4.0.0",
        "node-sass": "^3.8.0",
        "onchange": "^2.5.0",
        "typescript": "^1.8.10",
      }
    }

【问题讨论】:

    标签: typescript npm


    【解决方案1】:

    连接打字稿文件的最佳方法是什么。

    使用模块并使用像 webpack 这样的模块加载器。快速入门:https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html

    为什么

    在不使用模块系统的情况下盲目连接 JS 文件将充斥ReferenceError: Variable not definedTypeError : undefined is ....。还有其他可维护性的原因。更多:https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html

    【讨论】:

    • 我可以在 webpack.config.js 中使用 glob。我有一个 app 文件夹,其中包含我的 angularjs 代码的控制器、指令、服务和过滤器文件夹。所以我有不同的打字稿文件,如果我使用entry: './src/app/**/*.ts',,我需要编译我得到一个错误
    猜你喜欢
    • 2021-12-15
    • 2017-06-30
    • 2021-03-03
    • 2012-01-25
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 2018-09-03
    相关资源
    最近更新 更多