@jsenv/plugin-react 0.2.11 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@babel/plugin-transform-react-jsx": "7.18.6",
|
|
28
28
|
"@babel/plugin-transform-react-jsx-development": "7.18.6",
|
|
29
|
-
"@jsenv/ast": "1.
|
|
30
|
-
"@jsenv/plugin-commonjs": "0.
|
|
29
|
+
"@jsenv/ast": "1.2.0",
|
|
30
|
+
"@jsenv/plugin-commonjs": "1.0.0",
|
|
31
31
|
"@jsenv/sourcemap": "1.0.4",
|
|
32
32
|
"@jsenv/url-meta": "7.0.0",
|
|
33
33
|
"react-refresh": "0.14.0"
|
|
@@ -56,18 +56,18 @@ const jsenvPluginJsxAndRefresh = ({
|
|
|
56
56
|
name: "jsenv:jsx_and_refresh",
|
|
57
57
|
appliesDuring: "*",
|
|
58
58
|
transformUrlContent: {
|
|
59
|
-
js_module: async (urlInfo,
|
|
59
|
+
js_module: async (urlInfo, context) => {
|
|
60
60
|
const urlMeta = URL_META.applyAssociations({
|
|
61
61
|
url: urlInfo.url,
|
|
62
62
|
associations,
|
|
63
63
|
})
|
|
64
64
|
const jsxEnabled = urlMeta.jsx
|
|
65
|
-
const refreshEnabled =
|
|
65
|
+
const refreshEnabled = context.scenarios.dev ? urlMeta.refresh : false
|
|
66
66
|
const babelPlugins = [
|
|
67
67
|
...(jsxEnabled
|
|
68
68
|
? [
|
|
69
69
|
[
|
|
70
|
-
|
|
70
|
+
context.scenarios.dev
|
|
71
71
|
? "@babel/plugin-transform-react-jsx-development"
|
|
72
72
|
: "@babel/plugin-transform-react-jsx",
|
|
73
73
|
{
|
|
@@ -103,7 +103,7 @@ const jsenvPluginJsxAndRefresh = ({
|
|
|
103
103
|
let index = code.indexOf(importSpecifier)
|
|
104
104
|
while (index > -1) {
|
|
105
105
|
const specifier = importSpecifier.slice(1, -1)
|
|
106
|
-
const [injectedReference] = referenceUtils.inject({
|
|
106
|
+
const [injectedReference] = context.referenceUtils.inject({
|
|
107
107
|
type: "js_import_export",
|
|
108
108
|
expectedType: "js_module",
|
|
109
109
|
specifier,
|
|
@@ -121,11 +121,13 @@ const jsenvPluginJsxAndRefresh = ({
|
|
|
121
121
|
const hasReg = /\$RefreshReg\$\(/.test(code)
|
|
122
122
|
const hasSig = /\$RefreshSig\$\(/.test(code)
|
|
123
123
|
if (hasReg || hasSig) {
|
|
124
|
-
const [reactRefreshClientReference] = referenceUtils.inject(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
const [reactRefreshClientReference] = context.referenceUtils.inject(
|
|
125
|
+
{
|
|
126
|
+
type: "js_import_export",
|
|
127
|
+
expectedType: "js_module",
|
|
128
|
+
specifier: "@jsenv/plugin-react/src/client/react_refresh.js",
|
|
129
|
+
},
|
|
130
|
+
)
|
|
129
131
|
magicSource.prepend(`import { installReactRefresh } from ${
|
|
130
132
|
reactRefreshClientReference.generatedSpecifier
|
|
131
133
|
}
|
|
@@ -13,7 +13,7 @@ export const jsenvPluginReactRefreshPreamble = () => {
|
|
|
13
13
|
|
|
14
14
|
return {
|
|
15
15
|
name: "jsenv:react_refresh_preamble",
|
|
16
|
-
appliesDuring:
|
|
16
|
+
appliesDuring: "dev",
|
|
17
17
|
transformUrlContent: {
|
|
18
18
|
html: (urlInfo, context) => {
|
|
19
19
|
const htmlAst = parseHtmlString(urlInfo.content)
|
|
@@ -25,11 +25,11 @@ export const jsenvPluginReactRefreshPreamble = () => {
|
|
|
25
25
|
injectScriptNodeAsEarlyAsPossible(
|
|
26
26
|
htmlAst,
|
|
27
27
|
createHtmlNode({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"injected-by": "jsenv:react_refresh_preamble",
|
|
28
|
+
tagName: "script",
|
|
29
|
+
type: "module",
|
|
30
|
+
src: reactRefreshPreambleReference.generatedSpecifier,
|
|
32
31
|
}),
|
|
32
|
+
"jsenv:react_refresh_preamble",
|
|
33
33
|
)
|
|
34
34
|
const htmlModified = stringifyHtmlAst(htmlAst)
|
|
35
35
|
return htmlModified
|