workadventure/front/webpack.config.ts

215 lines
7.4 KiB
TypeScript
Raw Normal View History

2021-06-29 18:39:43 +02:00
import type { Configuration } from "webpack";
2021-05-17 12:20:07 +02:00
import type WebpackDevServer from "webpack-dev-server";
2021-06-29 18:39:43 +02:00
import path from "path";
import webpack from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import sveltePreprocess from "svelte-preprocess";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
2021-06-29 18:39:43 +02:00
import NodePolyfillPlugin from "node-polyfill-webpack-plugin";
2021-06-29 18:39:43 +02:00
const mode = process.env.NODE_ENV ?? "development";
const buildNpmTypingsForApi = !!process.env.BUILD_TYPINGS;
const isProduction = mode === "production";
const isDevelopment = !isProduction;
2021-06-29 18:39:43 +02:00
const entries: { [key: string]: string } = {};
if (!buildNpmTypingsForApi) {
entries.main = "./src/index.ts";
}
entries.iframe_api = "./src/iframe_api.ts";
2020-04-03 14:56:21 +02:00
module.exports = {
2021-06-29 18:39:43 +02:00
entry: entries,
mode: mode,
2021-06-29 18:39:43 +02:00
devtool: isDevelopment ? "inline-source-map" : "source-map",
2020-04-03 14:56:21 +02:00
devServer: {
2021-06-29 18:39:43 +02:00
contentBase: "./dist",
host: "0.0.0.0",
2021-03-31 16:20:21 +02:00
sockPort: 80,
disableHostCheck: true,
historyApiFallback: {
2021-06-29 18:39:43 +02:00
rewrites: [{ from: /^_\/.*$/, to: "/index.html" }],
disableDotRule: true,
},
2020-04-03 14:56:21 +02:00
},
module: {
rules: [
{
test: /\.tsx?$/,
//use: 'ts-loader',
2020-04-03 14:56:21 +02:00
exclude: /node_modules/,
2021-06-29 18:39:43 +02:00
loader: "ts-loader",
options: {
2021-06-29 18:39:43 +02:00
transpileOnly: !buildNpmTypingsForApi,
compilerOptions: {
declaration: buildNpmTypingsForApi,
},
},
2020-04-03 14:56:21 +02:00
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
2021-06-29 18:39:43 +02:00
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
//url: false,
2021-06-29 18:39:43 +02:00
sourceMap: true,
},
},
"sass-loader",
],
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
2021-06-29 18:39:43 +02:00
loader: "css-loader",
options: {
//url: false,
2021-06-29 18:39:43 +02:00
sourceMap: true,
},
},
],
},
2021-05-11 17:37:21 +02:00
{
2021-05-12 15:57:53 +02:00
test: /\.(html|svelte)$/,
2021-05-11 17:37:21 +02:00
exclude: /node_modules/,
use: {
2021-06-29 18:39:43 +02:00
loader: "svelte-loader",
2021-05-11 17:37:21 +02:00
options: {
compilerOptions: {
// Dev mode must be enabled for HMR to work!
2021-06-29 18:39:43 +02:00
dev: isDevelopment,
2021-05-11 17:37:21 +02:00
},
emitCss: isProduction,
hotReload: isDevelopment,
hotOptions: {
// List of options and defaults: https://www.npmjs.com/package/svelte-loader-hot#usage
noPreserveState: false,
optimistic: true,
},
preprocess: sveltePreprocess({
scss: true,
sass: true,
2021-06-01 16:17:36 +02:00
}),
2021-06-29 18:39:43 +02:00
onwarn: function (
warning: { code: string },
handleWarning: (warning: { code: string }) => void
) {
2021-06-01 16:17:36 +02:00
// See https://github.com/sveltejs/svelte/issues/4946#issuecomment-662168782
2021-06-29 18:39:43 +02:00
if (warning.code === "a11y-no-onchange") {
return;
}
if (warning.code === "a11y-autofocus") {
return;
}
if (warning.code === "a11y-media-has-caption") {
return;
}
2021-06-01 16:17:36 +02:00
// process as usual
handleWarning(warning);
2021-06-29 18:39:43 +02:00
},
},
},
2021-05-11 17:37:21 +02:00
},
// Required to prevent errors from Svelte on Webpack 5+, omit on Webpack 4
// See: https://github.com/sveltejs/svelte-loader#usage
{
test: /node_modules\/svelte\/.*\.mjs$/,
resolve: {
2021-06-29 18:39:43 +02:00
fullySpecified: false,
},
2021-05-11 17:37:21 +02:00
},
{
test: /\.(eot|svg|png|gif|jpg)$/,
exclude: /node_modules/,
2021-06-29 18:39:43 +02:00
type: "asset",
},
{
test: /\.(woff(2)?|ttf)$/,
2021-06-29 18:39:43 +02:00
type: "asset",
generator: {
2021-06-29 18:39:43 +02:00
filename: "fonts/[name][ext]",
},
},
2020-04-03 14:56:21 +02:00
],
},
resolve: {
2021-05-12 15:57:53 +02:00
alias: {
2021-06-29 18:39:43 +02:00
svelte: path.resolve("node_modules", "svelte"),
2021-05-12 15:57:53 +02:00
},
2021-06-29 18:39:43 +02:00
extensions: [".tsx", ".ts", ".js", ".svelte"],
mainFields: ["svelte", "browser", "module", "main"],
2020-04-03 14:56:21 +02:00
},
output: {
filename: (pathData) => {
// Add a content hash only for the main bundle.
// We want the iframe_api.js file to keep its name as it will be referenced from outside iframes.
2021-06-29 18:39:43 +02:00
return pathData.chunk?.name === "main" ? "js/[name].[contenthash].js" : "[name].js";
},
2021-06-29 18:39:43 +02:00
path: path.resolve(__dirname, "dist"),
publicPath: "/",
2020-04-03 14:56:21 +02:00
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new ForkTsCheckerWebpackPlugin({
eslint: {
2021-06-29 18:39:43 +02:00
files: "./src/**/*.ts",
},
}),
new MiniCssExtractPlugin({ filename: "[name].[contenthash].css" }),
new HtmlWebpackPlugin({
template: "./dist/index.tmpl.html.tmp",
minify: {
collapseWhitespace: true,
keepClosingSlash: true,
removeComments: false,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
},
chunks: ["main"],
}),
2020-04-03 14:56:21 +02:00
new webpack.ProvidePlugin({
2021-06-29 18:39:43 +02:00
Phaser: "phaser",
}),
2021-05-17 16:30:19 +02:00
new NodePolyfillPlugin(),
2021-03-31 16:20:11 +02:00
new webpack.EnvironmentPlugin({
2021-06-29 18:39:43 +02:00
API_URL: null,
SKIP_RENDER_OPTIMIZATIONS: false,
DISABLE_NOTIFICATIONS: false,
PUSHER_URL: undefined,
UPLOADER_URL: null,
ADMIN_URL: null,
CONTACT_URL: null,
Active authentication Oauth (#1377) * Active authentication Oauth - Google authentication - GitHub authentication - Linkedin authentication Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Finish connexion et get user info connexion Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Fix lint error Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Change the expires token for 30 days Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Update connexion stratgey - Set last room when it will be created and not when connexion is openned - Add '/login' end point permit to logout and open iframe to log user - Add logout feature permit to logout in front Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Implement logout and revoke token with hydra Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Fix pull develop conflict Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Profile url (#1399) * Create function that permit to get profile URL Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Continue profil user Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Add menu and logout button Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Update last room use Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Profile callback permit to get url profile setting from admin Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Finish profile show Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Delete profileUrl will be not use today Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Correct lint Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Update size of iframe Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Delete console log Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Update feedback ARP Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com>
2021-09-05 18:17:49 +02:00
PROFILE_URL: null,
2021-11-10 15:20:04 +01:00
ICON_URL: null,
2021-06-29 18:39:43 +02:00
DEBUG_MODE: null,
STUN_SERVER: null,
TURN_SERVER: null,
TURN_USER: null,
TURN_PASSWORD: null,
JITSI_URL: null,
JITSI_PRIVATE_MODE: null,
START_ROOM_URL: null,
MAX_USERNAME_LENGTH: 8,
MAX_PER_GROUP: 4,
DISPLAY_TERMS_OF_USE: false,
POSTHOG_API_KEY: null,
POSTHOG_URL: null,
NODE_ENV: mode,
DISABLE_ANONYMOUS: false,
OPID_LOGIN_SCREEN_PROVIDER: null,
2021-06-29 18:39:43 +02:00
}),
2020-07-28 11:06:08 +02:00
],
} as Configuration & WebpackDevServer.Configuration;