我开始构建一个我想在NPM上发布的组件库(并在其他应用程序中重用),通过使用创建一个React应用程序create-react-app.不幸的是,create-react-app默认配置似乎不支持构建此类组件库(请参阅 这些 问题).所以我似乎要弹出.
你有一些指令在弹出后配置什么来使这个组件库我可以在其他应用程序中重用(我猜一些Webpack的东西)?
我有一个单页应用程序,我在每条路线上编码拆分.当我部署新版本的应用时,如果用户仍然打开该页面并访问之前未访问过的路由,则用户通常会收到错误.
另一种情况是,如果应用程序启用了服务工作程序,也会发生这种情况.当用户在新部署后访问页面时,服务工作者将从缓存中提供服务.然后,如果用户尝试访问不在其缓存中的页面,则他们将获得块加载失败.
目前我在我的应用程序中禁用了代码拆分以避免这种情况,但我一直很好奇处理这个问题的最佳方法是什么.我已经考虑过在用户完成加载初始页面后预加载所有其他路由,我相信这可能会解决路由上代码拆分的问题.但是,假设我想对组件进行代码拆分,那么这意味着我必须设法确定何时以及如何预加载所有这些组件.
所以我想知道人们如何处理单页应用程序的这个问题?谢谢!(我目前正在使用create-react-app)
single-page-application reactjs webpack webpack-2 create-react-app
我需要像简单地那样运行服务器:
npm run start
但是我需要使用生产模式。这可能吗?
灰烬或棱角有可能。怎么办create-react-app?
我尝试过,npm run start --prod但是什么也没有。
使用create-react-app创建React应用时可以有条件地导入资产吗?我知道require语法-例如:
import React from "react";
const path = process.env.REACT_APP_TYPE === "app_1" ? "app_1" : "app_2";
const imagePath = require(`./assets/${path}/main.png`);
export default function Test() {
return (
<img src={imagePath} alt="" />
);
}
Run Code Online (Sandbox Code Playgroud)
但是,无论如何,这都会捆绑我的所有资产。
它将加载正确的映像,但仍将所有文件捆绑在一起,形成最终版本。
当我查看最终构建的开发工具时,即使我只想为加载资产,也可以看到那里的所有资产app_1。
我是否被迫触摸webpack配置,如果是的话,我应该改变什么?还是有另一种方法?
我正在开发一个由别人构建的项目。我知道它是由 create-react-app 引导的,因为它在 README.md 中这么说。
不过,我不确定它是否已被弹出。有很多帖子教你如何实际弹出它,但我一开始就找不到检查它的方法。任何帮助表示赞赏!
我正在开发一个用 制作的反应应用程序create-react-app,每当我启动该应用程序时,我都会收到此错误:
./node_modules/scrambles/dist/esm/scrambles.js 37:39
Module parse failed: Unexpected token (37:39)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|
| async function getWorker() {
> const url = outsideStrategy.url.esm ?? outsideStrategy.url.cjs;
| const workerInstantiator = outsideStrategy.workerInstantiator.esm ?? outsideStrategy.workerInstantiator.cjs;
| let worker;
Run Code Online (Sandbox Code Playgroud)
这是我的依赖项package.json:
"dependencies": {
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"@types/node": "^15.3.0",
"bulma": "^0.9.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": …Run Code Online (Sandbox Code Playgroud) 我在使用 create-react-app 创建的项目中运行纱线,但收到此错误:
Exit code: 1
Command: start /B node compile.js & node compile.js
Arguments:
Directory: uber-web/node_modules/coa
Output:
/bin/sh: 1: start: not found
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module 'uber-web/node_modules/coa/compile.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
Run Code Online (Sandbox Code Playgroud)
我已经卸载了所有 .lock 和 node_module 文件夹,但它仍然不起作用。
我正在使用 React 创建一个应用程序,它运行良好npm start,但是当我尝试构建该应用程序时,显示以下错误。
PS D:\ ****\ **\*\profile> npm run build
> profile@0.1.0 build
> react-scripts build
D:\ ****\ **\profile\node_modules\react-scripts\config\webpack.config.js:664
new MiniCssExtractPlugin({
^
TypeError: MiniCssExtractPlugin is not a constructor
at module.exports (D:\Documents\Project\React\profile\node_modules\react-scripts\config\webpack.config.js:664:9)
at Object.<anonymous> (D:\Documents\Project\React\profile\node_modules\react-scripts\scripts\build.js:58:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Run Code Online (Sandbox Code Playgroud)
我在用着
| 包裹名字 | 版本 |
|---|---|
| 节点 | 16.13.2 |
| 新项目管理 | 8.1.2 |
| 恩克斯 | 8.1.2 |
这是我的package.json文件。
{
"name": "profile",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": …Run Code Online (Sandbox Code Playgroud) node.js npm reactjs create-react-app mini-css-extract-plugin
我们目前正在开发一个小型应用程序,它只渲染外部 React 组件(因为它是外部npm install组件)。此应用程序的目的是获取一些 JSON 配置并将其作为 prop 传递给该组件以演示其用法。
该应用程序是由 create-react-app 创建的,它对脚手架应用程序的唯一更改是 index.tsx 和 App.tsx 文件的内容。嗯,公共目录中还添加了两个 JSON 文件。
现在的问题是,这个项目可以在我同事的机器上编译并运行,但不能在我的机器上运行。之后npm ci我npm start得到以下信息:
Failed to compile.
Module not found: Error: You attempted to import /home/newlukai/story/app/node_modules/react-refresh/runtime.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
You can either move it inside src/, or add a symlink to it from project's node_modules/.
assets by path static/js/*.js 4.81 MiB
asset static/js/bundle.js 4.8 …Run Code Online (Sandbox Code Playgroud) 我们希望我们的项目使用\xc2\xa0 react-scripts v 5,并且根据\xc2\xa0 craco维护者最近的评论,支持最新版本CRA的新版本不会如果有的话,很快就会推出(除了 alpha 版本)。
\n我们的 craco.config 并没有做那么繁重的工作 - 我们用它来让 webpack 忽略\xc2\xa0 config \xc2\xa0files,\xc2\xa0限制 moment 使用的时区数据,并为 antd 转译 .less文件xc2\xa0(我们不打算永远使用 antd,但现在我们的应用程序中有它们的一些组件)。
\n我很好奇,现在 \xc2\xa0craco\xc2\xa0 正在走 \xc2\xa0意大利小镇的路,其他人在做什么?
\ncreate-react-app ×10
reactjs ×9
webpack ×5
javascript ×3
node.js ×2
npm ×2
craco ×1
es6-modules ×1
react-router ×1
webpack-2 ×1
yarnpkg ×1