<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vueshenzhen on Medium]]></title>
        <description><![CDATA[Stories by Vueshenzhen on Medium]]></description>
        <link>https://medium.com/@vueshenzhen?source=rss-199e0fde1857------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EboxkRlolgpN3LuB4GmVHQ.png</url>
            <title>Stories by Vueshenzhen on Medium</title>
            <link>https://medium.com/@vueshenzhen?source=rss-199e0fde1857------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:21:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vueshenzhen/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Crypto-js-wasm: An alternative to crypto-js implemented with WebAssembly and ESM]]></title>
            <link>https://medium.com/@vueshenzhen/crypto-js-wasm-an-alternative-to-crypto-js-implemented-with-webassembly-and-esm-886a1d9a05dd?source=rss-199e0fde1857------2</link>
            <guid isPermaLink="false">https://medium.com/p/886a1d9a05dd</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Vueshenzhen]]></dc:creator>
            <pubDate>Sun, 31 Jul 2022 08:59:14 GMT</pubDate>
            <atom:updated>2022-07-31T08:59:14.737Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript, a high-level and just-in-time compiled programming language, has ruled the frontend development for over 20 years. However, performance and security have become the bottlenecks in building modern websites with JavaScript. This is where WebAssembly comes in useful.</p><h3>What’s WebAssembly?</h3><blockquote><em>WebAssembly (abbreviated </em>Wasm<em>) is a binary instruction format for a stack-based virtual machine.</em></blockquote><p>Designed to complement and run alongside JavaScript, WebAssembly code can be run at near native speed in modern web browsers. <a href="https://webassembly.org/roadmap/">WebAssembly roadmap</a> shows that most features of WebAssembly are supported in all of modern javascript runtime environments(e.g., Chrome, Firefox, Safari, Node.js).</p><p>WebAssembly is seldom written directly using the <a href="https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format">WebAssembly text format</a>. Instead, we usually compile WebAssembly modules from C/C++, Rust, AssemblyScript, C#, Go or other programming language(see <a href="https://webassembly.org/getting-started/developers-guide/">here</a> for more details).</p><h3>Pros of WebAssembly</h3><ul><li>Fast: A WebAssembly application is pre-compiled and more efficient than a JavaScript application.</li><li>Safe: WebAssembly describes a memory-safe, sandboxed execution environment.</li></ul><h3>Cons of WebAssembly</h3><ul><li><strong>Memory copy</strong>: WebAssembly has a different runtime compared to JavaScript, hence the memory has to be copied between these two runtimes. This is implemented using some javascript ‘glue code’. Please note the memory copy may take <em>some</em> time.</li><li><strong>Loading</strong>: WebAssembly modules need to be loaded before being used.</li><li><strong>New</strong>: The ecosystem of WebAssembly is still growing, with many libraries still under development.</li></ul><p>Basing on the pros and cons of WASM, we believe that it is a good idea to develop crypto algorithms using WebAssembly, crypto algorithms are performance sensitive, and most are only called once.</p><h3>Crypto-js-wasm</h3><p>Inspired by <a href="https://github.com/brix/crypto-js">crypto-js</a>, we have developed <a href="https://github.com/originjs/crypto-js-wasm">crypto-js-wasm</a>. Besides WebAssembly, we have also included jest and build scripts. <a href="https://www.npmjs.com/package/@originjs/crypto-js-wasm">crypto-js-wasm 1.0.0</a> has already been published on NPM, which supports all APIs of crypto-js.</p><h3>Installation</h3><pre>npm install @originjs/crypto-js-wasm</pre><h3>Usage</h3><p>As introduced above, WebAssembly modules need to be loaded beforehand. Therefore, we need to load the corresponding module by calling the loadWasm of each algorithm, or we can use loadAllWasm to load all the WebAssembly modules. Note that the required WebAssembly modules only need to be loaded once.</p><pre>import CryptoJSW from &#39;crypto-js-wasm&#39;;<br>​<br>// (Optional) load all wasm files<br>await CryptoJSW.loadAllWasm();<br>​<br>// Async/Await syntax<br>await CryptoJSW.MD5.loadWasm();<br>const rstMD5 = CryptoJSW.MD5(&#39;message&#39;).toString();<br>console.log(rstMD5);<br>​<br>// Promise syntax<br>CryptoJSW.SHA256.loadWasm().then(() =&gt; {<br>    const rstSHA256 = CryptoJSW.SHA256(&#39;message&#39;).toString();<br>    console.log(rstSHA256);<br>})</pre><h3>Benchmark</h3><p>To evaluate our library, we have developed a <a href="https://github.com/originjs/WASM-benchmark">benchmark</a> to compare between crypto-js-wasm and crypto-js. The benchmark can be run in browser and nodejs. We have also deployed an <a href="https://originjs.org/WASM-benchmark/#/">online benchmark</a>.</p><p>The benchmark below is run on a desktop PC (i5–4590, 16 GB RAM, Windows 10 Version 21H2 (OSBuild 19044, 1466)).</p><p><strong>Chrome</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/0*YMzhZjrZoSosIvH7.png" /></figure><p><strong>Firefox</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/0*ow1dKWBOkp3yPyva.png" /></figure><p><strong>Node.js</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/0*zI3EU1fj1B-GSUPz.png" /></figure><p>According to the benchmark, crypto-js-wasm has a better speed performance in most cases, even achieving a 16x speed boost in some algorithms.</p><h3>Conclusion</h3><p>If you are looking for a JavaScript library for crypto, or you are using crypto-js now, you can take a look at our crypto-js-wasm <a href="https://github.com/originjs/crypto-js-wasm">GitHub repo</a> or <a href="https://www.npmjs.com/package/@originjs/crypto-js-wasm">npm package</a>. Issues and PRs are always welcome. :)</p><h3>Future Work</h3><p>We are planning to publish our next version supporting RSA in the coming months.</p><p>Reference</p><ol><li><a href="https://webassembly.org/">WebAssembly offical website</a></li><li><a href="https://developer.mozilla.org/en-US/docs/WebAssembly">WebAssembly | MDN</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=886a1d9a05dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A brief introduction of vite-plugin-federation]]></title>
            <link>https://medium.com/@vueshenzhen/a-brief-introduction-of-vite-plugin-federation-9e998b2e43b?source=rss-199e0fde1857------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e998b2e43b</guid>
            <category><![CDATA[vite-plugin]]></category>
            <category><![CDATA[module-federation]]></category>
            <category><![CDATA[micro-frontends]]></category>
            <dc:creator><![CDATA[Vueshenzhen]]></dc:creator>
            <pubDate>Fri, 07 Jan 2022 02:27:05 GMT</pubDate>
            <atom:updated>2022-01-10T11:28:11.640Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Multiple separate builds should form a single application. These separate builds should not have dependencies between each other, so they can be developed and deployed individually.</blockquote><blockquote>This is often known as Micro-Frontends, but is not limited to that.</blockquote><p>This is an official introduction of module-federation from <em>webpack</em>, and also a description of <em>vite-plugin-federation</em>.</p><h3>Why we create vite-plugin-federation</h3><p><em>Module-federation</em> showed us some exciting functions but only under <em>webpack5</em>. Since <em>vite</em> is booming for the time being, we hope <em>module-federation</em> can be used on <em>vite</em>. (That&#39;s why we create <em>vite-plugin-federation</em>.)</p><h3>Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y4hSsm1lF4b_a4abHFaH5w.png" /></figure><p>The example can be accessed here:</p><p><a href="https://github.com/originjs/vite-plugin-federation/tree/main/packages/examples/vue3-advanced-demo">https://github.com/originjs/vite-plugin-federation/tree/main/packages/examples/vue3-advanced-demo</a></p><p>Under packages/example/, a demo of the plugin can be found and boost with <em>pnpm build &amp; pnpm serve</em>.</p><h3>Quick Start</h3><p>Before using it, I recommend to first understand the following concepts, which are the same as in <em>webpack</em>.</p><ul><li>remote: service provider</li><li>host: service consumer</li><li>shared: shared dependency library, which can make host and remote use the same underlying dependency instead of introducing multiple underlying dependencies at the same time</li></ul><p>For example, a simple project (omitting configuration files)</p><pre>demo<br>├── host<br>│ ├── index.html<br>│ └── src<br>│ └── index.js<br>└── remote<br>    └── src<br>        ├── button.vue<br>        └── index.js</pre><h4>Step 1: Install vite-plugin-federation</h4><p><em>pnpm: pnpm</em> install @originjs/vite-plugin-federation -D</p><p><em>yarn: yarn</em> add @originjs/vite-plugin-federation — dev</p><p><em>npm: npm</em> install @originjs/vite-plugin-federation -D</p><h4>Step 2: The remote part exposes the components</h4><p>Configure the following in <em>remote/vite.config.js</em></p><pre>export default defineConfig ({<br>  ...<br>  plugins: [<br>    federation ({<br>      //name of your app<br>      name:&#39;demo-remote&#39;,<br>      // Can be customized, but remoteEntry is a conventional name<br>      filename:&#39;remoteEntry.js&#39;,<br>      // Configure externally exposed components<br>      exposes: {<br>        &#39;./button&#39;:&#39;./src/components/button.vue&#39;<br>      },<br>      //share vue<br>      shared: [&#39;vue&#39;]<br>    })<br>  ],<br>  ...<br>})</pre><h4>Step 3: The host part defines remote</h4><p>Configure the following in host/vite.config.js</p><pre>export default defineConfig ({<br>   ...<br>   plugins: [<br>     federation ({<br>       //name of remote app<br>       name:&#39;demo-host&#39;,<br>       remotes: {<br>         //the address of remoteEntry<br>         demo-remote:&#39;<a href="http://localhost:5001/assets/remoteEntry.js&#39;">http://localhost:5001/assets/remoteEntry.js&#39;</a><br>       },<br>       //share vue<br>       shared: [&#39;vue&#39;]<br>     })<br>   ]<br>   ...<br>})</pre><h4>Step 4: The host part uses remote components</h4><pre>const app = createApp ();<br>// Define components, note that this is vue&#39;s way of writing, different frameworks define remote components in different ways<br>const remoteButton = defineAsyncComponent (() =&gt; import (&quot;demo-remote/button&quot;));<br>app.component (&quot;button&quot;, remoteButton);</pre><pre>// Finally, just use the defined component just like using the local component</pre><p>Then <em>build &amp; serve </em>to see the results.</p><h3>Integration with webpack</h3><p>Considering that some projects have used <em>webpack</em> and <em>module-federation</em> and are gradually moving to <em>vite</em>, <em>vite-plugin-federation</em> can consume <em>webpack</em> <em>module-federation</em> plugins but in restricted conditions. The restrictions are as follow.</p><h3>Current restrictions</h3><ul><li>The <em>vite</em> dev mode currently only supports host and does not support remote side.</li><li>Integration with <em>webpack</em> only supports the use of <em>webpack</em> <em>module-federation</em> on the remote side, with restrictions on packaging format as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgQtFG_hgavGQxVc21rN_w.png" /></figure><h3>Follow-up plan</h3><ul><li>Provide support for host: <em>webpack</em>+ remote: <em>vite-plugin-federation</em></li><li>Provide support for packaging format of <em>webpack</em> esm after it&#39;s stablized (currently experimental feature).</li><li>Provide support for <em>vite</em> remote dev mode.</li></ul><h3>Choose vite-plugin-federation or module-federation</h3><p>When you choose between vite and webpack, you naturally choose between vite-plugin-federation and module-federation.</p><h3>Repo</h3><p><a href="https://github.com/originjs/vite-plugin-federation">GitHub - originjs/vite-plugin-federation: Module Federation for vite &amp; rollup</a></p><p>Issue and contributions are all welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e998b2e43b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>