按照此处的建议添加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()