Skip to content

Commit f451cba

Browse files
committedMay 14, 2020
update the new version of yew 0.16 and extend the bundle to fix breaking with the new version of wasm-bindgen
1 parent 9b8e4d0 commit f451cba

16 files changed

+1637
-1729
lines changed
 

‎.travis.yml

-21
This file was deleted.

‎app/cargo-module.d.ts

-4
This file was deleted.

‎app/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
import 'prismjs/themes/prism.css';
2-
import 'prismjs/components/prism-markup';
3-
import 'prismjs/components/prism-rust';
4-
import module from '../crate/Cargo.toml';
5-
6-
module.run();
2+
import 'prismjs';
3+
import 'prismjs/components/prism-rust';

‎crate/Cargo.lock

+7-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crate/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ serde = "1.0"
1919
serde_derive = "1.0"
2020
dotenv = "0.15"
2121
failure = "0.1"
22-
yew = { version = "0.15", features = ["toml", "yaml", "msgpack", "cbor", "web_sys"]}
22+
yew = { version = "0.16", features = ["toml", "yaml", "msgpack", "cbor", "web_sys"]}
2323
web-sys = "0.3"
2424
yew_prism= {path="./yew_prism"}

‎crate/yew_prism/Cargo.lock

+14-45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crate/yew_prism/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ readme = "README.md"
1717
crate-type = ["cdylib", "rlib"]
1818

1919
[dependencies]
20-
yew = { version = "0.15", features = ["toml", "yaml", "msgpack", "cbor", "web_sys"]}
20+
yew = { version="0.16", features = ["toml", "yaml", "msgpack", "cbor", "web_sys"]}
2121
wasm-bindgen="0.2"
22-
web-sys={version="0.3"}
23-
wasm-bindgen-test = "0.3"
22+
web-sys={version="0.3", features=["Document", "HtmlCollection", "NodeList"]}

‎crate/yew_prism/src/prism.rs

-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::prism_sys::{highlight, languages as lang};
2-
use wasm_bindgen_test::*;
32
use web_sys::HtmlElement;
43
use yew::prelude::*;
54

@@ -60,28 +59,3 @@ impl Component for Prism {
6059
}
6160
}
6261
}
63-
64-
wasm_bindgen_test_configure!(run_in_browser);
65-
66-
#[wasm_bindgen_test]
67-
fn shoud_create_prism_component() {
68-
let props_prism = Props {
69-
code: "let greeting: &str = \"Hello World\";".to_string(),
70-
language: "rust".to_string(),
71-
};
72-
73-
let link = ComponentLink::new();
74-
75-
let prism = Prism::create(props_prism, link);
76-
77-
let prism_vnode = prism.render();
78-
let code_ref = NodeRef::default();
79-
80-
let vnode_expected = html! {
81-
<pre>
82-
<code class="language-rust", ref=code_ref/>
83-
</pre>
84-
};
85-
86-
assert_eq!(prism_vnode, vnode_expected);
87-
}

‎crate/yew_prism/src/prism_sys.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use wasm_bindgen::prelude::*;
22

3-
#[wasm_bindgen(module = "prismjs")]
3+
#[wasm_bindgen]
44
extern "C" {
55
pub type Language;
6+
#[wasm_bindgen(js_namespace = Prism)]
67
pub static languages: Language;
78

89
#[wasm_bindgen(method, structural, indexing_getter)]
910
pub fn get(this: &Language, prop: String) -> Language;
1011

12+
#[wasm_bindgen(js_namespace = Prism)]
1113
pub fn highlight(code: String, lang: Language) -> String;
1214
}

‎crate/yew_prism/webdriver.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"browserName": "firefox",
3+
"browserVersion": "76",
4+
"moz:firefoxOptions": {
5+
"log": {"level": "trace"}
6+
}
7+
}

‎index.html

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33
<head>
44
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
55
<title>Yew Prism</title>
6-
<script src="app/index.ts"></script>
76
</head>
87
<body>
8+
<script src="app/index.ts"></script>
9+
<script type="module">
10+
import init, { run } from './yew_parcel.js';
11+
12+
const start = async() => {
13+
await init('./yew_parcel_bg.wasm');
14+
run();
15+
};
16+
17+
start();
18+
</script>
919
</body>
1020
</html>

‎package-lock.json

+1,517-1,575
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+16-9
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@
33
"repository": {
44
"url": "https://github.com/spielrs/yew-parcel-template"
55
},
6-
"name": "yew-prism",
7-
"version": "0.2.1",
8-
"license": "Apache-2.0/MIT",
6+
"name": "create-yew-parcel",
7+
"version": "0.15.0",
8+
"license": "MIT",
99
"scripts": {
10-
"start": "parcel index.html",
11-
"build": "parcel build index.html"
10+
"start": "node wasm-builder.js",
11+
"build": "node wasm-builder.js production",
12+
"debug": "NODE_ENV=dev node --nolazy --inspect-brk=9229 wasm-builder.js"
1213
},
1314
"bin": {
1415
"create-yew-parcel": ".bin/create-yew-parcel.js"
1516
},
1617
"devDependencies": {
18+
"chokidar": "^3.4.0",
19+
"dotenv": "^8.2.0",
1720
"parcel-bundler": "^1.12.4",
18-
"parcel-plugin-wasm.rs": "^1.2.15",
19-
"minimist": "1.2.5",
20-
"kind-of": "6.0.3",
21-
"typescript": "^3.8.3"
21+
"parcel-plugin-static-files-copy": "^2.3.1",
22+
"sass": "^1.26.5",
23+
"typescript": "^3.8.3",
24+
"yew-styles": "0.2.0"
2225
},
2326
"dependencies": {
2427
"prismjs": "^1.20.0"
28+
},
29+
"staticFiles": {
30+
"staticPath": "./crate/pkg",
31+
"watcherGlob": false
2532
}
2633
}

‎wasm-builder.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { execSync } = require('child_process');
2+
const Bundler = require('parcel-bundler');
3+
const Path = require('path');
4+
const chokidar = require('chokidar');
5+
const dotenv = require('dotenv');
6+
dotenv.config();
7+
8+
const entryFiles = [Path.join(__dirname, 'index.html')];
9+
10+
const buildType = process.argv[2];
11+
12+
const options = {
13+
outDir: './dist',
14+
outFile: 'index.html',
15+
publicUrl: '/',
16+
watch: true,
17+
minify: buildType === 'production',
18+
};
19+
20+
(async () => {
21+
const bundler = new Bundler(entryFiles, options);
22+
23+
chokidar.watch(['./crate/src', './crate/Cargo.toml', './crate/yew_prism/src', './crate/yew_prism/src']).on('change', async (event, path) => {
24+
console.log(`there are new changes in '${path}'. Start to rebuild rustwasm sources`);
25+
26+
bundler.bundle();
27+
28+
bundler.hmr.broadcast({
29+
type: 'reload'
30+
});
31+
});
32+
33+
bundler.on('buildStart', () => {
34+
const prevtBuildFile = Path.join(__dirname, './wasm_pack_cmd');
35+
console.log(`running: ${prevtBuildFile}`);
36+
execSync(`${prevtBuildFile} ${buildType === 'production' ? '' : '--dev'}`, {stdio: 'inherit'});
37+
});
38+
39+
await bundler.serve(process.env.SERVER_ADDRESS || 1234);
40+
})();
41+

‎wasm_pack_cmd

172 KB
Binary file not shown.

‎wasm_pack_cmd.v

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
3+
4+
fn main() {
5+
build_type := if os.args.len >= 2 {
6+
os.args[1]
7+
} else {
8+
""
9+
}
10+
11+
code := os.system('wasm-pack build $build_type --target web crate')
12+
13+
if code != 0 {
14+
println('error in wasm-pack execution')
15+
}
16+
}

0 commit comments

Comments
 (0)
Please sign in to comment.