我有一个使用 Webpack 作为捆绑器的 React 项目,我将我的捆绑包分成两个块 - 主代码库main.js
和供应商捆绑包vendor.js
。
构建这些捆绑包后,main.js
最终大小为 45kb 和vendor.js
651kb。
一个特定的供应商库大小为 225kb,似乎是供应商导入中最严重的违规者。
我正在文件顶部的页面组件中导入该库:
import React from 'react';
import { ModuleA, ModuleB } from 'heavyPackage'; // 225kb import
...
const Page = ({ setThing }) => {
...
};
Run Code Online (Sandbox Code Playgroud)
为了尝试将这个繁重的导入加载到单独的包中,我尝试使用动态导入来导入这些模块。
在组件内部Page
,直到调用特定函数才真正使用模块,因此我尝试在该范围内而不是在文件顶部导入模块:
import React from 'react';
...
const Page = ({ setThing }) => {
...
const handleSignIn = async () => {
const scopedPackage = await import('heavyPackage');
const { moduleA, moduleB …
Run Code Online (Sandbox Code Playgroud) 在某些情况下,我不想在webpack 4中使用webpack转换来动态导入.
我们可以用一些选项做到这一点吗?
async componentDidMount() {
const { default: Greeting } = await import("/components/Greeting.js");
this.setState({ component: Greeting });
}
Run Code Online (Sandbox Code Playgroud)
这/components/Greeting.js
是在服务器上预编译的.它在chrome中没有正确的webpack工作.
webpack正在尝试编译并发出错误
Uncaught (in promise) Error: Cannot find module '/components/Greeting.js'
at webpackMissingModule
Run Code Online (Sandbox Code Playgroud) As in the title I'd like to convert GetProcAddress into std::function. Yes, there are multiple solutions in stack overflow, but none actually explains why those workarounds are needed. I can't really understand the exact error message and why it happens. The sample source is simple:
#include <functional>
#include <Windows.h>
using fn_NtAllocateVirtualMemory = NTSTATUS (NTAPI*)(
HANDLE ProcessHandle,
PVOID* BaseAddress,
ULONG_PTR ZeroBits,
PSIZE_T RegionSize,
ULONG AllocationType,
ULONG Protect
);
int main()
{
std::function<fn_NtAllocateVirtualMemory> myFn(reinterpret_cast<fn_NtAllocateVirtualMemory>(0xDEADBABE));
}
Run Code Online (Sandbox Code Playgroud)
( https://godbolt.org/z/FhaeLA )
So, my question is …
我正在将 SvelteJs 与 svelte-spa-router 一起使用。
我有我的案例
<script>
import Component1 from './Component1.svelte'
import Component2 from './Component2.svelte'
</script>
{#if condition}
<Component1 {...props1} />
{:else}
<Component2 {...props2} />
{/if}
Run Code Online (Sandbox Code Playgroud)
我有更好的方法可以做到这一点吗?我可以仅在满足条件时动态导入和渲染组件吗?
我有这段代码可以在 CommonJS 上运行,但我想将我的项目切换到 ES6,但我得到的错误是.bind
isn\xe2\x80\x99t 函数,所以我想知道是否有人知道我如何切换它超过。
for (const file of player) {\n const event = import(`./player/${file}`);\n\n Storage.player.on(file.split(".")[0], event.bind(null, client));\n}\n
Run Code Online (Sandbox Code Playgroud)\n