Skip to content

Commit

Permalink
chore: upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ZLY201 committed Feb 7, 2024
1 parent 6dbb173 commit 43ae299
Show file tree
Hide file tree
Showing 5 changed files with 802 additions and 826 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/problems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import problemsJson from '@config/problems.json';
import i18nJson from '@config/i18n.json';
import localCache from '@src/utils/local-cache';
import { Setting } from '@src/utils/setting';
import typeAssertions from '@problems/type-assertions';
import typeAssertions from '@problems/type-assertions-raw';

export type Problem = {
key: string;
Expand Down
24 changes: 12 additions & 12 deletions tools/RspackSSRPlugin.ts → tools/SSRRspackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type RspackSSRPluginOptions = {
template: string;
};

class RspackSSRPlugin implements RspackPluginInstance {
class SSRRspackPlugin implements RspackPluginInstance {
private readonly templateContent: string;
private readonly options: RspackSSRPluginOptions;
constructor(options: RspackSSRPluginOptions) {
Expand All @@ -18,7 +18,7 @@ class RspackSSRPlugin implements RspackPluginInstance {
}
apply(compiler: Compiler) {
const mode = compiler.options.mode;
const pluginName = RspackSSRPlugin.name;
const pluginName = SSRRspackPlugin.name;
const tabFunc =
mode === 'development'
? compiler.hooks.watchRun
Expand All @@ -31,9 +31,9 @@ class RspackSSRPlugin implements RspackPluginInstance {
);
}
replaceTemplateFile(compiler: Compiler, callback: () => void) {
const token = this.options.token;
const context = compiler.context;
const mode = compiler.options.mode;
const { token, template } = this.options;
const templateContent = this.templateContent;
const buildProcess = childProcess.spawn('yarn', [
'build:ssr',
Expand All @@ -48,14 +48,13 @@ class RspackSSRPlugin implements RspackPluginInstance {
const getSSRContent = require(ssrFilePath).default;
delete require.cache[require.resolve(ssrFilePath)];
const ssrContent = getSSRContent();
const newTemplateContent = templateContent.replace(token, ssrContent);
writeFileSync(
path.resolve(context, './html/index.html'),
newTemplateContent,
{
encoding: 'utf-8',
},
const newTemplateContent = templateContent.replace(
`{% ${token} %}`,
ssrContent,
);
writeFileSync(path.resolve(context, template), newTemplateContent, {
encoding: 'utf-8',
});
callback();
} else {
throw new Error(`Generate SSR content failed with code ${code}`);
Expand All @@ -64,11 +63,12 @@ class RspackSSRPlugin implements RspackPluginInstance {
}
recoverTemplateFile(compiler: Compiler) {
const context = compiler.context;
const template = this.options.template;
const templateContent = this.templateContent;
writeFileSync(path.resolve(context, './html/index.html'), templateContent, {
writeFileSync(path.resolve(context, template), templateContent, {
encoding: 'utf-8',
});
}
}

export default RspackSSRPlugin;
export default SSRRspackPlugin;
6 changes: 3 additions & 3 deletions tools/rspack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Configuration } from '@rspack/cli';
import HtmlRspackPlugin from '@rspack/plugin-html';
import { CopyRspackPlugin, DefinePlugin } from '@rspack/core';
import { ArcoDesignPlugin } from '@arco-plugins/unplugin-react';
import RspackSSRPlugin from './RspackSSRPlugin';
import SSRRspackPlugin from './SSRRspackPlugin';
import createBaseRspackConfig from './rspack.base.config';

export default function createRspackConfig(): Configuration {
Expand All @@ -21,9 +21,9 @@ export default function createRspackConfig(): Configuration {
ignored: template,
},
plugins: [
new RspackSSRPlugin({
new SSRRspackPlugin({
template,
token: '{% ROOT_CONTENT %}',
token: 'ROOT_CONTENT',
}),
new HtmlRspackPlugin({
template,
Expand Down
Loading

0 comments on commit 43ae299

Please sign in to comment.