我正在使用使用 Lodash 的 webpack 4/React 应用程序学习摇树。
起初,我的 Lodash 用法是这样的:
import * as _ from "lodash";
_.random(...
Run Code Online (Sandbox Code Playgroud)
我很快通过 BundleAnalyzerPlugin 了解到,整个 Lodash 都包含在开发和生产版本中(527MB)。
经过google搜索周围,我意识到,我需要使用特定的语法:
import random from "lodash/random";
random(...
Run Code Online (Sandbox Code Playgroud)
现在,只有random
它的依赖项正确地包含在包中,但我仍然有点困惑。
如果我需要在我的import
语句中明确指定函数,那么 tree-shaking 实际扮演了什么角色?在比较开发和生产模式构建时,BundleAnalyzerPlugin 没有显示有效负载大小的差异(这两者都是正确的小尺寸,但我认为摇树仅发生在生产构建中?)。
我的印象是 TreeShaking 会执行某种静态代码分析,以确定实际使用了哪些代码部分(可能基于功能?)并剪掉未使用的位。
为什么我们不能总是只*
在我们的中使用import
并依靠 TreeShaking 来找出实际包含在包中的内容?
如果有帮助,这是我的webpack.config.js
:
const path = require("path");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
module.exports = {
entry: {
app: ["babel-polyfill", "./src/index.js"]
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: "static",
openAnalyzer: false
})
],
devtool: "source-map", …
Run Code Online (Sandbox Code Playgroud) 我有一个包含组件路径的 path.json 文件
// path.json
{
"main": "./login/index.js",
"paths": [
{
"name": "login",
"path": "./login/index.js",
"image": ""
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想在 react native 中动态加载'./login/index.js'文件并呈现这个特定文件
我目前的实施
const MyComponent = createLazyContainer(() => {
const componentPath = PathJson.main; // ./login/index.js
return import(`${componentPath}`); //import error here @ line 7
});
export default MyComponent;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
第 7 行的无效调用:import("" + componentPath)
我对 React 很陌生,需要问一下。我可以在库中拥有 ReactJs Redux 存储,然后在也具有 Redux 存储的应用程序中使用该库吗?
他们俩都这样做:
<Provider store={store}>
..App
</Provider>
Run Code Online (Sandbox Code Playgroud)
我学习 ReactJs,但不确定我是否理解 Webpack 是如何构建这里的代码的。
我已经测试过执行其中一些操作,但无法使其工作。就像 Redux 第一次加载库 Redux store 之后就无法加载 App store 但我是新手所以必须问
以下代码是我ScrollView
在react native
项目中的代码:
<ScrollView
ref={(scrollView) => { this._scrollView = scrollView; }}
horizontal={true}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
directionalLockEnabled={true}
bounces={false}
scrollsToTop={false}
>
Run Code Online (Sandbox Code Playgroud)
现在它从左向右移动,如何在第一次加载时从右向左移动?
我有一个 Ubuntu 幼虫 AWS 实例正在运行,我正在尝试更改一些权限:
当我访问新安装站点的 IP 地址时,我收到此警告:
The /var/www/seekadventure.net directory is not writable.
Please chmod this directory and its contents to 0775.
Run Code Online (Sandbox Code Playgroud)
所以在命令行中我试试这个:
ubuntu@ip-172-31-80-211:/var/www$ sudo chmod 0775 /var/www/seekadventure.net
ubuntu@ip-172-31-80-211:/var/www$ ls -la
total 20
drwxr-xr-x 5 root root 4096 Dec 14 05:32 .
drwxr-xr-x 14 root root 4096 Feb 27 2018 ..
drwxr-xr-x 12 www-data www-data 4096 Feb 28 2018 laravel5.6
drwxrwxr-x 5 root root 4096 Dec 14 05:34 seekadventure.net
drwxr-xr-x 3 www-data www-data 4096 Nov 8 13:32 utility
ubuntu@ip-172-31-80-211:/var/www$ …
Run Code Online (Sandbox Code Playgroud) 我正在使用Fabric.js
在画布上绘制一些矩形。默认行为是在矩形内单击以选择它。如何更改行为,使其仅在单击矩形边框时才被选中?
单击矩形内部而不是边框应该什么都不做。
您可以通过在 TradingView.com 图表上绘制一个矩形来查看此行为
它在结构中有一个选项,如果没有,我该如何实施它?
我有一个getUrl()
调用 API 端点的方法
useEffect(() => {
getUrl()
.then(x => x.json())
.then(x => {
const { result } = x;
});
});
Run Code Online (Sandbox Code Playgroud)
我可以在控制台中看到我页面中的调用,正如您在屏幕截图中看到的,这是我的数据
{
"result":"https://www.google.it",
"error":null,
"errorCode":null,
"isSuccessful":true,
"operationStatusCode":"OK"
}
Run Code Online (Sandbox Code Playgroud)
如何在我的视图中在外部链接中显示以下result
链接示例https://www.gooole.it?
我必须使用状态吗?
我需要一个如何编码的例子在这里
<a target="_blank" href={result}>Google Link</a>
Run Code Online (Sandbox Code Playgroud)
我正在使用 webpack 开发服务器端 react-node 项目。我在控制台上有太多错误,我从昨天开始就无法弄清楚。我希望有人花时间帮助我。这是最后一个错误:
ERROR in ./src lazy ^\.\/.*$ namespace object ./main
It's not allowed to load an initial chunk on demand. The chunk name "main" is already used by an entrypoint.
Run Code Online (Sandbox Code Playgroud)
这是服务器设置:
import express from "express";
const server = express();
import path from "path";
// const expressStaticGzip = require("express-static-gzip");
import expressStaticGzip from "express-static-gzip";
import webpack from "webpack";
import webpackHotServerMiddleware from "webpack-hot-server-middleware";
import configDevClient from "../../config/webpack.dev-client";
import configDevServer from "../../config/webpack.dev-server.js";
import configProdClient from "../../config/webpack.prod-client.js";
import …
Run Code Online (Sandbox Code Playgroud) 由于某种原因,我无法再在我的项目上进行 NPM 安装,因为我收到以下消息:
SOLINK_MODULE(target) Release/.node
clang: warning: using sysroot for 'iPhoneSimulator' but targeting 'MacOSX' [-Wincompatible-sysroot]
ld: warning: building for macOS, but linking in .tbd file (/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.5.sdk/usr/lib/libc++.tbd) built for iOS Simulator
ld: warning: building for macOS, but linking in .tbd file (/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.5.sdk/usr/lib/libSystem.tbd) built for iOS Simulator
ld: warning: building for macOS, but linking in .tbd file (/usr/lib/system/libcache.dylib) built for iOS Simulator
ld: warning: building for macOS, but linking in .tbd file (/usr/lib/system/libcommonCrypto.dylib) built for iOS Simulator
ld: warning: building for macOS, …
Run Code Online (Sandbox Code Playgroud) 升级iOS 14版本后,React Native构建失败。将 XCode 构建设置切换为“传统构建设置”并成功构建。
但是新版本不加载图像,图像的原始部分现在是白屏
<Image
source={require('./images/home.png')}
/>
Run Code Online (Sandbox Code Playgroud)
系统规格
Environment:
Xcode Version 12.0
Simulator: IPhone X - 2nd generation - 14.0
"react": "16.11.0",
"react-native": "0.62.2"
Run Code Online (Sandbox Code Playgroud) reactjs ×5
javascript ×4
react-native ×4
ios ×2
node.js ×2
webpack ×2
chmod ×1
cocoapods ×1
ecmascript-6 ×1
es6-modules ×1
fabricjs ×1
lodash ×1
npm ×1
react-hooks ×1
redux ×1
scrollview ×1
server-side ×1
tree-shaking ×1
ubuntu ×1
use-effect ×1