Git Product home page Git Product logo

cfile's Introduction

模板使用

  1. 代码片段使用
    • 模板统一存放于 template 文件夹,文件命名方式为 项目名_目录1_目录2_标识(标识可自定义用于区分)
    • 模板使用 handlebars 语法,参考文档handlebarsjs

QA

package.json 配置 type=module, ts-node 执行.ts后缀文件异常,不支持.ts后缀文件

  • 使用 ts-node-esm 执行
  • stackoverflow

使用 TS + ESM 模块注意事项

  • package.json 默认 CommonJS, 设置 "type": "module" 标识 Node 以 ESM 规范(import、export)来运行当前项目,项目加载依赖使用 import foo from 'foo' 而不是 const foo = require('foo') 来导入包
  • 使用 ts-node 运行代码、ESM 规范需要用 ts-node-esm 运行
  • 将 package.json 中的 "engines" 字段更新为 Node.js 18: "node": ">=18"。
  • 仅使用完整的相对文件路径进行导入:import x from '.'import x from './index.js'
  • typescript 中的 config.json 配置
    • 若使用旧的 CommonJS 规范,则 “module”=“CommonJS” 生成代码的模块类型,“moduleResolution”=“Node” 包模块寻找方式
    • 使用 ESM 规范 “module”=“Node16”、“moduleResolution”=“Node16”,或者更新的 NodeNext
  • 使用 tsx 编译时
    • 使用新的ESM解析规范、import 引入需要带上文件后缀,使用 .ts 后缀,编译不会转换为 .js,可直接使用 .js 后缀。
  • 使用 CommonJS 规范时、依赖的第三方包需要使用 CommonJS 规范的版本
  • 详细参考

cfile's People

Contributors

daiyu-ola avatar

Watchers

daiyu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.