我有一个 create-react-app 应用程序工作 100% ,我想集成 webpack4 来部署我的应用程序,但是在配置 webpack 后,当我“npm dev run”时,我在每个惰性导入行上收到这些错误:找不到模块:错误:可以无法解析“C:...”中的“src/views/UserList”
我的 webpack.config.js :
// webpack.config.js
const path = require( 'path' );
const HtmlWebPackPlugin = require( 'html-webpack-plugin' );
const webpack=require('webpack');
module.exports = {
context: __dirname,
entry: {
bundle: './src/index.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js',
},
devServer: {
historyApiFallback: true
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
{
test: /\.((c|sa|sc)ss)$/i,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|j?g|svg|gif)?$/,
use: 'file-loader',
include: path.resolve(__dirname, 'src') …Run Code Online (Sandbox Code Playgroud)我有一个带有 build 文件夹的 React 应用程序(由: npm run build 生成),我想在 .env 文件中包含 3 个变量(只有一个文件):
REACT_APP_API_URL=http://localhost:3000/api ( for production)
REACT_APP_PROD_URL=http://localhost:3001/api ( for staging)
REACT_APP_STAGIN_URL=http://localhost:3002/api ( for development)
Run Code Online (Sandbox Code Playgroud)
并在 npm run build 文件夹中使用它们