Webpack och TypeScript - ingen transpilation och saknad kod


Jag har en ganska enkel Webpack/TypeScript-konfiguration men av någon anledning finns det ingen transpilation ner till ES5 i utdata-bundle och moduler ingår inte i bundlen.

Jag har ett annat projekt med exakt samma upplägg som fungerar korrekt.

tsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false
    },
    "exclude": [ "node_modules" ]
}

webpack.config.js:

module.exports = {
    entry: './lib/main.ts',
    output: {
        filename: './assets/js/bundle.js'
    },
    resolve: {
        extensions: ['', '.ts']
    },
    modules: {
        loaders: [
            { test: /.ts$/, loader: 'awesome-typescript-loader' }
        ]
    }
}

main.ts:

import { thing } from './thing';
console.log(thing.foo);

thing.ts:

export const thing = {
    foo: 'bar'
}

bundle.js:

/******/ (function(modules) { // webpackBootstrap
/******/    // The module cache
/******/    var installedModules = {};

/******/    // The require function
/******/    function __webpack_require__(moduleId) {

/******/        // Check if module is in cache
/******/        if(installedModules[moduleId])
/******/            return installedModules[moduleId].exports;

/******/        // Create a new module (and put it into the cache)
/******/        var module = installedModules[moduleId] = {
/******/            exports: {},
/******/            id: moduleId,
/******/            loaded: false
/******/        };

/******/        // Execute the module function
/******/        modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/        // Flag the module as loaded
/******/        module.loaded = true;

/******/        // Return the exports of the module
/******/        return module.exports;
/******/    }


/******/    // expose the modules object (__webpack_modules__)
/******/    __webpack_require__.m = modules;

/******/    // expose the module cache
/******/    __webpack_require__.c = installedModules;

/******/    // __webpack_public_path__
/******/    __webpack_require__.p = "";

/******/    // Load entry module and return exports
/******/    return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {

    import { thing } from './thing';
    console.log(thing.foo);

/***/ }
/******/ ]);

Svar #1

Min webpack.config.js hade en modules-egenskap istället för en module-egenskap.