使用ts-loader进行Webpack构建,提供有关打字的警告

时间:2016-05-06 00:18:21

标签: typescript angular webpack ts-loader

我有以下开发设置:

  • Angular2(使用Typescript)
  • Webpack for packaging
  • Karma作为Jasmine测试的试运行者
  • Gulp调用Karma

Karma配置如下:

var webpackConfig = require('./webpack.config');
webpackConfig.entry = {};

module.exports = function(config) {
config.set({
    basePath: '',

    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],

    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['PhantomJS'],

    reporters: [],
    coverageReporter: {},
    port: 9876,
    action: 'run',
    colors: true,
    logLevel: config.LOG_INFO, // LOG_DEBUG | LOG_INFO | LOG_WARN | LOG_ERROR
    autoWatch: false,
    autoWatchBatchDelay: 300,
    singleRun: true,

    files: [ { pattern: './spec-bundle.js', watched: false } ],
    exclude: [],
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
        './spec-bundle.js': ['webpack']
    },

    webpack: webpackConfig,

    // https://webpack.github.io/docs/webpack-dev-middleware.html
    webpackMiddleware: {
        noInfo: true,
        stats: 'errors-only'
    },

    plugins: [
        'karma-coverage',
        'karma-jasmine',
        'karma-phantomjs-launcher',
        'karma-teamcity-reporter',
        'karma-webpack'
    ]
});
}

Webpack配置如下:

var webpack = require('webpack');

module.exports = {
entry: {
    main: './src/run.ts'
},
target: 'web', // 'web' | 'node'
output: {
    filename: '[name].js',
    pathinfo: true
},
devtool: 'source-map',
resolve: {
    extensions: ['', '.ts', '.js']
},
resolveLoader: {
    modulesDirectories: ['node_modules']
},
module: {
    loaders: [
        { test: /\.ts$/, loader: 'ts-loader' },
        // fastclick contains AMD and CJS loader logic - disable AMD so CJS is used
        { test: require.resolve('fastclick'), loader: 'imports?define=>false' }
    ],
    postLoaders: [
        { test: /\.ts$/, exclude: /(node_modules|spec)\//, loader: 'istanbul-instrumenter' }
    ]
},
stats: {
    colors: true,
    errorDetails: true,
    modules: false,
    reasons: true   // add information about the reasons why modules are included
}
};

ts配置如下:

"compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "moduleResolution": "node",
    "noEmitHelpers": true,
    "module": "commonjs",
    "outDir": "../dist/app",
    "sourceMap": true
},
"buildOnSave": false,
"compileOnSave": false
}    

(/ node_modules与/ src处于同一级别,tsconfig.json位于/ src文件夹中)。

所以,我有一个/ src / typings文件夹,其中包含各种* .d.ts文件,用于lodash,fastclick等。当我调用Karma时,我会为每个定义收到以下消息:

WARNING in ./src/typings/lodash/lodash.d.ts
Module build failed: Error: Typescript emitted no output for /Users/jbrighton/src/teammember-client/src/typings/lodash/lodash.d.ts
at Object.loader (/Users/jbrighton/src/teammember-client/node_modules/ts-loader/index.js:456:15)
 @ ./src \.ts

Jasmine测试成功运行(并且非测试版本运行正常)但是导致这些消息的原因是什么以及如何防止它们?

0 个答案:

没有答案