Skip to content

Commit

Permalink
v3.1.8 fix: 修复 build 下 端口校验 & 抽离 @kkt/ssr 下 plugin 文件 & 整洁代码 (#28) d1…
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 28, 2022
1 parent 2c3dae2 commit 0eed886
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 42 deletions.
41 changes: 20 additions & 21 deletions create-kkt-ssr.html
Original file line number Diff line number Diff line change
Expand Up @@ -886,31 +886,30 @@ <h3 id="using-plugins"><a class="anchor" aria-hidden="true" tabindex="-1" href="
You can use plug-ins, taking KKT as an example
Add <code>.kktrc.js</code> to the root directory of your project
</p>
<p><strong>use SSRWebpackRunPlugin</strong></p>
<pre class="language-js"><code class="language-js"><span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> restWebpackManifestPlugin<span class="token punctuation">,</span> getRemoveHtmlTemp<span class="token punctuation">,</span> <span class="token maybe-class-name">SSRWebpackRunPlugin</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@kkt/ssr/lib/plugins'</span><span class="token punctuation">;</span>
<pre class="language-js"><code class="language-js"><span class="token keyword module">import</span> <span class="token imports">pluginLess</span> <span class="token keyword module">from</span> <span class="token string">"@kkt/plugin-less"</span>

<span class="token keyword module">export</span> <span class="token keyword module">default</span> <span class="token punctuation">(</span><span class="token parameter">conf<span class="token punctuation">,</span> evn</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>
<span class="token comment">// client ,</span>
<span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>options<span class="token punctuation">.</span><span class="token property-access">bundle</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
conf<span class="token punctuation">.</span><span class="token property-access">plugins</span><span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">SSRWebpackRunPlugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
conf<span class="token punctuation">.</span><span class="token property-access">plugins</span> <span class="token operator">=</span> <span class="token function">getRemoveHtmlTemp</span><span class="token punctuation">(</span>conf<span class="token punctuation">.</span><span class="token property-access">plugins</span><span class="token punctuation">)</span>
conf <span class="token operator">=</span> <span class="token function">restWebpackManifestPlugin</span><span class="token punctuation">(</span>conf<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
conf<span class="token punctuation">.</span><span class="token property-access">module</span><span class="token punctuation">.</span><span class="token property-access">exprContextCritical</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
<span class="token keyword control-flow">return</span> conf<span class="token punctuation">;</span>
<span class="token keyword module">export</span> <span class="token keyword module">default</span> <span class="token punctuation">{</span>
<span class="token function-variable function">overridesCommonWebpack</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">conf<span class="token punctuation">,</span> env<span class="token punctuation">,</span> options</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>
<span class="token keyword">const</span> newConfig <span class="token operator">=</span> <span class="token function">pluginLess</span><span class="token punctuation">(</span>conf<span class="token punctuation">,</span> <span class="token punctuation">{</span>
<span class="token literal-property property">target</span><span class="token operator">:</span> conf<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token operator">===</span><span class="token string">"node14"</span><span class="token operator">?</span><span class="token string">"node"</span><span class="token operator">:</span><span class="token string">"web"</span><span class="token punctuation">,</span>
env<span class="token punctuation">,</span>
<span class="token literal-property property">paths</span><span class="token operator">:</span> options<span class="token punctuation">.</span><span class="token property-access">paths</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword control-flow">return</span> newConfig
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

</code><div onclick="copied(this)" data-code="import { restWebpackManifestPlugin, getRemoveHtmlTemp, SSRWebpackRunPlugin } from &#x27;@kkt/ssr/lib/plugins&#x27;;
</code><div onclick="copied(this)" data-code="import pluginLess from &#x22;@kkt/plugin-less&#x22;
export default (conf, evn) => {
// client ,
if (!options.bundle) {
conf.plugins.push(new SSRWebpackRunPlugin());
conf.plugins = getRemoveHtmlTemp(conf.plugins)
conf = restWebpackManifestPlugin(conf);
}
conf.module.exprContextCritical = false;
return conf;
export default {
overridesCommonWebpack: (conf, env, options) => {
const newConfig = pluginLess(conf, {
target: conf.target===&#x22;node14&#x22;?&#x22;node&#x22;:&#x22;web&#x22;,
env,
paths: options.paths
})
return newConfig
},
};
" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
Expand Down
41 changes: 20 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -886,31 +886,30 @@ <h3 id="using-plugins"><a class="anchor" aria-hidden="true" tabindex="-1" href="
You can use plug-ins, taking KKT as an example
Add <code>.kktrc.js</code> to the root directory of your project
</p>
<p><strong>use SSRWebpackRunPlugin</strong></p>
<pre class="language-js"><code class="language-js"><span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> restWebpackManifestPlugin<span class="token punctuation">,</span> getRemoveHtmlTemp<span class="token punctuation">,</span> <span class="token maybe-class-name">SSRWebpackRunPlugin</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@kkt/ssr/lib/plugins'</span><span class="token punctuation">;</span>
<pre class="language-js"><code class="language-js"><span class="token keyword module">import</span> <span class="token imports">pluginLess</span> <span class="token keyword module">from</span> <span class="token string">"@kkt/plugin-less"</span>

<span class="token keyword module">export</span> <span class="token keyword module">default</span> <span class="token punctuation">(</span><span class="token parameter">conf<span class="token punctuation">,</span> evn</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>
<span class="token comment">// client ,</span>
<span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>options<span class="token punctuation">.</span><span class="token property-access">bundle</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
conf<span class="token punctuation">.</span><span class="token property-access">plugins</span><span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">SSRWebpackRunPlugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
conf<span class="token punctuation">.</span><span class="token property-access">plugins</span> <span class="token operator">=</span> <span class="token function">getRemoveHtmlTemp</span><span class="token punctuation">(</span>conf<span class="token punctuation">.</span><span class="token property-access">plugins</span><span class="token punctuation">)</span>
conf <span class="token operator">=</span> <span class="token function">restWebpackManifestPlugin</span><span class="token punctuation">(</span>conf<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
conf<span class="token punctuation">.</span><span class="token property-access">module</span><span class="token punctuation">.</span><span class="token property-access">exprContextCritical</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
<span class="token keyword control-flow">return</span> conf<span class="token punctuation">;</span>
<span class="token keyword module">export</span> <span class="token keyword module">default</span> <span class="token punctuation">{</span>
<span class="token function-variable function">overridesCommonWebpack</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">conf<span class="token punctuation">,</span> env<span class="token punctuation">,</span> options</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>
<span class="token keyword">const</span> newConfig <span class="token operator">=</span> <span class="token function">pluginLess</span><span class="token punctuation">(</span>conf<span class="token punctuation">,</span> <span class="token punctuation">{</span>
<span class="token literal-property property">target</span><span class="token operator">:</span> conf<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token operator">===</span><span class="token string">"node14"</span><span class="token operator">?</span><span class="token string">"node"</span><span class="token operator">:</span><span class="token string">"web"</span><span class="token punctuation">,</span>
env<span class="token punctuation">,</span>
<span class="token literal-property property">paths</span><span class="token operator">:</span> options<span class="token punctuation">.</span><span class="token property-access">paths</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword control-flow">return</span> newConfig
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

</code><div onclick="copied(this)" data-code="import { restWebpackManifestPlugin, getRemoveHtmlTemp, SSRWebpackRunPlugin } from &#x27;@kkt/ssr/lib/plugins&#x27;;
</code><div onclick="copied(this)" data-code="import pluginLess from &#x22;@kkt/plugin-less&#x22;
export default (conf, evn) => {
// client ,
if (!options.bundle) {
conf.plugins.push(new SSRWebpackRunPlugin());
conf.plugins = getRemoveHtmlTemp(conf.plugins)
conf = restWebpackManifestPlugin(conf);
}
conf.module.exprContextCritical = false;
return conf;
export default {
overridesCommonWebpack: (conf, env, options) => {
const newConfig = pluginLess(conf, {
target: conf.target===&#x22;node14&#x22;?&#x22;node&#x22;:&#x22;web&#x22;,
env,
paths: options.paths
})
return newConfig
},
};
" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
Expand Down
Binary file modified zip/basic-plugins.zip
Binary file not shown.
Binary file modified zip/basic-routes-rematch-new.zip
Binary file not shown.
Binary file modified zip/basic-routes.zip
Binary file not shown.
Binary file modified zip/basic.zip
Binary file not shown.
Binary file modified zip/react-router-rematch.zip
Binary file not shown.

0 comments on commit 0eed886

Please sign in to comment.