@cpp.js/plugin-webpack 1.0.2 → 2.0.0-beta.12
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/index.js +34 -7
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import { state, createLib, buildWasm, createBridgeFile, getData, getCppJsScript } from 'cpp.js';
|
|
3
|
+
import { state, createLib, buildWasm, createBridgeFile, getData, getCppJsScript, getTargetParams, getFilteredBuildTargets } from 'cpp.js';
|
|
4
|
+
|
|
5
|
+
const targetParams = getTargetParams({ platform: ['wasm'], arch: ['wasm32'], runtime: ['st'], runtimeEnv: ['browser'] }, true);
|
|
6
|
+
let buildTargetRelease = getFilteredBuildTargets(targetParams, { buildType: 'release' })?.[0];
|
|
7
|
+
let buildTargetDebug = getFilteredBuildTargets(targetParams, { buildType: 'debug' })?.[0];
|
|
8
|
+
|
|
9
|
+
if (!buildTargetRelease && !buildTargetDebug) {
|
|
10
|
+
throw new Error('No build targets found');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!buildTargetDebug) {
|
|
14
|
+
buildTargetDebug = buildTargetRelease;
|
|
15
|
+
} else if (!buildTargetRelease) {
|
|
16
|
+
buildTargetRelease = buildTargetDebug;
|
|
17
|
+
}
|
|
4
18
|
|
|
5
19
|
export default class CppjsWebpackPlugin {
|
|
6
20
|
static defaultOptions = {};
|
|
@@ -23,12 +37,23 @@ export default class CppjsWebpackPlugin {
|
|
|
23
37
|
|
|
24
38
|
async onDone({ compilation }) {
|
|
25
39
|
const isDev = compilation.options.mode === 'development';
|
|
26
|
-
|
|
27
|
-
createLib(
|
|
28
|
-
|
|
40
|
+
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);
|
|
29
44
|
if (!isDev) {
|
|
30
|
-
|
|
31
|
-
fs.copyFileSync(`${state.config.paths.build}/${
|
|
45
|
+
const output = state.config.paths.output === state.config.paths.build ? compilation.options.output.path : state.config.paths.output;
|
|
46
|
+
fs.copyFileSync(`${state.config.paths.build}/${buildTarget.jsName}`, `${output}/cpp.js`);
|
|
47
|
+
fs.copyFileSync(`${state.config.paths.build}/${buildTarget.wasmName}`, `${output}/cpp.wasm`);
|
|
48
|
+
|
|
49
|
+
const dataFilePath = `${state.config.paths.build}/${buildTarget.dataTxtName}`;
|
|
50
|
+
if (fs.existsSync(dataFilePath)) {
|
|
51
|
+
fs.copyFileSync(dataFilePath, `${output}/cpp.data.txt`);
|
|
52
|
+
}
|
|
53
|
+
/* const workerFilePath = `${state.config.paths.build}/${state.config.general.name}.js`;
|
|
54
|
+
if (fs.existsSync(workerFilePath)) {
|
|
55
|
+
fs.copyFileSync(workerFilePath, `${output}/cpp.worker.js`);
|
|
56
|
+
} */
|
|
32
57
|
}
|
|
33
58
|
}
|
|
34
59
|
|
|
@@ -39,6 +64,8 @@ export default class CppjsWebpackPlugin {
|
|
|
39
64
|
getData,
|
|
40
65
|
state,
|
|
41
66
|
getCppJsScript,
|
|
67
|
+
getTargetParams,
|
|
68
|
+
getFilteredBuildTargets
|
|
42
69
|
};
|
|
43
70
|
}
|
|
44
71
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cpp.js/plugin-webpack",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.12",
|
|
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": "^
|
|
11
|
+
"cpp.js": "^2.0.0-beta.12"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"cpp.js-plugin",
|