@cpp.js/plugin-webpack 2.0.0-beta.12 → 2.0.0-beta.15

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 (2) hide show
  1. package/index.js +62 -4
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  import fs from 'node:fs';
3
- import { state, createLib, buildWasm, createBridgeFile, getData, getCppJsScript, getTargetParams, getFilteredBuildTargets } from 'cpp.js';
3
+ import {
4
+ state, createLib, buildWasm, createBridgeFile, getData, getCppJsScript, getTargetParams, getFilteredBuildTargets, isSourceNewer,
5
+ } from 'cpp.js';
4
6
 
5
7
  const targetParams = getTargetParams({ platform: ['wasm'], arch: ['wasm32'], runtime: ['st'], runtimeEnv: ['browser'] }, true);
6
8
  let buildTargetRelease = getFilteredBuildTargets(targetParams, { buildType: 'release' })?.[0];
@@ -38,9 +40,10 @@ export default class CppjsWebpackPlugin {
38
40
  async onDone({ compilation }) {
39
41
  const isDev = compilation.options.mode === 'development';
40
42
  const buildTarget = isDev ? buildTargetDebug : buildTargetRelease;
41
- createLib(buildTarget, 'Source', { buildSource: true });
42
- createLib(buildTarget, 'Bridge', { buildSource: false, nativeGlob: [`${state.config.paths.cli}/assets/commonBridges.cpp`, ...this.bridges] });
43
- await buildWasm(buildTarget);
43
+ const force = isSourceNewer(buildTarget);
44
+ createLib(buildTarget, 'Source', { force, buildSource: true });
45
+ createLib(buildTarget, 'Bridge', { force, buildSource: false, nativeGlob: [`${state.config.paths.cli}/assets/cpp-runtime/commonBridges.cpp`, ...this.bridges] });
46
+ await buildWasm(buildTarget, { force });
44
47
  if (!isDev) {
45
48
  const output = state.config.paths.output === state.config.paths.build ? compilation.options.output.path : state.config.paths.output;
46
49
  fs.copyFileSync(`${state.config.paths.build}/${buildTarget.jsName}`, `${output}/cpp.js`);
@@ -68,4 +71,59 @@ export default class CppjsWebpackPlugin {
68
71
  getFilteredBuildTargets
69
72
  };
70
73
  }
74
+
75
+ getRule() {
76
+ return {
77
+ test: new RegExp(`\\.(${state.config.ext.header.join('|')})$`),
78
+ loader: '@cpp.js/plugin-webpack-loader',
79
+ options: { ...this.getLoaderOptions() },
80
+ };
81
+ }
82
+
83
+ setDevServerMiddleware(middlewares, devServer) {
84
+ if (!devServer) {
85
+ throw new Error('devServer is not defined');
86
+ }
87
+
88
+ middlewares.unshift({
89
+ name: '/cpp.js',
90
+ path: '/cpp.js',
91
+ middleware: (req, res) => {
92
+ const filePath = `${state.config.paths.build}/${buildTargetDebug.jsName}`;
93
+ res.setHeader('Content-Type', 'application/javascript');
94
+ res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
95
+ res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
96
+ fs.createReadStream(filePath).pipe(res);
97
+ },
98
+ });
99
+
100
+ middlewares.unshift({
101
+ name: '/cpp.wasm',
102
+ path: '/cpp.wasm',
103
+ middleware: (req, res) => {
104
+ const filePath = `${state.config.paths.build}/${buildTargetDebug.wasmName}`;
105
+ res.setHeader('Content-Type', 'application/wasm');
106
+ res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
107
+ res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
108
+ fs.createReadStream(filePath).pipe(res);
109
+ },
110
+ });
111
+
112
+ return middlewares;
113
+ }
114
+
115
+ getDevServerConfig() {
116
+ return {
117
+ watchFiles: state.config.paths.native,
118
+ hot: true,
119
+ liveReload: true,
120
+ headers: {
121
+ 'Cross-Origin-Opener-Policy': 'same-origin',
122
+ 'Cross-Origin-Embedder-Policy': 'require-corp',
123
+ },
124
+ setupMiddlewares: (middlewares, devServer) => {
125
+ return this.setDevServerMiddleware(middlewares, devServer);
126
+ },
127
+ };
128
+ }
71
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpp.js/plugin-webpack",
3
- "version": "2.0.0-beta.12",
3
+ "version": "2.0.0-beta.15",
4
4
  "description": "Cpp.js Webpack plugin: A tool for seamless C++ integration with the Webpack bundler.",
5
5
  "homepage": "https://github.com/bugra9/cpp.js/tree/main/packages/cppjs-plugin-rollup#readme",
6
6
  "repository": "https://github.com/bugra9/cpp.js.git",
@@ -8,7 +8,7 @@
8
8
  "type": "module",
9
9
  "main": "index.js",
10
10
  "dependencies": {
11
- "cpp.js": "^2.0.0-beta.12"
11
+ "cpp.js": "^2.0.0-beta.15"
12
12
  },
13
13
  "keywords": [
14
14
  "cpp.js-plugin",