-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from kwonoj/feat-module-bundle
feat(loadmodule): support bundling wasm binary
- Loading branch information
Showing
18 changed files
with
8,457 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Bundle cld3-asm in frontend javascript | ||
|
||
This example aims for particular configuration to include wasm binary itself into frontend javascript bundles. | ||
In normal cases, it is more recommended to use `moduleInitOption.binaryRemoteEndpoint` to point remote location of wasm binary instead. | ||
Check comments in webpack.config.js for required configurations. |
File renamed without changes.
File renamed without changes.
81 changes: 81 additions & 0 deletions
81
examples/browser/package-lock.json → examples/browser_bundle/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
entry: './index.ts', | ||
output: { | ||
path: path.join(__dirname, 'dist'), | ||
filename: 'index_bundle.js' | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.tsx', '.js'] | ||
}, | ||
mode: 'development', | ||
module: { | ||
/** | ||
* Override default rules to avoid parsing wasm file as module | ||
*/ | ||
defaultRules: [ | ||
{ | ||
type: 'javascript/auto', | ||
resolve: {} | ||
} | ||
], | ||
rules: [ | ||
{ | ||
test: /\.tsx?$/, | ||
loader: 'ts-loader', | ||
exclude: /node_modules/, | ||
options: { | ||
transpileOnly: true, | ||
compilerOptions: { | ||
module: 'esnext', | ||
skipLibCheck: true, | ||
skipDefaultLibCheck: true | ||
} | ||
} | ||
}, | ||
/** | ||
* Bundle wasm binary as dataUri in javascript. | ||
*/ | ||
{ | ||
test: /\.wasm$/, | ||
loader: 'url-loader', | ||
options: { | ||
name: '[name]-[hash].[ext]' | ||
} | ||
} | ||
] | ||
}, | ||
target: 'web', | ||
node: { | ||
fs: 'empty' | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin({ | ||
template: 'index.ejs' | ||
}) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## Bundle cld3-asm in frontend javascript | ||
|
||
This example aims for load wasm binary via remote endpoint using `moduleInitOption.binaryRemoteEndpoint` options. | ||
binaryRemoteEndpoint automatically constructs endpoint file name so `file-loader` sets up output option without hash. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>cld3-asm browser example</title> | ||
</head> | ||
<body> | ||
<p>Open up devtools and check console output</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//tslint:disable:no-console | ||
import { loadModule } from '../../src/index'; | ||
import { enableLogger } from '../../src/util/logger'; | ||
import { runCld } from '../runCld'; | ||
|
||
enableLogger(console.log.bind(console)); | ||
|
||
const runBrowserCld = async () => { | ||
const cldFactory = await loadModule({ | ||
binaryRemoteEndpoint: `http://localhost:8888` | ||
}); | ||
|
||
runCld(cldFactory); | ||
}; | ||
|
||
runBrowserCld(); |
Oops, something went wrong.