Added observable for web worker communication

This commit is contained in:
squidfunk
2019-12-17 15:59:13 +01:00
parent 862982a69d
commit 4e4e086af7
13 changed files with 208 additions and 61 deletions

View File

@@ -21,28 +21,23 @@
*/
import * as path from "path"
// import { Options } from "ts-loader"
import { Configuration } from "webpack"
/* ----------------------------------------------------------------------------
* Configuration
* Helper functions
* ------------------------------------------------------------------------- */
/**
* Webpack configuration
* Webpack base configuration
*
* @param env - Webpack environment arguments
* @param args - Command-line arguments
*
* @return Webpack configuration
*/
export default (_env: never, args: Configuration) => {
function config(args: Configuration): Configuration {
return {
mode: args.mode,
/* Entrypoint */
entry: ["src/assets/javascripts/index.ts"],
/* Loaders */
module: {
rules: [
@@ -57,45 +52,16 @@ export default (_env: never, args: Configuration) => {
transpileOnly: true,
compilerOptions: {
module: "esnext",
noUnusedLocals: args.mode === "production",
noUnusedParameters: args.mode === "production",
removeComments: false
}
}
}
],
exclude: /\/node_modules\//
},
{
test: /\worker\/(.*?)\.ts$/,
use: [
{ loader: "worker-loader", options: {
inline: true, fallback: false } },
{
loader: "ts-loader",
options: {
transpileOnly: true,
compilerOptions: {
module: "esnext",
noUnusedLocals: args.mode === "production",
noUnusedParameters: args.mode === "production", // TODO: do not duplicate
removeComments: false
}
}
}
]
}
]
},
/* Export class constructor as entrypoint */
output: {
path: path.resolve(__dirname, "material/assets/javascripts"),
filename: "app.js",
libraryTarget: "window"
},
/* Module resolver */
resolve: {
modules: [
@@ -109,3 +75,40 @@ export default (_env: never, args: Configuration) => {
devtool: "source-map"
}
}
/* ----------------------------------------------------------------------------
* Configuration
* ------------------------------------------------------------------------- */
/**
* Webpack configuration
*
* @param env - Webpack environment arguments
* @param args - Command-line arguments
*
* @return Webpack configuration
*/
export default (_env: never, args: Configuration): Configuration[] => ([
/* Application */
{
...config(args),
entry: "src/assets/javascripts",
output: {
path: path.resolve(__dirname, "material/assets/javascripts"),
filename: "bundle.js",
libraryTarget: "window"
}
},
/* Search worker */
{
...config(args),
entry: "src/assets/javascripts/workers/search",
output: {
path: path.resolve(__dirname, "material/assets/javascripts"),
filename: "search.js",
libraryTarget: "var"
}
}
])