我是 webpack 的新手,在构建处理方面,我一直依赖于 create-react-app 等工具的开箱即用功能。但是,我现在才开始“尝试”并深入了解事物 - 所以请原谅我的新手理解。
我们在整个应用程序中都使用 Lodash,并且我们正在努力确保我们只导入我们需要的内容。据我所知,有两种导入方式:
import assign from 'lodash/assign';import {assign} from 'lodash-es';我个人更喜欢第二个选项,因为如果您使用多个 Lodash 函数,您可以将所有导入合并为一行。
所以我安装了 lodash-es 库,从我的 package.json 中删除了 lodash,更新了所有的导入,然后运行了一个干净的构建。但是,当我使用 source-map-explorer 查看包时,即使我的 package.json 中没有列出 lodash,我也会看到对lodash-esas 的引用lodash。我认为这是因为它在 create-react-app 中的某个地方发货。请参阅下面的源地图...
使用import {assign} from 'lodash-es'约定的示例 Sourcemap

我认为这是一件坏事,并认为我可能正在“双重导入”已经在 create-react-app 中使用/导入的 lodash 函数。所以我尝试使用选项 1. 来做我的导入。然而,令我惊讶的是,实际上应用程序的总大小似乎更大,而且 lodash 导入的大小实际上比使用选项 2 时多约 3k!
使用import assign from 'lodash/assign'约定的示例 Sourcemap

所以我的问题是 - 我是否正确解释了 lodash-es 中的源映射实际上是一种更有效的导入方式,而“双重导入”实际上并不是一种风险。还是选项 1 约定是使用 lodash 处理导入的最佳方式?
我jsconfig.json在我的 vscode 项目中添加了一个,由于某种原因,我收到一个打字稿错误,指出“dotenv/types未找到”。
我一生都无法弄清楚为什么会出现这个错误。我什至尝试将 dotenv 添加到我的中package.json,但它没有解决我的问题。
这是使用 create-react-app 创建的标准项目,我添加了jsconfig.json来允许绝对导入
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
Run Code Online (Sandbox Code Playgroud)
例外:
找不到文件“/Users/path/to/file/node_modules/dotenv/types”。
其他可能有用的潜在文件:
package.json
{
"name": "quantous-spa",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.20.0",
"babel-plugin-macros": "^2.8.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-feather": "^2.0.8",
"react-loading-skeleton": "^2.1.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"styled-components": "^5.1.1",
"typeface-muli": "^1.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject" …Run Code Online (Sandbox Code Playgroud) javascript typescript reactjs visual-studio-code create-react-app
我正在尝试合并在一定时间间隔后触发的本地通知,但是,在使用模拟器进行测试时,我似乎无法在任何时候显示通知.
我只是想在创建后10秒显示本地通知,但是,当在模拟器中运行应用程序时,无论应用程序是在前台还是后台,都不会显示任何内容.
我错过了什么吗?这可能与时区有关吗?
//通知设置
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
localNotification.alertBody = @"Testing";
localNotification.alertAction = @"Show me the item";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Run Code Online (Sandbox Code Playgroud)
//这是我的app委托中的didReceiveLocalNotification
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder" message:notification.alertBody delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
Run Code Online (Sandbox Code Playgroud) timezone uiapplication ios uilocalnotification ios-simulator
bundle ×1
ios ×1
javascript ×1
lodash ×1
reactjs ×1
timezone ×1
tree-shaking ×1
typescript ×1
webpack ×1