Skip to content

Commit

Permalink
fix(plugins) 修复 图片 url 地址问题 & 删除 match 参数 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLxy authored Mar 25, 2022
1 parent 6f1fc34 commit 692bc0e
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 44 deletions.
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kkt/ssr",
"version": "3.1.7",
"version": "3.1.8",
"description": "",
"license": "MIT",
"main": "lib/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


import { devServerConfigPath, reactDevUtils } from "../../overrides/pathUtils"
import { OverridesProps } from "../../overrides"
import { devServerConfigPath, reactDevUtils } from "./pathUtils"
import { OverridesProps } from "."
import webpackDevServer from "webpack-dev-server"
import MockerApi from "mocker-api"

Expand Down
2 changes: 1 addition & 1 deletion core/src/script/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import createCompiler from "./utils"
import createCompiler from "../utils"
import fs from "fs-extra";
import FileSizeReporter from "react-dev-utils/FileSizeReporter";
import { Paths, webpackConfigPath } from "./../overrides/pathUtils"
Expand Down
4 changes: 2 additions & 2 deletions core/src/script/start.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


import createCompiler from "./utils"
import createCompiler from "../utils"
import { OptionsProps } from "../interface"
import { webpackConfigPath, reactScripts, reactDevUtils } from "./../overrides/pathUtils"
import overridesDevServer from "./utils/overridesDevServer"
import overridesDevServer from "../overrides/overridesDevServer"
export default async (options: OptionsProps) => {
// 修复 运行 start 停止之后,再次运行 watch 报错
delete require.cache[require.resolve(webpackConfigPath)];
Expand Down
2 changes: 1 addition & 1 deletion core/src/script/watch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


import createCompiler from "./utils"
import createCompiler from "../utils"
import clearConsole from 'react-dev-utils/clearConsole';
import { OptionsProps } from "../interface"
import { webpackConfigPath } from "./../overrides/pathUtils"
Expand Down
17 changes: 12 additions & 5 deletions core/src/script/utils/index.ts → core/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// 根据 kkt 写法 重置 create-react-app 中的 react-script配置
import { reactScripts, webpackConfigPath } from "../../overrides/pathUtils"
import { reactScripts, webpackConfigPath } from "../overrides/pathUtils"
import webpackNodeExternals from "webpack-node-externals"
import webpack from "webpack"
import { OptionsProps } from "../../interface"
import { OptionsProps } from "../interface"
import fs from 'fs';
import nodemonWebpackPlugin from "nodemon-webpack-plugin"
import { loaderConf, OverridesProps } from "./../../overrides"
import { loaderConf, OverridesProps } from "../overrides"

import DevServerPlugins from "./devServer"
import DevServerPlugins from "./plugins/devServer"

import CreateTemporaryAsset from "./plugins/CreateTemporaryAsset"

import {
getWbpackBarPlugins,
Expand All @@ -16,7 +18,7 @@ import {
clearHtmlTemp,
restDevModuleRuleCss,
removeSourceMapLoader
} from "../../overrides/utils"
} from "../overrides/utils"

const { choosePort } = require('react-dev-utils/WebpackDevServerUtils');
// 引入环境变量
Expand Down Expand Up @@ -71,17 +73,21 @@ const getWebpackConfig: GetWebpackConfig = (newConfig, type, overrides, nodeExte
/** 重置 输入配置 */
newConfig = restOutPut(newConfig, out)

/** start 命令下 生成 client 端 asset 文件 **/
let isCreateAsset = false;

if (isWebpackDevServer && type === "client" && env === "development") {
isCreateAsset = true
}
/** start 命令下 生成 server.js文件和 自动启动 server.js 服务 */
if (isWebpackDevServer && type === "server" && env === "development") {
newConfig.plugins.push(
/** 生成 server.js 文件 */
new DevServerPlugins({
filename: `${out.filename}`,
outputPath: out.path
}),
/** 自动启动 server.js 文件服务 */
new nodemonWebpackPlugin({
script: `${out.path}/${out.filename}`,
watch: [`${out.path}`]
Expand Down Expand Up @@ -115,6 +121,7 @@ const getWebpackConfig: GetWebpackConfig = (newConfig, type, overrides, nodeExte

newConfig.plugins.push(
new webpack.DefinePlugin(define),
new CreateTemporaryAsset(`${overrides.output_path}/asset-${type}-manifest.json`)
)

if (!split) {
Expand Down
17 changes: 17 additions & 0 deletions core/src/utils/plugins/CreateTemporaryAsset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* 解决 打包时 页面引入 asset 报错问题
* **/
import FS from 'fs-extra';
export default class CreateTemporaryAsset {
pathname = ""

constructor(pathname: string) {
this.pathname = pathname
}

apply() {
if (!FS.existsSync(this.pathname)) {
FS.ensureFileSync(this.pathname)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import webpack from "webpack"
import FS from 'fs-extra';


class DevServerPlugins {
class CreateTemporaryAsset {

filename = "server.js"
outputPath = ""

constructor(props: { filename: string, outputPath: string }) {
constructor(props: { filename: string, outputPath: string, }) {
this.filename = props.filename
this.outputPath = props.outputPath
}
Expand All @@ -27,4 +27,4 @@ class DevServerPlugins {
}
}

export default DevServerPlugins
export default CreateTemporaryAsset
4 changes: 2 additions & 2 deletions example/basic-plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/basic-plugins",
"version": "3.1.7",
"version": "3.1.8",
"description": "",
"private": true,
"scripts": {
Expand All @@ -16,7 +16,7 @@
"react-dom": "17.0.2"
},
"devDependencies": {
"@kkt/ssr": "3.1.7",
"@kkt/ssr": "3.1.8",
"kkt": "~7.1.5"
},
"browserslist": {
Expand Down
4 changes: 2 additions & 2 deletions example/basic-routes-rematch-new/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/basic-routes-rematch-new",
"version": "3.1.7",
"version": "3.1.8",
"description": "",
"private": true,
"scripts": {
Expand All @@ -22,7 +22,7 @@
"serialize-javascript": "6.0.0"
},
"devDependencies": {
"@kkt/ssr": "3.1.7",
"@kkt/ssr": "3.1.8",
"kkt": "~7.1.5"
},
"browserslist": {
Expand Down
4 changes: 2 additions & 2 deletions example/basic-routes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/basic-routes",
"version": "3.1.7",
"version": "3.1.8",
"description": "",
"private": true,
"scripts": {
Expand All @@ -18,7 +18,7 @@
"react-router-dom": "^6.2.2"
},
"devDependencies": {
"@kkt/ssr": "3.1.7",
"@kkt/ssr": "3.1.8",
"kkt": "~7.1.5"
},
"browserslist": {
Expand Down
4 changes: 2 additions & 2 deletions example/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/basic",
"version": "3.1.7",
"version": "3.1.8",
"description": "",
"private": true,
"scripts": {
Expand All @@ -16,7 +16,7 @@
"react-dom": "17.0.2"
},
"devDependencies": {
"@kkt/ssr": "3.1.7",
"@kkt/ssr": "3.1.8",
"kkt": "~7.1.5"
},
"browserslist": {
Expand Down
8 changes: 4 additions & 4 deletions example/react-router-rematch-old/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/basic-routes-rematch-old",
"version": "3.1.7",
"version": "3.1.8",
"description": "",
"private": true,
"scripts": {
Expand All @@ -15,7 +15,7 @@
"author": "Kenny Wong <[email protected]>",
"license": "MIT",
"dependencies": {
"@kkt/react-ssr-enhanced": "3.1.7",
"@kkt/react-ssr-enhanced": "3.1.8",
"@rematch/core": "2.2.0",
"axios": "0.26.0",
"cookie-parser": "1.4.3",
Expand All @@ -31,8 +31,8 @@
"redux": "4.1.2"
},
"devDependencies": {
"@kkt/plugin-less": "3.1.7",
"@kkt/ssr": "3.1.7",
"@kkt/plugin-less": "3.1.8",
"@kkt/ssr": "3.1.8",
"assert": "2.0.0",
"browserify-zlib": "0.2.0",
"buffer": "6.0.3",
Expand Down
7 changes: 3 additions & 4 deletions example/react-router-rematch-old/src/serverIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import { createStore } from './store';

const assetPath = `${OUTPUT_PUBLIC_PATH}/asset-client-manifest.json`


// require 方式 打包报错
let assetsMainifest = {}
if (FS.existsSync(assetPath)) {
assetsMainifest = new Function(`return ${FS.readFileSync(`${assetPath}`, "utf-8")}`)()
}
// if (FS.existsSync(assetPath)) {
assetsMainifest = new Function(`return ${FS.readFileSync(`${assetPath}`, "utf-8")}`)()
// }

const appDirectory = FS.realpathSync(process.cwd());
const resolveApp = (relativePath) => Path.resolve(appDirectory, relativePath);
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"packages/react-ssr-enhanced",
"packages/kkt-plugin-less"
],
"version": "3.1.7",
"version": "3.1.8",
"command": {
"create": {
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-kkt-ssr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-kkt-ssr",
"version": "3.1.7",
"version": "3.1.8",
"description": "CLI tool to bootstrap KKT applications with no configuration",
"main": "lib/index.js",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion packages/kkt-plugin-less/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kkt/plugin-less",
"version": "3.1.7",
"version": "3.1.8",
"description": "Support less.",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
14 changes: 7 additions & 7 deletions packages/kkt-plugin-less/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ export default (conf: WebpackConfiguration, options: LessOptions): WebpackConfig
},
},
postcssLoader,
{
loader: require.resolve('resolve-url-loader'),
options: {
sourceMap: shouldUseSourceMap,
root: options.paths.appSrc,
},
},
// {
// loader: require.resolve('resolve-url-loader'),
// options: {
// sourceMap: shouldUseSourceMap,
// root: options.paths.appSrc,
// },
// },
{
loader: require.resolve('less-loader'),
options: {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ssr-enhanced/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kkt/react-ssr-enhanced",
"version": "3.1.7",
"version": "3.1.8",
"description": "KKT react server side rendering enhancement tool.",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/react-ssr-enhanced/src/RoutersController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Params,
useRoutes,
createRoutesFromChildren,
Navigate
Navigate,
} from 'react-router-dom';
import { loadInitialProps } from './loadInitialProps';
import { RematchStore, Models } from "@rematch/core"
Expand Down Expand Up @@ -102,7 +102,7 @@ const WithRouters = (props: any) => {
const location = useLocation()
const navigate = useNavigate()
const params = useParams()
return <Controller location={location} navigate={navigate} params={params} {...props} match={{ params, location }} />
return <Controller location={location} navigate={navigate} params={params} {...props} />
}

export default WithRouters

0 comments on commit 692bc0e

Please sign in to comment.