reactjs - Webpack 设置 React + TypeScript 构建文件夹未出现
问题描述
嘿,所以我不知道我做错了什么,所以我尝试使用 webpack 和 babel 设置一个 React TypeScript 项目,以便成功转换源代码,但我没有看到输出目录文件。
我能否就我的配置中可能出错的地方获得一些帮助:
webpack.config.js
const HtmlPlugin = require("html-webpack-plugin");
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpack = require("webpack");
module.exports = {
output: {
path: path.resolve(__dirname, "public/build"),
filename: "bundle.js",
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
},
],
},
{
test: /\.html$/,
use: [
{
loader: "html-loader",
},
],
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: "file-loader",
},
],
},
{
test: /\.s[ac]ss$/i,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
},
],
},
plugins: [
new HtmlPlugin({
filename: "index.html",
template: "./public/index.html",
}),
new MiniCssExtractPlugin(),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}),
],
devServer: {
historyApiFallback: true,
port: 3000,
},
};
tsconfig
{
"compilerOptions": {
"target": "es5",
"sourceMap": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": false,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"jsx": "react",
"removeComments": true
}
}
package.json 脚本
{
"name": "vid",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "cross-env NODE_ENV=beta webpack-dev-server",
"build-prod": "cross-env NODE_ENV=production webpack",
"build-beta": "cross-env NODE_ENV=beta webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@types/react": "^16.9.49",
"@types/react-dom": "^16.9.8",
"babel-loader": "^8.1.0",
"cross-env": "^7.0.2",
"css-loader": "^4.3.0",
"file-loader": "^6.1.0",
"html-loader": "^1.3.0",
"html-webpack-plugin": "^4.4.1",
"mini-css-extract-plugin": "^0.11.1",
"node-sass": "^4.14.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"sass-loader": "^10.0.2",
"typescript": "^4.0.2",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
}
}
这是我的 .babelrc 文件
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
]
}
解决方案
推荐阅读
- swagger - 如何修复操作必须在 Swagger 编辑器中具有唯一标识符语义错误
- node.js - 是否需要 GET 请求 API,因为 POST 在各方面都更好?
- r - plm:::vcovDC.plm 中的自由度是如何计算的?
- python - 在图python上找到最短路径
- c# - ParseLambda 方法抛出异常
- node.js - NestJS > TypeORM 将复杂实体映射到复杂 DTO
- java-8 - jdk 11 中缺少外部 jar 文件
- python - 在 CentOS 6 中使用 Python 2.6.6 和 scapy 2.3.3 的问题
- thingsboard - 如何使用 thingsboard.io 中的任何接口(其他 tahn smtp)向应用程序发布警报通知
- ruby-on-rails - 调用内部存根方法的 RSpec