简体   繁体   English

Webpack,打字稿和导入解析

[英]Webpack,typescript and import resolve

I have a little problem with typescript import statement and webpack support. 我对Typescript导入语句和Webpack支持有一点问题。 eg if I have module A which has only import statment inside and module B which import module A.After run webpack watch, my bundle.js output file is empty in the section where javaScript code is generate. 例如,如果我有仅在其中导入语句的模块A和导入模块A的模块B。运行webpack watch后,我的bundle.js输出文件在生成JavaScript代码的部分为空。 It's suggests that webpack does not resolve import. 这表明webpack无法解决导入问题。 Here is the example: 这是示例:

         /*controllerA*/
          export class ControllerA{
            constructor(){}  
          }

         /*a.ts*/
        import {controllerA} from './controllerA'   

        /*b.ts*/
        import * as moduleA from './a'

And here is my webpack configuration 这是我的webpack配置

   module.exports = {

   entry: ['./b.ts'],
    output: {
     filename: 'bundle.js'

   },

 resolve: {
  extensions: ['', '.webpack.js', '.web.js', '.ts', '.js']
 },

   module: {
   loaders: [
     { test: /\.ts$/, loader: 'ts-loader' }
    ]
  }
 }

Any ideas how to fix it? 任何想法如何解决?

Your a.ts doesn't export anything. 您的a.ts不会导出任何内容。 You need to re-export controllerA after importing it, or just replace the import keyword in a.ts by export 导入后,您需要重新导出controllerA,或仅将export中的a.ts中import关键字替换export

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM