2015-06-19 4 views
5

Sto utilizzando Webpack sia per l'app che per i test (utilizzando https://github.com/webpack/karma-webpack per esso). L'app è in dattiloscritto e i test in Babel.Webpack Karma non è in grado di risolvere l'importazione locale

Importare qualcosa da un modulo autonomo nei test funziona (utilizzando import { cleanHTML, fromHTML, toHTML } from "../../app/utils/text.ts";, cioè ho bisogno di menzionare l'estensione .ts altrimenti fallisce).

Quando provo effettivamente a importare un componente React che importa un componente in un altro file, viene visualizzato il seguente errore: Module not found: Error: Cannot resolve 'file' or 'directory' ./blocks/paragraph.

L'albero della directory assomiglia a:

src/ 
    app/ 
    components/ 
     blocks/ 
     paragraph.ts 
    main.ts 
    tests/ 
    components/ 
     main_tests.js 
    utils/ 

e le importazioni main.ts paragraph.ts in questo modo import { ParagraphBlockComponent } from "./blocks/paragraph";

opere di compilazione normale ma non le prove. Qui è la configurazione del karma:

var path = require('path'); 

module.exports = function (config) { 

config.set({ 
    basePath: 'src', 
    singleRun: true, 
    frameworks: ['mocha', 'chai'], 
    reporters: ['dots'], 
    browsers: ['Firefox'], 
    files: [ 
     'tests/index.js' 
    ], 
    preprocessors: { 
     'tests/index.js': ['webpack'] 
    }, 
    webpack: { 
     noInfo: true, 
     module: { 
      loaders: [ 
       { 
        test: /\.ts$/, 
        loaders: ['awesome-typescript-loader'] 
       }, 
       { 
        test: /\_tests.js$/, 
        loaders: ['babel-loader'] 
       } 
      ] 
     } 
    }, 
    webpackMiddleware: { 
     noInfo: true, 
     stats: { 
      color: true, 
      chunkModules: false, 
      modules: false 
     } 
    } 
}); 

}; 

Mi sono perso qualcosa?

risposta

7

L'aggiunta dei seguenti alla configurazione karma webpack fissata per me

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