mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 14:12:13 +00:00
Change flag to --no-modules
This commit is contained in:
parent
ee1e3abd45
commit
8c935d5d94
@ -47,7 +47,7 @@ impl<'a> Context<'a> {
|
|||||||
let contents = contents.trim();
|
let contents = contents.trim();
|
||||||
let global = if self.config.nodejs {
|
let global = if self.config.nodejs {
|
||||||
format!("module.exports.{} = {};\n", name, contents)
|
format!("module.exports.{} = {};\n", name, contents)
|
||||||
} else if self.config.amd {
|
} else if self.config.no_modules {
|
||||||
format!("__exports.{} = {}\n", name, contents)
|
format!("__exports.{} = {}\n", name, contents)
|
||||||
} else {
|
} else {
|
||||||
if contents.starts_with("function") {
|
if contents.starts_with("function") {
|
||||||
@ -229,7 +229,7 @@ impl<'a> Context<'a> {
|
|||||||
self.footer.push_str(&format!("wasm = require('./{}_bg');",
|
self.footer.push_str(&format!("wasm = require('./{}_bg');",
|
||||||
module_name));
|
module_name));
|
||||||
format!("var wasm;")
|
format!("var wasm;")
|
||||||
} else if self.config.amd {
|
} else if self.config.no_modules {
|
||||||
format!("
|
format!("
|
||||||
return fetch('{module}_bg.wasm')
|
return fetch('{module}_bg.wasm')
|
||||||
.then(response => response.arrayBuffer())
|
.then(response => response.arrayBuffer())
|
||||||
@ -247,7 +247,7 @@ impl<'a> Context<'a> {
|
|||||||
format!("import * as wasm from './{}_bg';", module_name)
|
format!("import * as wasm from './{}_bg';", module_name)
|
||||||
};
|
};
|
||||||
|
|
||||||
let js = if self.config.amd {
|
let js = if self.config.no_modules {
|
||||||
format!("
|
format!("
|
||||||
(function (root, factory) {{
|
(function (root, factory) {{
|
||||||
if (typeof define === 'function' && define.amd) {{
|
if (typeof define === 'function' && define.amd) {{
|
||||||
@ -695,7 +695,7 @@ impl<'a> Context<'a> {
|
|||||||
self.globals.push_str(&format!("
|
self.globals.push_str(&format!("
|
||||||
const TextEncoder = require('util').TextEncoder;
|
const TextEncoder = require('util').TextEncoder;
|
||||||
"));
|
"));
|
||||||
} else if !(self.config.browser || self.config.amd) {
|
} else if !(self.config.browser || self.config.no_modules) {
|
||||||
self.globals.push_str(&format!("
|
self.globals.push_str(&format!("
|
||||||
const TextEncoder = typeof window === 'object' && window.TextEncoder
|
const TextEncoder = typeof window === 'object' && window.TextEncoder
|
||||||
? window.TextEncoder
|
? window.TextEncoder
|
||||||
@ -715,7 +715,7 @@ impl<'a> Context<'a> {
|
|||||||
self.globals.push_str(&format!("
|
self.globals.push_str(&format!("
|
||||||
const TextDecoder = require('util').TextDecoder;
|
const TextDecoder = require('util').TextDecoder;
|
||||||
"));
|
"));
|
||||||
} else if !(self.config.browser || self.config.amd) {
|
} else if !(self.config.browser || self.config.no_modules) {
|
||||||
self.globals.push_str(&format!("
|
self.globals.push_str(&format!("
|
||||||
const TextDecoder = typeof window === 'object' && window.TextDecoder
|
const TextDecoder = typeof window === 'object' && window.TextDecoder
|
||||||
? window.TextDecoder
|
? window.TextDecoder
|
||||||
|
@ -17,7 +17,7 @@ pub struct Bindgen {
|
|||||||
path: Option<PathBuf>,
|
path: Option<PathBuf>,
|
||||||
nodejs: bool,
|
nodejs: bool,
|
||||||
browser: bool,
|
browser: bool,
|
||||||
amd: bool,
|
no_modules: bool,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
typescript: bool,
|
typescript: bool,
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ impl Bindgen {
|
|||||||
path: None,
|
path: None,
|
||||||
nodejs: false,
|
nodejs: false,
|
||||||
browser: false,
|
browser: false,
|
||||||
amd: false,
|
no_modules: false,
|
||||||
debug: false,
|
debug: false,
|
||||||
typescript: false,
|
typescript: false,
|
||||||
}
|
}
|
||||||
@ -58,8 +58,8 @@ impl Bindgen {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn amd(&mut self, amd: bool) -> &mut Bindgen {
|
pub fn no_modules(&mut self, no_modules: bool) -> &mut Bindgen {
|
||||||
self.amd = amd;
|
self.no_modules = no_modules;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ Options:
|
|||||||
--out-dir DIR Output directory
|
--out-dir DIR Output directory
|
||||||
--nodejs Generate output that only works in node.js
|
--nodejs Generate output that only works in node.js
|
||||||
--browser Generate output that only works in a browser
|
--browser Generate output that only works in a browser
|
||||||
--amd Generate output that only works in a browser
|
--no-modules Generate output that only works in a browser (without modules)
|
||||||
--typescript Output a TypeScript definition file
|
--typescript Output a TypeScript definition file
|
||||||
--debug Include otherwise-extraneous debug checks in output
|
--debug Include otherwise-extraneous debug checks in output
|
||||||
-V --version Print the version number of wasm-bindgen
|
-V --version Print the version number of wasm-bindgen
|
||||||
@ -32,7 +32,7 @@ Options:
|
|||||||
struct Args {
|
struct Args {
|
||||||
flag_nodejs: bool,
|
flag_nodejs: bool,
|
||||||
flag_browser: bool,
|
flag_browser: bool,
|
||||||
flag_amd: bool,
|
flag_no_modules: bool,
|
||||||
flag_typescript: bool,
|
flag_typescript: bool,
|
||||||
flag_out_dir: Option<PathBuf>,
|
flag_out_dir: Option<PathBuf>,
|
||||||
flag_debug: bool,
|
flag_debug: bool,
|
||||||
@ -59,7 +59,7 @@ fn main() {
|
|||||||
b.input_path(&input)
|
b.input_path(&input)
|
||||||
.nodejs(args.flag_nodejs)
|
.nodejs(args.flag_nodejs)
|
||||||
.browser(args.flag_browser)
|
.browser(args.flag_browser)
|
||||||
.amd(args.flag_amd)
|
.no_modules(args.flag_no_modules)
|
||||||
.debug(args.flag_debug)
|
.debug(args.flag_debug)
|
||||||
.typescript(args.flag_typescript);
|
.typescript(args.flag_typescript);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user