Skip to content

Commit

Permalink
can build the package in prod mode
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed Mar 29, 2024
1 parent 889a17b commit fb377c9
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 37 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jackson-wasm/pkg/*.js
11 changes: 11 additions & 0 deletions jackson-wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions jackson-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["console_error_panic_hook"]

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
js-sys = "0.3.69"
wasm-bindgen="0.2"

console_error_panic_hook = { version = "0.1.7", optional = true }


[dependencies.web-sys]
version = "0.3.69"
Expand Down
1 change: 1 addition & 0 deletions jackson-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod utils;
mod util;
mod default_context_group;

Expand Down
3 changes: 2 additions & 1 deletion jackson-wasm/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::default_context_group::{self, DEFAULT_CONTEXT_GROUP};
use crate::{default_context_group::{self, DEFAULT_CONTEXT_GROUP}, utils};
use js_sys::{Array, Boolean, Object, RegExp};
use wasm_bindgen::prelude::*;

Expand Down Expand Up @@ -198,6 +198,7 @@ pub fn make_metadata_key_with_context(
key: &str,
options: MakeMetadataKeyWithContextOptions,
) -> Result<String, JsValue> {
utils::set_panic_hook();
let reg_exp = RegExp::new(r"^[\w]+$", "");

if let Some(context_group) = &options.contextGroup {
Expand Down
11 changes: 11 additions & 0 deletions jackson-wasm/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"build:dev": "npm run clean && \"./node_modules/.bin/webpack\" --config webpack.dev.js",
"build:prod": "npm run clean && ./node_modules/.bin/webpack --config webpack.prod.js",
"build:win:dev": "npm run clean && \"./node_modules/.bin/webpack\" --config webpack.dev.js",
"build:win:prod": "npm run clean && \"./node_modules/.bin/webpack\" --config webpack.prod.js",
"build:win:prod": "npm run build:rs:prod && npm run clean && \"./node_modules/.bin/webpack\" --config webpack.prod.js",
"build:rs:prod": "cd jackson-wasm && wasm-pack build",
"build:rs:node": "cd jackson-wasm && wasm-pack build --target nodejs",
"start:node:dev": "node dist/lib.node",
Expand Down
36 changes: 3 additions & 33 deletions webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const ESLintPlugin = require('eslint-webpack-plugin');
const webpack = require('webpack');
const path = require('path');

const defaultConfig = {
Expand All @@ -25,39 +24,10 @@ const defaultConfig = {
},
devtool: 'inline-source-map',
mode: 'development',
plugins: [new ESLintPlugin({})]
};

const testConfig = {
watch: true,
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: [/node_modules/],
include: [/src/, /tests/],
use: [
{
loader: 'ts-loader',
options: {
configFile: path.resolve(__dirname, 'tsconfig.json'),
}
}
]
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
devtool: 'inline-source-map',
mode: 'development',
plugins: [new ESLintPlugin({})],
target: 'node',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'test.node.js'
},
experiments: {
asyncWebAssembly: true
}
};

const serverConfig = {
Expand Down
6 changes: 4 additions & 2 deletions webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const ESLintPlugin = require('eslint-webpack-plugin');
const webpack = require('webpack');
const path = require('path');

const defaultConfig = {
Expand All @@ -24,7 +23,10 @@ const defaultConfig = {
},
devtool: 'source-map',
mode: 'production',
plugins: [new ESLintPlugin({})]
plugins: [new ESLintPlugin({})],
experiments: {
asyncWebAssembly: true
}
};

const serverConfig = {
Expand Down

0 comments on commit fb377c9

Please sign in to comment.