@rsbuild/plugin-preact 1.0.3 → 1.1.1
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/dist/index.cjs +126 -28
- package/dist/index.d.ts +19 -2
- package/dist/index.js +56 -19
- package/package.json +10 -3
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"@rspack/plugin-preact-refresh": function(module1) {
|
|
4
|
+
module1.exports = require("@rspack/plugin-preact-refresh");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
/************************************************************************/ // The module cache
|
|
8
|
+
var __webpack_module_cache__ = {};
|
|
9
|
+
// The require function
|
|
10
|
+
function __webpack_require__(moduleId) {
|
|
11
|
+
// Check if module is in cache
|
|
12
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
+
// Create a new module (and put it into the cache)
|
|
15
|
+
var module1 = __webpack_module_cache__[moduleId] = {
|
|
16
|
+
exports: {}
|
|
17
|
+
};
|
|
18
|
+
// Execute the module function
|
|
19
|
+
__webpack_modules__[moduleId](module1, module1.exports, __webpack_require__);
|
|
20
|
+
// Return the exports of the module
|
|
21
|
+
return module1.exports;
|
|
22
|
+
}
|
|
23
|
+
/************************************************************************/ // webpack/runtime/create_fake_namespace_object
|
|
24
|
+
(()=>{
|
|
25
|
+
var getProto = Object.getPrototypeOf ? function(obj) {
|
|
26
|
+
return Object.getPrototypeOf(obj);
|
|
27
|
+
} : function(obj) {
|
|
28
|
+
return obj.__proto__;
|
|
29
|
+
};
|
|
30
|
+
var leafPrototypes;
|
|
31
|
+
// create a fake namespace object
|
|
32
|
+
// mode & 1: value is a module id, require it
|
|
33
|
+
// mode & 2: merge all properties of value into the ns
|
|
34
|
+
// mode & 4: return value when already ns object
|
|
35
|
+
// mode & 16: return value when it's Promise-like
|
|
36
|
+
// mode & 8|1: behave like require
|
|
37
|
+
__webpack_require__.t = function(value, mode) {
|
|
38
|
+
if (1 & mode) value = this(value);
|
|
39
|
+
if (8 & mode) return value;
|
|
40
|
+
if ('object' == typeof value && value) {
|
|
41
|
+
if (4 & mode && value.__esModule) return value;
|
|
42
|
+
if (16 & mode && 'function' == typeof value.then) return value;
|
|
43
|
+
}
|
|
44
|
+
var ns = Object.create(null);
|
|
45
|
+
__webpack_require__.r(ns);
|
|
46
|
+
var def = {};
|
|
47
|
+
leafPrototypes = leafPrototypes || [
|
|
48
|
+
null,
|
|
49
|
+
getProto({}),
|
|
50
|
+
getProto([]),
|
|
51
|
+
getProto(getProto)
|
|
52
|
+
];
|
|
53
|
+
for(var current = 2 & mode && value; 'object' == typeof current && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach(function(key) {
|
|
54
|
+
def[key] = function() {
|
|
55
|
+
return value[key];
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
def['default'] = function() {
|
|
59
|
+
return value;
|
|
60
|
+
};
|
|
61
|
+
__webpack_require__.d(ns, def);
|
|
62
|
+
return ns;
|
|
63
|
+
};
|
|
64
|
+
})();
|
|
65
|
+
// webpack/runtime/define_property_getters
|
|
5
66
|
(()=>{
|
|
6
67
|
__webpack_require__.d = function(exports1, definition) {
|
|
7
68
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
@@ -29,26 +90,36 @@ var __webpack_require__ = {};
|
|
|
29
90
|
};
|
|
30
91
|
})();
|
|
31
92
|
/************************************************************************/ var __webpack_exports__ = {};
|
|
93
|
+
// ESM COMPAT FLAG
|
|
32
94
|
__webpack_require__.r(__webpack_exports__);
|
|
95
|
+
// EXPORTS
|
|
33
96
|
__webpack_require__.d(__webpack_exports__, {
|
|
34
|
-
PLUGIN_PREACT_NAME:
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
pluginPreact: function() {
|
|
38
|
-
return pluginPreact;
|
|
39
|
-
}
|
|
97
|
+
PLUGIN_PREACT_NAME: ()=>/* binding */ PLUGIN_PREACT_NAME,
|
|
98
|
+
pluginPreact: ()=>/* binding */ pluginPreact
|
|
40
99
|
});
|
|
100
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
101
|
+
const src_require = (0, external_node_module_namespaceObject.createRequire)(/*#__PURE__*/ function() {
|
|
102
|
+
return 'undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
103
|
+
}());
|
|
41
104
|
const PLUGIN_PREACT_NAME = 'rsbuild:preact';
|
|
42
|
-
const pluginPreact =
|
|
43
|
-
let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
|
44
|
-
return {
|
|
105
|
+
const pluginPreact = (userOptions = {})=>({
|
|
45
106
|
name: PLUGIN_PREACT_NAME,
|
|
46
107
|
setup (api) {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
108
|
+
const options = {
|
|
109
|
+
include: /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,
|
|
110
|
+
exclude: /[\\/]node_modules[\\/]/,
|
|
111
|
+
prefreshEnabled: true,
|
|
112
|
+
reactAliasesEnabled: true,
|
|
113
|
+
...userOptions
|
|
114
|
+
};
|
|
115
|
+
// @rspack/plugin-preact-refresh does not support Windows yet
|
|
116
|
+
if ('win32' === process.platform) options.prefreshEnabled = false;
|
|
117
|
+
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
118
|
+
const isDev = 'development' === config.mode;
|
|
119
|
+
const usePrefresh = isDev && options.prefreshEnabled && config.dev.hmr && 'web' === config.output.target;
|
|
50
120
|
const reactOptions = {
|
|
51
|
-
development: 'development' ===
|
|
121
|
+
development: 'development' === config.mode,
|
|
122
|
+
refresh: usePrefresh,
|
|
52
123
|
runtime: 'automatic',
|
|
53
124
|
importSource: 'preact'
|
|
54
125
|
};
|
|
@@ -56,6 +127,14 @@ const pluginPreact = function() {
|
|
|
56
127
|
tools: {
|
|
57
128
|
swc: {
|
|
58
129
|
jsc: {
|
|
130
|
+
experimental: {
|
|
131
|
+
plugins: usePrefresh ? [
|
|
132
|
+
[
|
|
133
|
+
src_require.resolve('@swc/plugin-prefresh'),
|
|
134
|
+
{}
|
|
135
|
+
]
|
|
136
|
+
] : void 0
|
|
137
|
+
},
|
|
59
138
|
parser: {
|
|
60
139
|
syntax: 'typescript',
|
|
61
140
|
// enable supports for JSX/TSX compilation
|
|
@@ -68,20 +147,39 @@ const pluginPreact = function() {
|
|
|
68
147
|
}
|
|
69
148
|
}
|
|
70
149
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
150
|
+
extraConfig.source ||= {};
|
|
151
|
+
if (usePrefresh) // transpile `@prefresh/core` and `@prefresh/utils` to ensure browser compatibility
|
|
152
|
+
extraConfig.source.include = [
|
|
153
|
+
/node_modules[\\/]@prefresh[\\/](core|utils)/
|
|
154
|
+
];
|
|
155
|
+
if (options.reactAliasesEnabled) extraConfig.source.alias = {
|
|
156
|
+
react: 'preact/compat',
|
|
157
|
+
'react-dom/test-utils': 'preact/test-utils',
|
|
158
|
+
'react-dom': 'preact/compat',
|
|
159
|
+
'react/jsx-runtime': 'preact/jsx-runtime'
|
|
160
|
+
};
|
|
161
|
+
return mergeEnvironmentConfig(extraConfig, config);
|
|
162
|
+
});
|
|
163
|
+
api.modifyBundlerChain(async (chain, { isDev, target })=>{
|
|
164
|
+
const config = api.getNormalizedConfig();
|
|
165
|
+
const usePrefresh = isDev && options.prefreshEnabled && config.dev.hmr && 'web' === target;
|
|
166
|
+
if (!usePrefresh) return;
|
|
167
|
+
const { default: PreactRefreshPlugin } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "@rspack/plugin-preact-refresh", 23));
|
|
168
|
+
const preactPath = src_require.resolve('preact', {
|
|
169
|
+
paths: [
|
|
170
|
+
api.context.rootPath
|
|
171
|
+
]
|
|
172
|
+
});
|
|
173
|
+
chain.plugin('preact-refresh').use(PreactRefreshPlugin, [
|
|
174
|
+
{
|
|
175
|
+
include: options.include,
|
|
176
|
+
exclude: options.exclude,
|
|
177
|
+
preactPath
|
|
178
|
+
}
|
|
179
|
+
]);
|
|
81
180
|
});
|
|
82
181
|
}
|
|
83
|
-
};
|
|
84
|
-
};
|
|
182
|
+
});
|
|
85
183
|
var __webpack_export_target__ = exports;
|
|
86
184
|
for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
|
|
87
185
|
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
1
|
+
import type { RsbuildPlugin, Rspack } from '@rsbuild/core';
|
|
2
2
|
export type PluginPreactOptions = {
|
|
3
3
|
/**
|
|
4
4
|
* Whether to aliases `react`, `react-dom` to `preact/compat`
|
|
5
5
|
* @default true
|
|
6
6
|
*/
|
|
7
7
|
reactAliasesEnabled?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to inject Prefresh for HMR
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
prefreshEnabled?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Include files to be processed by the `@rspack/plugin-preact-refresh` plugin.
|
|
15
|
+
* The value is the same as the `rule.test` option in Rspack.
|
|
16
|
+
* @default /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
|
|
17
|
+
*/
|
|
18
|
+
include?: Rspack.RuleSetCondition;
|
|
19
|
+
/**
|
|
20
|
+
* Exclude files from being processed by the `@rspack/plugin-preact-refresh` plugin.
|
|
21
|
+
* The value is the same as the `rule.exclude` option in Rspack.
|
|
22
|
+
* @default /[\\/]node_modules[\\/]/
|
|
23
|
+
*/
|
|
24
|
+
exclude?: Rspack.RuleSetCondition;
|
|
8
25
|
};
|
|
9
26
|
export declare const PLUGIN_PREACT_NAME = "rsbuild:preact";
|
|
10
|
-
export declare const pluginPreact: (
|
|
27
|
+
export declare const pluginPreact: (userOptions?: PluginPreactOptions) => RsbuildPlugin;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
|
|
2
|
+
const src_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
|
|
1
3
|
const PLUGIN_PREACT_NAME = 'rsbuild:preact';
|
|
2
|
-
const pluginPreact =
|
|
3
|
-
let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
|
4
|
-
return {
|
|
4
|
+
const pluginPreact = (userOptions = {})=>({
|
|
5
5
|
name: PLUGIN_PREACT_NAME,
|
|
6
6
|
setup (api) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const options = {
|
|
8
|
+
include: /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,
|
|
9
|
+
exclude: /[\\/]node_modules[\\/]/,
|
|
10
|
+
prefreshEnabled: true,
|
|
11
|
+
reactAliasesEnabled: true,
|
|
12
|
+
...userOptions
|
|
13
|
+
};
|
|
14
|
+
// @rspack/plugin-preact-refresh does not support Windows yet
|
|
15
|
+
if ('win32' === process.platform) options.prefreshEnabled = false;
|
|
16
|
+
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
17
|
+
const isDev = 'development' === config.mode;
|
|
18
|
+
const usePrefresh = isDev && options.prefreshEnabled && config.dev.hmr && 'web' === config.output.target;
|
|
10
19
|
const reactOptions = {
|
|
11
|
-
development: 'development' ===
|
|
20
|
+
development: 'development' === config.mode,
|
|
21
|
+
refresh: usePrefresh,
|
|
12
22
|
runtime: 'automatic',
|
|
13
23
|
importSource: 'preact'
|
|
14
24
|
};
|
|
@@ -16,6 +26,14 @@ const pluginPreact = function() {
|
|
|
16
26
|
tools: {
|
|
17
27
|
swc: {
|
|
18
28
|
jsc: {
|
|
29
|
+
experimental: {
|
|
30
|
+
plugins: usePrefresh ? [
|
|
31
|
+
[
|
|
32
|
+
src_require.resolve('@swc/plugin-prefresh'),
|
|
33
|
+
{}
|
|
34
|
+
]
|
|
35
|
+
] : void 0
|
|
36
|
+
},
|
|
19
37
|
parser: {
|
|
20
38
|
syntax: 'typescript',
|
|
21
39
|
// enable supports for JSX/TSX compilation
|
|
@@ -28,18 +46,37 @@ const pluginPreact = function() {
|
|
|
28
46
|
}
|
|
29
47
|
}
|
|
30
48
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
extraConfig.source ||= {};
|
|
50
|
+
if (usePrefresh) // transpile `@prefresh/core` and `@prefresh/utils` to ensure browser compatibility
|
|
51
|
+
extraConfig.source.include = [
|
|
52
|
+
/node_modules[\\/]@prefresh[\\/](core|utils)/
|
|
53
|
+
];
|
|
54
|
+
if (options.reactAliasesEnabled) extraConfig.source.alias = {
|
|
55
|
+
react: 'preact/compat',
|
|
56
|
+
'react-dom/test-utils': 'preact/test-utils',
|
|
57
|
+
'react-dom': 'preact/compat',
|
|
58
|
+
'react/jsx-runtime': 'preact/jsx-runtime'
|
|
59
|
+
};
|
|
60
|
+
return mergeEnvironmentConfig(extraConfig, config);
|
|
61
|
+
});
|
|
62
|
+
api.modifyBundlerChain(async (chain, { isDev, target })=>{
|
|
63
|
+
const config = api.getNormalizedConfig();
|
|
64
|
+
const usePrefresh = isDev && options.prefreshEnabled && config.dev.hmr && 'web' === target;
|
|
65
|
+
if (!usePrefresh) return;
|
|
66
|
+
const { default: PreactRefreshPlugin } = await import("@rspack/plugin-preact-refresh");
|
|
67
|
+
const preactPath = src_require.resolve('preact', {
|
|
68
|
+
paths: [
|
|
69
|
+
api.context.rootPath
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
chain.plugin('preact-refresh').use(PreactRefreshPlugin, [
|
|
73
|
+
{
|
|
74
|
+
include: options.include,
|
|
75
|
+
exclude: options.exclude,
|
|
76
|
+
preactPath
|
|
77
|
+
}
|
|
78
|
+
]);
|
|
41
79
|
});
|
|
42
80
|
}
|
|
43
|
-
};
|
|
44
|
-
};
|
|
81
|
+
});
|
|
45
82
|
export { PLUGIN_PREACT_NAME, pluginPreact };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-preact",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Preact plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,13 +21,20 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@prefresh/core": "^1.5.2",
|
|
26
|
+
"@prefresh/utils": "^1.2.0",
|
|
27
|
+
"@rspack/plugin-preact-refresh": "^1.1.0",
|
|
28
|
+
"@swc/plugin-prefresh": "^3.0.3"
|
|
29
|
+
},
|
|
24
30
|
"devDependencies": {
|
|
25
31
|
"@types/node": "18.x",
|
|
32
|
+
"preact": "^10.24.3",
|
|
26
33
|
"typescript": "^5.6.3",
|
|
27
|
-
"@rsbuild/core": "1.0.
|
|
34
|
+
"@rsbuild/core": "1.0.19"
|
|
28
35
|
},
|
|
29
36
|
"peerDependencies": {
|
|
30
|
-
"@rsbuild/core": "1.x
|
|
37
|
+
"@rsbuild/core": "1.x"
|
|
31
38
|
},
|
|
32
39
|
"publishConfig": {
|
|
33
40
|
"access": "public",
|