mmelodies/webpack.config.js

98 lines
2.0 KiB
JavaScript

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const WorkboxPlugin = require("workbox-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
module.exports = (env) => {
return {
mode: "development",
entry: {
controller: "./src/controller/controller.ts",
display: "./src/display/display.ts",
index: "./src/index.ts",
},
output: {
filename: "[name]_[chunkhash].js",
path: path.resolve(__dirname, "dist"),
clean: true,
},
plugins: [
new HtmlWebpackPlugin({
template: "src/controller/index.html",
filename: "controller/index.html",
chunks: ["controller"],
}),
new HtmlWebpackPlugin({
template: "src/display/index.html",
filename: "display/index.html",
chunks: ["display"],
}),
new HtmlWebpackPlugin({
template: "src/index.html",
filename: "index.html",
chunks: ["index"],
}),
new HtmlWebpackPlugin({
template: "src/baby/index.html",
filename: "baby/index.html",
chunks: [],
}),
new WorkboxPlugin.GenerateSW({
// these options encourage the ServiceWorkers to get in there fast
// and not allow any straggling "old" SWs to hang around
clientsClaim: true,
skipWaiting: true,
}),
new CopyPlugin({
patterns: ["public"],
}),
],
devServer: {
proxy: {
"/api": {
target: "ws://localhost:8001",
ws: true, // important
},
},
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-typescript"],
},
},
},
{
test: /\.proto$/,
use: {
loader: "protobufjs-loader",
options: {
paths: ["proto"],
pbjsArgs: ["--no-encode"],
pbts: {},
target: "json-module",
},
},
},
],
},
};
};