我正在使用 esbuild 来使用 lit 构建我的 Web 组件。
我现在正在研究code splitting如何缩小我的包裹。
我生成了很多组件(~100),它们都具有相同的导入语句
import { LitElement, html, nothing } from "lit";
import { customElement, property } from 'lit/decorators.js';
Run Code Online (Sandbox Code Playgroud)
最终将 lit 中的代码导入到我的所有组件中。
添加
chunkNames: 'chunks/[name]-[hash]',
splitting: true,
format: 'esm',
Run Code Online (Sandbox Code Playgroud)
esbuild 配置使 esbuild 创建包含导入文件内容的“块”,并使每个包变得更小。正是我正在寻找的:)
但..
我导入的一些文件不在组件之间共享,只是将组件拆分为更多文件以使其更具可读性。
是否可以告诉 esbuild“不要创建此文件的块,只需将其捆绑到当前入口点”?
import { LitElement, html, nothing } from "lit"; //<-- Create a chunk of this
import { customElement, property } from 'lit/decorators.js';//<-- Create a chunk of this
import { ComponentViewModel } from './ViewModel'; //<--bundle this
import …Run Code Online (Sandbox Code Playgroud) 我正在尝试将结构传递给子/ void以用数据填充它.在C#中,这样可以正常工作
[TestFixture]
public class Boxing
{
[Test]
public void BoxingValue()
{
var res = (object)new Test();
SomeVoid(res);
Assert.AreEqual(2, ((Test)res).Id);
}
public static void SomeVoid(object b)
{
var f = b.GetType().GetField("Id");
f.SetValue(b, 2);
}
public struct Test
{
public int Id;
}
}
Run Code Online (Sandbox Code Playgroud)
此代码在vb thoug中通过C#中的测试
<Test> Public Sub StructTest()
Dim s As Object
s = CObj(New Test)
A(s)
Assert.AreEqual(2, CType(s, Test).Id)
End Sub
Public Sub A(val As Object)
Dim f = val.GetType().GetField("Id")
f.SetValue(val, 2)
End Sub
Public Structure Test
Public …Run Code Online (Sandbox Code Playgroud) 使用 svelte 创建 Web 组件,当组件的属性更改时,我需要运行一些代码。
我想出的是以下模式。
<script>
export let test = "default value";
$: {
testIsChanged(test);
}
function testIsChanged(newValue) {
console.log(newValue);
}
</script>
The value of test is {test}
Run Code Online (Sandbox Code Playgroud)
这是这样做的方法吗?或者我错过了什么?