@crossbind/plugin-webpack 2.0.0-beta.63 → 2.0.0-beta.64
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/README.md +16 -97
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,19 +13,18 @@ A tool for seamless C++ integration with the Webpack bundler.
|
|
|
13
13
|
</a>
|
|
14
14
|
|
|
15
15
|
## Integration
|
|
16
|
-
|
|
16
|
+
Install the plugin and its loader:
|
|
17
17
|
|
|
18
18
|
```sh
|
|
19
19
|
npm install @crossbind/plugin-webpack@beta @crossbind/plugin-webpack-loader@beta --save-dev
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
**Webpack**
|
|
23
|
-
|
|
23
|
+
Register the plugin, its loader rule and its dev server settings in `webpack.config.js`:
|
|
24
24
|
|
|
25
25
|
```diff
|
|
26
|
-
+ const CrossbindWebpackPlugin = require('@crossbind/plugin-webpack');
|
|
26
|
+
+ const CrossbindWebpackPlugin = require('@crossbind/plugin-webpack').default;
|
|
27
27
|
+ const crossbindWebpackPlugin = new CrossbindWebpackPlugin();
|
|
28
|
-
+ const compiler = crossbindWebpackPlugin.getCompiler();
|
|
29
28
|
|
|
30
29
|
module.exports = {
|
|
31
30
|
//...
|
|
@@ -34,112 +33,32 @@ module.exports = {
|
|
|
34
33
|
],
|
|
35
34
|
module: {
|
|
36
35
|
rules: [
|
|
37
|
-
+
|
|
38
|
-
+ test: /\.h$/,
|
|
39
|
-
+ loader: '@crossbind/plugin-webpack-loader',
|
|
40
|
-
+ options: { compiler },
|
|
41
|
-
+ }
|
|
36
|
+
+ crossbindWebpackPlugin.getRule(),
|
|
42
37
|
],
|
|
43
38
|
},
|
|
39
|
+
+ devServer: crossbindWebpackPlugin.getDevServerConfig(),
|
|
44
40
|
};
|
|
45
41
|
```
|
|
46
42
|
|
|
47
43
|
**Rspack**
|
|
48
|
-
|
|
44
|
+
The same plugin works in `rspack.config.mjs`:
|
|
49
45
|
|
|
50
46
|
```diff
|
|
51
47
|
+ import CrossbindWebpackPlugin from '@crossbind/plugin-webpack';
|
|
52
48
|
|
|
53
49
|
+ const crossbindWebpackPlugin = new CrossbindWebpackPlugin();
|
|
54
|
-
+ const compiler = crossbindWebpackPlugin.getCompiler();
|
|
55
50
|
|
|
56
51
|
export default defineConfig({
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
+
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
+
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
plugins: [
|
|
67
|
-
+ crossbindWebpackPlugin,
|
|
68
|
-
].filter(Boolean),
|
|
69
|
-
+ devServer: {
|
|
70
|
-
+ watchFiles: compiler.config.paths.native,
|
|
71
|
-
+ setupMiddlewares: (middlewares, devServer) => {
|
|
72
|
-
+ if (!devServer) {
|
|
73
|
-
+ throw new Error('@rspack/dev-server is not defined');
|
|
74
|
-
+ }
|
|
75
|
-
+
|
|
76
|
-
+ middlewares.unshift({
|
|
77
|
-
+ name: '/crossbind.js',
|
|
78
|
-
+ path: '/crossbind.js',
|
|
79
|
-
+ middleware: (req, res) => {
|
|
80
|
-
+ res.sendFile(`${compiler.config.paths.temp}/${compiler.config.general.name}.browser.js`);
|
|
81
|
-
+ },
|
|
82
|
-
+ });
|
|
83
|
-
+ middlewares.unshift({
|
|
84
|
-
+ name: '/crossbind.wasm',
|
|
85
|
-
+ path: '/crossbind.wasm',
|
|
86
|
-
+ middleware: (req, res) => {
|
|
87
|
-
+ res.send(fs.readFileSync(`${compiler.config.paths.temp}/${compiler.config.general.name}.wasm`));
|
|
88
|
-
+ },
|
|
89
|
-
+ });
|
|
90
|
-
+
|
|
91
|
-
+ return middlewares;
|
|
92
|
-
+ },
|
|
93
|
-
+ },
|
|
52
|
+
module: {
|
|
53
|
+
rules: [
|
|
54
|
+
+ crossbindWebpackPlugin.getRule(),
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
plugins: [
|
|
58
|
+
+ crossbindWebpackPlugin,
|
|
59
|
+
],
|
|
60
|
+
+ devServer: crossbindWebpackPlugin.getDevServerConfig(),
|
|
94
61
|
});
|
|
95
62
|
```
|
|
96
63
|
|
|
97
|
-
|
|
98
|
-
To enable the plugin, create the `craco.config.js` file as shown below.
|
|
99
|
-
|
|
100
|
-
```js
|
|
101
|
-
const fs = require('fs');
|
|
102
|
-
|
|
103
|
-
module.exports = async function () {
|
|
104
|
-
const { default: CrossbindWebpackPlugin } = await import('@crossbind/plugin-webpack');
|
|
105
|
-
const crossbindWebpackPlugin = new CrossbindWebpackPlugin();
|
|
106
|
-
const compiler = crossbindWebpackPlugin.getCompiler();
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
webpack: {
|
|
110
|
-
plugins: {
|
|
111
|
-
add: [crossbindWebpackPlugin],
|
|
112
|
-
},
|
|
113
|
-
configure: (config) => {
|
|
114
|
-
config.module.rules[1].oneOf = [
|
|
115
|
-
{
|
|
116
|
-
test: /\.h$/,
|
|
117
|
-
loader: '@crossbind/plugin-webpack-loader',
|
|
118
|
-
options: { compiler },
|
|
119
|
-
},
|
|
120
|
-
...config.module.rules[1].oneOf,
|
|
121
|
-
];
|
|
122
|
-
return config;
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
devServer: (devServerConfig) => {
|
|
126
|
-
devServerConfig.watchFiles = compiler.config.paths.native;
|
|
127
|
-
devServerConfig.onBeforeSetupMiddleware = (devServer) => {
|
|
128
|
-
if (!devServer) {
|
|
129
|
-
throw new Error('webpack-dev-server is not defined');
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
devServer.app.get('/crossbind.js', function (req, res) {
|
|
133
|
-
res.sendFile(`${compiler.config.paths.temp}/${compiler.config.general.name}.browser.js`);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
devServer.app.get('/crossbind.wasm', function (req, res) {
|
|
137
|
-
res.send(fs.readFileSync(`${compiler.config.paths.temp}/${compiler.config.general.name}.wasm`));
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
return devServerConfig;
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
```
|
|
64
|
+
`getRule()` sends header and Rust imports to the loader, and `getDevServerConfig()` serves the build with the COOP/COEP headers a multithreaded build needs. To keep a `devServer` of your own, spread `getDevServerConfig()` into it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crossbind/plugin-webpack",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.64",
|
|
4
4
|
"description": "crossbind Webpack plugin: A tool for seamless C++ integration with the Webpack bundler.",
|
|
5
5
|
"homepage": "https://github.com/crossbind/crossbind/tree/main/plugins/webpack#readme",
|
|
6
6
|
"repository": {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "index.js",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"crossbind": "^2.0.0-beta.
|
|
15
|
-
"@crossbind/core-embind-rust": "^2.0.0-beta.
|
|
14
|
+
"crossbind": "^2.0.0-beta.64",
|
|
15
|
+
"@crossbind/core-embind-rust": "^2.0.0-beta.64"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"webpack": ">=5.0.0"
|