@cpp.js/plugin-webpack 1.0.0-beta.2 → 1.0.0-beta.3

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 +18 -12
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import fs from 'fs';
2
- import p from 'path';
3
- import CppjsCompiler from 'cpp.js';
1
+ /* eslint-disable object-curly-newline */
2
+ import fs from 'node:fs';
3
+ import { state, createLib, buildWasm, createBridgeFile, getData, getCppJsScript } from 'cpp.js';
4
4
 
5
5
  export default class CppjsWebpackPlugin {
6
6
  static defaultOptions = {};
7
7
 
8
8
  constructor(options = {}) {
9
9
  this.options = { ...CppjsWebpackPlugin.defaultOptions, ...options };
10
- this.compiler = new CppjsCompiler();
10
+ this.bridges = [];
11
11
  }
12
12
 
13
13
  apply(compiler) {
@@ -17,22 +17,28 @@ export default class CppjsWebpackPlugin {
17
17
  }
18
18
 
19
19
  afterCompile(compilation, callback) {
20
- this.compiler.config.paths.native.map(file => compilation.contextDependencies.add(file));
20
+ state.config.paths.native.map((file) => compilation.contextDependencies.add(file));
21
21
  callback();
22
22
  }
23
23
 
24
24
  async onDone({ compilation }) {
25
25
  const isDev = compilation.options.mode === 'development';
26
- this.compiler.createBridge();
27
- await this.compiler.createWasm({ cc: ['-O3'] });
26
+ createLib('Emscripten-x86_64', 'Source', { isProd: true, buildSource: true });
27
+ createLib('Emscripten-x86_64', 'Bridge', { isProd: true, buildSource: false, nativeGlob: this.bridges });
28
+ await buildWasm('browser', true);
28
29
  if (!isDev) {
29
- fs.copyFileSync(`${this.compiler.config.paths.temp}/${this.compiler.config.general.name}.browser.js`, `${compilation.options.output.path}/cpp.js`);
30
- fs.copyFileSync(`${this.compiler.config.paths.temp}/${this.compiler.config.general.name}.wasm`, `${compilation.options.output.path}/cpp.wasm`);
31
- fs.rmSync(this.compiler.config.paths.temp, { recursive: true, force: true });
30
+ fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.browser.js`, `${compilation.options.output.path}/cpp.js`);
31
+ fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.wasm`, `${compilation.options.output.path}/cpp.wasm`);
32
32
  }
33
33
  }
34
34
 
35
- getCompiler() {
36
- return this.compiler;
35
+ getLoaderOptions() {
36
+ return {
37
+ bridges: this.bridges,
38
+ createBridgeFile,
39
+ getData,
40
+ state,
41
+ getCppJsScript,
42
+ };
37
43
  }
38
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpp.js/plugin-webpack",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.3",
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": "^1.0.0-beta.7"
11
+ "cpp.js": "1.0.0-beta.26"
12
12
  },
13
13
  "keywords": [
14
14
  "webpack",