@crossbind/plugin-webpack-loader 2.0.0-beta.50
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/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +145 -0
- package/index.js +19 -0
- package/package.json +25 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @crossbind/plugin-webpack-loader
|
|
2
|
+
|
|
3
|
+
## 2.0.0-beta.50
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Aligned on the 2.0.0-beta.50 baseline. No source change; the version exists so every package in
|
|
8
|
+
the workspace names the same release.
|
|
9
|
+
|
|
10
|
+
## 1.0.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- crossbind@1.0.4
|
|
16
|
+
|
|
17
|
+
## 1.0.0
|
|
18
|
+
|
|
19
|
+
### Major Changes
|
|
20
|
+
|
|
21
|
+
- 🚀 first stable release
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
- crossbind@1.0.0
|
|
27
|
+
|
|
28
|
+
## 1.0.0-beta.10
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- chore: add initial version of CHANGELOGS files
|
|
33
|
+
- Updated dependencies
|
|
34
|
+
- crossbind@1.0.0-beta.33
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Buğra Sarı and crossbind contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# @crossbind/plugin-webpack-loader
|
|
2
|
+
**crossbind Webpack loader**
|
|
3
|
+
A tool for seamless C++ integration with the Webpack bundler.
|
|
4
|
+
|
|
5
|
+
<a href="https://www.npmjs.com/package/@crossbind/plugin-webpack-loader">
|
|
6
|
+
<img alt="NPM version" src="https://img.shields.io/npm/v/@crossbind/plugin-webpack-loader?style=for-the-badge" />
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://github.com/crossbind/crossbind/blob/main/LICENSE">
|
|
9
|
+
<img alt="License" src="https://img.shields.io/github/license/crossbind/crossbind?style=for-the-badge" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://crossbind.js.org/docs/guide/integrate-into-existing-project/webpack">
|
|
12
|
+
<img alt="Docs - React Native" src="https://img.shields.io/badge/Docs_-_Webpack-20B2AA?style=for-the-badge" />
|
|
13
|
+
</a>
|
|
14
|
+
|
|
15
|
+
## Integration
|
|
16
|
+
To integrate crossbind into your project using Webpack as a bundler, you can utilize the @crossbind/plugin-webpack-loader plugin. Start by installing these package with the following command:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @crossbind/plugin-webpack @crossbind/plugin-webpack-loader --save-dev
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Webpack**
|
|
23
|
+
To enable the plugin, modify the `webpack.config.js` file as shown below.
|
|
24
|
+
|
|
25
|
+
```diff
|
|
26
|
+
+ const CrossbindWebpackPlugin = require('@crossbind/plugin-webpack');
|
|
27
|
+
+ const crossbindWebpackPlugin = new CrossbindWebpackPlugin();
|
|
28
|
+
+ const compiler = crossbindWebpackPlugin.getCompiler();
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
//...
|
|
32
|
+
plugins: [
|
|
33
|
+
+ crossbindWebpackPlugin,
|
|
34
|
+
],
|
|
35
|
+
module: {
|
|
36
|
+
rules: [
|
|
37
|
+
+ {
|
|
38
|
+
+ test: /\.h$/,
|
|
39
|
+
+ loader: '@crossbind/plugin-webpack-loader',
|
|
40
|
+
+ options: { compiler },
|
|
41
|
+
+ }
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Rspack**
|
|
48
|
+
To enable the plugin, modify the `rspack.config.mjs` file as shown below.
|
|
49
|
+
|
|
50
|
+
```diff
|
|
51
|
+
+ import CrossbindWebpackPlugin from '@crossbind/plugin-webpack';
|
|
52
|
+
|
|
53
|
+
+ const crossbindWebpackPlugin = new CrossbindWebpackPlugin();
|
|
54
|
+
+ const compiler = crossbindWebpackPlugin.getCompiler();
|
|
55
|
+
|
|
56
|
+
export default defineConfig({
|
|
57
|
+
module: {
|
|
58
|
+
rules: [
|
|
59
|
+
+ {
|
|
60
|
+
+ test: /\.h$/,
|
|
61
|
+
+ loader: '@crossbind/plugin-webpack-loader',
|
|
62
|
+
+ options: { compiler },
|
|
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
|
+
+ },
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Craco**
|
|
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
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
async function crossbindLoader() {
|
|
2
|
+
const {
|
|
3
|
+
bridges, createBridgeFile, getCrossbindScript, getRustJsScript, state,
|
|
4
|
+
} = this.getOptions();
|
|
5
|
+
const target = state.targets.find((t) => t.platform === 'wasm');
|
|
6
|
+
|
|
7
|
+
// Rust surfaces need no C++ bridge file: the native bridge is the generated companion
|
|
8
|
+
// crate; this only emits the JS proxy module - the same shape as the .h flow.
|
|
9
|
+
if (this.resourcePath.endsWith('.rs')) {
|
|
10
|
+
return getRustJsScript(target, this.resourcePath);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const bridgeFile = createBridgeFile(this.resourcePath);
|
|
14
|
+
bridges.push(bridgeFile);
|
|
15
|
+
|
|
16
|
+
return getCrossbindScript(target, bridgeFile);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = crossbindLoader;
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@crossbind/plugin-webpack-loader",
|
|
3
|
+
"version": "2.0.0-beta.50",
|
|
4
|
+
"description": "crossbind Webpack loader: A tool for seamless C++ integration with the Webpack bundler.",
|
|
5
|
+
"homepage": "https://github.com/crossbind/crossbind/tree/main/plugins/webpack-loader#readme",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/crossbind/crossbind.git"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "index.js",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"crossbind": "^2.0.0-beta.50"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"webpack": ">=5.109.2"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"crossbind-plugin",
|
|
20
|
+
"webpack",
|
|
21
|
+
"loader",
|
|
22
|
+
"bind",
|
|
23
|
+
"c++"
|
|
24
|
+
]
|
|
25
|
+
}
|