美文网首页
开发速记-typescript篇: ember.js集成

开发速记-typescript篇: ember.js集成

作者: larluo_罗浩 | 来源:发表于2020-02-24 22:55 被阅读0次

    安装nix并配置channel:

    sudo install -d -m755 -o $(id -u) -g $(id -g) /nix
    curl https://nixos.org/nix/install | sh
    
    nix-channel --add https://nixos.org/channels/nixos-20.03 nixos-20.03
    nix-channel --update nixos-20.03
    

    安装yarn

    nix-env -f ~/.nix-defexpr/channels/nixos-20.03 -iA yarn
    

    安装ember

    yarn global add ember-cli
    

    创建ember项目

    ember new ember-larluo
    cd ember-larluo
    

    添加typescript支持

    yarn add typescript -D 
    yarn add @types/ember-resolver
    ember install ember-cli-typescript@latest
    

    修改配置

    • 添加 APP {}选项
    • 修改'../app'至 'ember-larluo/app';
    larrys-MacBook-Pro:ember-larluo larluo$ cp app/config/environment.d.ts config/environment.d.ts
    larrys-MacBook-Pro:ember-larluo larluo$ cat config/environment.d.ts
    export default config;
    
    /**
     * Type declarations for
     *    import config from './config/environment'
     *
     * For now these need to be managed by the developer
     * since different ember addons can materialize new entries.
     */
    declare const config: {
      environment: any;
      modulePrefix: string;
      podModulePrefix: string;
      locationType: string;
      rootURL: string;
      APP: {} ;
    };
    
    larrys-MacBook-Pro:ember-larluo larluo$ cat tests/test-helper.ts
    import Application from 'ember-larluo/app';
    import config from '../config/environment';
    import { setApplication } from '@ember/test-helpers';
    import { start } from 'ember-qunit';
    
    setApplication(Application.create(config.APP));
    
    start();
    

    切换到ts文件

    mv app/app.js app/app.ts
    mv app/router.js app/router.ts 
    mv ./tests/test-helper.js ./tests/test-helper.ts
    

    相关文章

      网友评论

          本文标题:开发速记-typescript篇: ember.js集成

          本文链接:https://www.haomeiwen.com/subject/ortgqhtx.html