Skip to content

Commit 2a816ae

Browse files
authored
fix: lodash is commonjs (#50)
1 parent b8c2863 commit 2a816ae

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

.changeset/chilled-terms-judge.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-server-renderer": patch
3+
---
4+
5+
fix: lodash is commonjs

.codesandbox/ci.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"node": "18",
3+
"installCommand": "codesandbox:install",
34
"sandboxes": []
45
}

package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
22
"name": "react-server-renderer",
33
"version": "2.0.1",
4+
"type": "module",
45
"description": "Yet another simple React SSR solution inspired by vue-server-render",
56
"repository": "[email protected]:un-ts/react-server-renderer.git",
67
"author": "JounQin <[email protected]>",
78
"license": "MIT",
8-
"type": "module",
99
"packageManager": "[email protected]",
10+
"engines": {
11+
"node": "^12.20.0 || >=14.13.0"
12+
},
1013
"main": "lib/index.cjs",
1114
"module": "lib/index.js",
12-
"types": "lib/index.d.ts",
1315
"exports": {
1416
".": {
1517
"types": "./lib/index.d.ts",
@@ -20,22 +22,21 @@
2022
"./server-plugin": "./lib/webpack-plugin/server.js",
2123
"./package.json": "./package.json"
2224
},
25+
"types": "lib/index.d.ts",
2326
"files": [
2427
"lib"
2528
],
26-
"engines": {
27-
"node": "^12.20.0 || >=14.13.0"
28-
},
2929
"scripts": {
3030
"build": "run-p 'build:*'",
3131
"build:r": "r -f cjs",
3232
"build:tsc": "tsc",
33+
"codesandbox:install": "yarn --ignore-engines",
3334
"lint": "run-p 'lint:*'",
3435
"lint:es": "eslint . --cache",
3536
"lint:tsc": "tsc --noEmit",
36-
"typecov": "type-coverage",
3737
"prepare": "simple-git-hooks",
38-
"release": "yarn build && clean-pkg-json && changeset publish"
38+
"release": "yarn build && clean-pkg-json && changeset publish",
39+
"typecov": "type-coverage"
3940
},
4041
"peerDependencies": {
4142
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",

src/template-renderer/parse-template.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { template as compile } from 'lodash'
1+
import _ from 'lodash'
22

33
import type { ParsedTemplate } from '../types.js'
44

@@ -32,9 +32,9 @@ export function parseTemplate(
3232
}
3333

3434
return {
35-
head: compile(template.slice(0, i), compileOptions),
36-
neck: compile(template.slice(i, j), compileOptions),
37-
tail: compile(
35+
head: _.template(template.slice(0, i), compileOptions),
36+
neck: _.template(template.slice(i, j), compileOptions),
37+
tail: _.template(
3838
template.slice(j + contentPlaceholder.length),
3939
compileOptions,
4040
),

src/util.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isPlainObject } from 'lodash'
1+
import _ from 'lodash'
22

33
import type { File } from './types.js'
44

@@ -11,7 +11,8 @@ export const isJS = (file: File): boolean =>
1111
export const isCSS = (file: File): boolean =>
1212
/\.css(?:\?[^.]+)?$/.test(getFilename(file))
1313

14-
export const isObjectType = isPlainObject as <T>(
14+
// eslint-disable-next-line @typescript-eslint/unbound-method
15+
export const isObjectType = _.isPlainObject as <T>(
1516
value: unknown,
1617
) => value is T & object
1718

src/webpack-plugin/client.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import hash from 'hash-sum'
2-
import { uniq } from 'lodash'
2+
import _ from 'lodash'
33
import type { Compiler, WebpackPluginInstance, sources } from 'webpack'
44

55
import { getFilename } from '../util.js'
@@ -23,9 +23,9 @@ export class ReactSSRClientPlugin implements WebpackPluginInstance {
2323
onEmit(compiler, 'react-client-plugin', (compilation, cb) => {
2424
const stats = compilation.getStats().toJson()
2525

26-
const allFiles = uniq<string>(stats.assets!.map(a => a.name))
26+
const allFiles = _.uniq<string>(stats.assets!.map(a => a.name))
2727

28-
const initialFiles = uniq(
28+
const initialFiles = _.uniq(
2929
Object.keys(stats.entrypoints!)
3030
.map(name => stats.entrypoints![name].assets!)
3131
.reduce((assets, all) => [...all, ...assets], [])

0 commit comments

Comments
 (0)