我正在尝试使用 构建一个小node.js + ts项目webpack。
tsconfig.json
{
"compilerOptions": {
"lib": ["ESNext"],
"target": "ES2020",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"types": ["node"],
"allowSyntheticDefaultImports": true,
"rootDir": "./"
},
}
Run Code Online (Sandbox Code Playgroud)
我将其添加到package.json行中"type": "module"
webpack.config.ts
import * as path from 'path';
import * as webpack from 'webpack';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const PATHS = {
entry: path.resolve(__dirname, 'src/server/index.ts'),
output: path.resolve(__dirname, 'dist'),
};
const config: webpack.Configuration = {
target: 'node',
entry: PATHS.entry,
output: { …Run Code Online (Sandbox Code Playgroud)