小编Dag*_*gon的帖子

捆绑和使用webpack构建的typescript库的正确方法?

我最近开始使用typescript,无法理解如何构建一个使用webpack在另一个打字稿模块中使用的打字稿库.

此库也适用于在浏览器中运行.

目前我最终得到了以下结构和构建输出:

lib
??? build
?   ??? typings // tsc output with declaration:true
?   ?   ??? Bar.d.ts
?   ?   ??? Foo.d.ts
?   ??? lib.bundle.js //webpack bundle file
??? src
?   ??? Bar.ts
?   ??? Foo.ts
??? bower.json
??? package.json
??? tconfig.json
Run Code Online (Sandbox Code Playgroud)

webpack配置:

webpackOptions = {
    resolve: { extensions: ['', '.ts'] },
    module: {
      loaders: [{ test: /\.ts$/, exclude: [/node_modules/,/out/,/.*\.d\.ts/],include:[/\.ts$/], loaders: ['ts-loader']}]
    },
    ts:{
      compilerOptions:compilerOptions
    },
    output: {
      library:"mylib",
      libraryTarget:'commonjs',
      filename: 'mylib.bundle.js'
    }
  }
Run Code Online (Sandbox Code Playgroud)

tsconfig.json:

{
  "compilerOptions": { …
Run Code Online (Sandbox Code Playgroud)

typescript webpack

1
推荐指数
1
解决办法
1310
查看次数

标签 统计

typescript ×1

webpack ×1