-
-
Notifications
You must be signed in to change notification settings - Fork 433
Closed
Labels
Description
I am writing a npm package which will running in node environment. and i find a problem.
if my ts code like:
class TestModule {}
export default TestModule;this code will transifier to:
// transifier-index.js
// some code...
export.default = TestModule;And then if i want to use this package like this:
const testModule = require('transifier-index.js');
console.log(testModule); // { default: [Function: TestModule] }
const obj = new testModule() // error: testModule is not a constructorbut if i write .ts file like this:
class TestModule {}
export = TestModule;then i will get the current module.export:
// transifier-index.js
// some code...
module.export = TestModule;Question: what't different between export = xxx and export default xxx? How can i transfer export default xxx to module.export =xxx?
some version info:
node: 7.7.1
webpack: 2.6.1
ts-loader: last version
tsc: 2.4.1
some config:
// tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es2015", "es2017", "dom"],
"declaration": true,
"declarationDir": "./wechat-pay-sdk",
"strict": true,
"noImplicitAny": false,
"moduleResolution": "node",
"experimentalDecorators": true
},
"include": [
"./src"
],
"exclude": [
"node_modules"
]
}// webpack.config.js
const webpack = require('webpack');
const path = require('path');
const config = {
entry: path.join(__dirname, './src/index.ts'),
output: {
filename: 'index.js',
path: path.join(__dirname, './lib'),
libraryTarget: 'umd',
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
externals: {
md5: 'md5',
url: 'url',
request: 'request',
xml2json: 'xml2json',
js2xmlparser: 'js2xmlparser',
},
module: {
loaders: [{
test: /\.ts/,
loaders: 'ts-loader',
exclude: /node_modules/
}]
},
target: 'node'
}
module.exports = config;