@crossbind/plugin-webpack-loader 2.0.0-beta.62 → 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.
Files changed (3) hide show
  1. package/README.md +20 -101
  2. package/index.js +5 -2
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -3,29 +3,28 @@
3
3
  A tool for seamless C++ integration with the Webpack bundler.
4
4
 
5
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" />
6
+ <img alt="NPM version" src="https://img.shields.io/npm/v/@crossbind/plugin-webpack-loader/beta?style=for-the-badge" />
7
7
  </a>
8
8
  <a href="https://github.com/crossbind/crossbind/blob/main/LICENSE">
9
9
  <img alt="License" src="https://img.shields.io/github/license/crossbind/crossbind?style=for-the-badge" />
10
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" />
11
+ <a href="https://crossbind.dev/docs/guide/integrate-into-existing-project/webpack">
12
+ <img alt="Docs - Webpack" src="https://img.shields.io/badge/Docs_-_Webpack-20B2AA?style=for-the-badge" />
13
13
  </a>
14
14
 
15
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:
16
+ Install the plugin and its loader:
17
17
 
18
18
  ```sh
19
- npm install @crossbind/plugin-webpack @crossbind/plugin-webpack-loader --save-dev
19
+ npm install @crossbind/plugin-webpack@beta @crossbind/plugin-webpack-loader@beta --save-dev
20
20
  ```
21
21
 
22
22
  **Webpack**
23
- To enable the plugin, modify the `webpack.config.js` file as shown below.
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
- To enable the plugin, modify the `rspack.config.mjs` file as shown below.
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
- 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
- + },
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
- **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
- ```
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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  async function crossbindLoader() {
2
2
  const {
3
- bridges, createBridgeFile, getCrossbindScript, getRustJsScript, state,
3
+ bridges, appSourceFiles, createBridgeFile, getCrossbindScript, getRustJsScript, state,
4
4
  } = this.getOptions();
5
5
  const target = state.targets.find((t) => t.platform === 'wasm');
6
6
 
@@ -11,7 +11,10 @@ async function crossbindLoader() {
11
11
  }
12
12
 
13
13
  const bridgeFile = createBridgeFile(this.resourcePath);
14
- bridges.push(bridgeFile);
14
+ // A header loads again after each source edit; a repeated entry would change the bridge lib's fingerprint.
15
+ if (!bridges.includes(bridgeFile)) bridges.push(bridgeFile);
16
+ // The names the app imports decide what a header binds, so watch mode loads it again after any source edit.
17
+ appSourceFiles(state.config.paths.project).forEach((file) => this.addDependency(file));
15
18
 
16
19
  return getCrossbindScript(target, bridgeFile);
17
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossbind/plugin-webpack-loader",
3
- "version": "2.0.0-beta.62",
3
+ "version": "2.0.0-beta.64",
4
4
  "description": "crossbind Webpack loader: A tool for seamless C++ integration with the Webpack bundler.",
5
5
  "homepage": "https://github.com/crossbind/crossbind/tree/main/plugins/webpack-loader#readme",
6
6
  "repository": {
@@ -10,7 +10,7 @@
10
10
  "license": "MIT",
11
11
  "main": "index.js",
12
12
  "dependencies": {
13
- "crossbind": "^2.0.0-beta.62"
13
+ "crossbind": "^2.0.0-beta.64"
14
14
  },
15
15
  "peerDependencies": {
16
16
  "webpack": ">=5.0.0"