要求webpack包返回空对象

时间:2019-03-22 17:53:42

标签: typescript webpack

按照此处的建议添加libraryTarget:Require Webpack bundle -- returns empty object?无济于事。

webpack.config.js:

var path = require('path');
var webpack = require('webpack');

module.exports = {
    target: "node",
    entry: './src/Api.ts',
    resolve: {
        extensions: ['.ts', '.tsx', '.js']
    },
    output: {
        path: path.join(__dirname, '/dist'),
        filename: 'bundle.min.js',
        libraryExport: "umd"  // tried several here
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: 'awesome-typescript-loader'
            }
        ]
    }
}

Api.ts:

export class Api {
    test(){

    }
}

然后在另一个我有(expressjs)的项目中:

const mymodule = require('full_path/dist/bundle.min.js');
console.log(mymodule) # always empty object

我期望能够做到mymodule.test()

0 个答案:

没有答案