【发布时间】:2020-10-17 20:45:08
【问题描述】:
我正在尝试使用 Typescript 为 React 创建一个模板。
为了在生产环境中使用它,我想将它与 webpack 捆绑在一起。
就我的研究而言,我应该正确配置所有内容。
如下
webpack.config.ts
const path = require('path');
module.exports = {
mode: "development",
entry: {
app: path.join(__dirname, 'src', 'index.tsx')
},
target: 'web',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
include: [
path.resolve(__dirname, 'ts')
],
},
{
enforce: "pre",
test: "/\.js$/",
loader: "source-map-loader"
}
]
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
},
output: {
filename: 'index.js',
path: path.resolve(__filename, 'js')
},
devtool: 'source-map',
};
tsconfig.json
{
"compilerOptions": {
"target": "ES6",
"module": "CommonJS",
"outDir": "./js/",
"preserveConstEnums": true,
"moduleResolution": "Node",
"sourceMap": true,
"removeComments": true,
"jsx": "react"
},
"include": [
"./ts/**/*"
]
}
package.json
{
"name": "reacttest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --config webpack.config.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^14.0.14",
"@types/react": "^16.9.41",
"@types/react-dom": "^16.9.8",
"html-webpack-plugin": "^4.3.0",
"source-map-loader": "^1.0.0",
"ts-loader": "^7.0.5",
"typescript": "^3.9.5",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
},
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
}
但每次我跑
webpack
或
webpack --config webpack.config.ts
或
webpack webpack.config.ts
我收到以下错误消息
错误:EEXIST:文件已存在,mkdir '\Some\Path\WebWorkspace\reacttest\webpack.config.ts'
我做错了什么?
都试过了
NodeJs 13.7
和
NodeJs v12.18.1
提前致谢
【问题讨论】:
标签: node.js reactjs typescript webpack