wly19960911
V2EX  ›  问与答

请教 angular 组件开发编译的问题

  •  
  •   wly19960911 · Jun 11, 2018 · 1479 views
    This topic created in 2949 days ago, the information mentioned may be changed or developed.

    最近需要处理组件开发编译发布,但是在开发过程中碰到一些问题。

    因为新的 angular 不像 angular2,不允许随处 import ts 文件了,所以这里就需要编译成 js 文件。

    但是我发现在 .component.ts 中定义 @Component 的时候,发现一些导入问题。

    @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css'],
        providers: [
            MenuService,
            Description
        ]
    })
    

    其中 templateUrlstyleUrls 不能使用,否则就会出现编译之后成为 require 的方式请求,最后变成请求地址 localhost:4200/app.component.html

    有关这个问题我查看了一些 UI 框架的处理,基本都是 app.component.html 采用内联的写法,直接字符串写入 @Component 里面,然后 css 都是统一处理并且从 .angular-cli.json 导入的。

    我想问问还有什么办法处理这个问题吗?

    参考地址:how-to-build-and-publish-an-angular-module

    Supplement 1  ·  Jun 11, 2018
    前面没有描述好,不能随便 import 非 src 里面的 ts 文件, 除非进行一些 tsconfig.json 的一些配置,这样的话,开发组件的话,必然需要编译成 js 上传到 npm 仓库才能正常被 import ( node_modules 里面的文件)。

    这个问题就是在编译成 js 的时候发生的。
    2 replies    2018-06-11 15:30:03 +08:00
    gen900
        1
    gen900  
       Jun 11, 2018
    只有我没看懂遇到什么问题了吗?“新的 angular 不像 angular2,不允许随处 import ts 文件了” 什么意思?新的 angular 是什么?不允许随处 import,何出此言?
    wly19960911
        2
    wly19960911  
    OP
       Jun 11, 2018
    @gen900 #1 抱歉我没有描述好,从 angular4 开始 不能随便 import 非 src 里面的 ts 文件, 除非进行一些 tsconfig.json 的一些配置,这样的话,开发组件的话,必然需要编译成 js 上传到 npm 仓库才能正常被 import ( node_modules 里面的文件)。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3221 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 11:20 · PVG 19:20 · LAX 04:20 · JFK 07:20
    ♥ Do have faith in what you're doing.