2021-05-17 14:49:18 +02:00
|
|
|
import type {Configuration} from "webpack";
|
|
|
|
import type WebpackDevServer from "webpack-dev-server";
|
2021-05-17 14:30:54 +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';
|
2021-05-17 16:09:42 +02:00
|
|
|
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
|
2021-05-17 14:30:54 +02:00
|
|
|
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';
|
2020-04-03 14:56:21 +02:00
|
|
|
|
2021-05-12 11:05:49 +02:00
|
|
|
const mode = process.env.NODE_ENV ?? 'development';
|
|
|
|
const isProduction = mode === 'production';
|
|
|
|
const isDevelopment = !isProduction;
|
|
|
|
|
2020-04-03 14:56:21 +02:00
|
|
|
module.exports = {
|
2021-03-04 19:00:00 +01:00
|
|
|
entry: {
|
|
|
|
'main': './src/index.ts',
|
|
|
|
'iframe_api': './src/iframe_api.ts'
|
|
|
|
},
|
2021-05-12 11:05:49 +02:00
|
|
|
mode: mode,
|
|
|
|
devtool: isDevelopment ? 'inline-source-map' : 'source-map',
|
2020-04-03 14:56:21 +02:00
|
|
|
devServer: {
|
|
|
|
contentBase: './dist',
|
2020-04-03 18:31:11 +02:00
|
|
|
host: '0.0.0.0',
|
2021-04-13 15:21:21 +02:00
|
|
|
sockPort: 443,
|
2020-04-03 18:31:11 +02:00
|
|
|
disableHostCheck: true,
|
2020-05-12 00:07:50 +02:00
|
|
|
historyApiFallback: {
|
|
|
|
rewrites: [
|
|
|
|
{ from: /^_\/.*$/, to: '/index.html' }
|
|
|
|
],
|
|
|
|
disableDotRule: true
|
|
|
|
},
|
2020-04-03 14:56:21 +02:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
2021-05-17 16:09:42 +02:00
|
|
|
//use: 'ts-loader',
|
2020-04-03 14:56:21 +02:00
|
|
|
exclude: /node_modules/,
|
2021-05-17 16:09:42 +02:00
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
|
|
|
transpileOnly: true,
|
|
|
|
},
|
2020-04-03 14:56:21 +02:00
|
|
|
},
|
2021-03-18 12:37:05 +01:00
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
2021-05-17 15:42:12 +02:00
|
|
|
exclude: /node_modules/,
|
2021-05-17 14:30:54 +02:00
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader, {
|
|
|
|
loader: 'css-loader',
|
2021-05-17 15:42:12 +02:00
|
|
|
options: {
|
|
|
|
//url: false,
|
2021-05-17 14:30:54 +02:00
|
|
|
sourceMap: true
|
2021-05-17 15:42:12 +02:00
|
|
|
}
|
2021-05-17 14:30:54 +02:00
|
|
|
}, 'sass-loader'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
2021-05-17 15:42:12 +02:00
|
|
|
exclude: /node_modules/,
|
2021-05-17 14:30:54 +02:00
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
2021-05-17 15:42:12 +02:00
|
|
|
options: {
|
|
|
|
//url: false,
|
2021-05-17 14:30:54 +02:00
|
|
|
sourceMap: true
|
2021-05-17 15:42:12 +02:00
|
|
|
}
|
2021-05-17 14:30:54 +02:00
|
|
|
}
|
|
|
|
]
|
2021-03-18 12:37:05 +01:00
|
|
|
},
|
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: {
|
|
|
|
loader: 'svelte-loader',
|
|
|
|
options: {
|
|
|
|
compilerOptions: {
|
|
|
|
// Dev mode must be enabled for HMR to work!
|
|
|
|
dev: isDevelopment
|
|
|
|
},
|
|
|
|
emitCss: isProduction,
|
|
|
|
hotReload: isDevelopment,
|
|
|
|
hotOptions: {
|
|
|
|
// List of options and defaults: https://www.npmjs.com/package/svelte-loader-hot#usage
|
|
|
|
noPreserveState: false,
|
|
|
|
optimistic: true,
|
|
|
|
},
|
2021-05-17 14:30:54 +02:00
|
|
|
preprocess: sveltePreprocess({
|
|
|
|
scss: true,
|
|
|
|
sass: true,
|
|
|
|
})
|
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: {
|
|
|
|
fullySpecified: false
|
|
|
|
}
|
2021-03-18 12:37:05 +01:00
|
|
|
},
|
2021-05-26 20:31:33 +02:00
|
|
|
{
|
|
|
|
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
outputPath: 'fonts/'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2021-05-17 14:30:54 +02:00
|
|
|
{
|
2021-05-17 15:42:12 +02:00
|
|
|
test: /\.(ttf|eot|svg|png|gif|jpg)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
type: 'asset'
|
2021-05-17 14:30:54 +02:00
|
|
|
}
|
2020-04-03 14:56:21 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
resolve: {
|
2021-05-12 15:57:53 +02:00
|
|
|
alias: {
|
2021-05-11 17:37:21 +02:00
|
|
|
svelte: path.resolve('node_modules', 'svelte')
|
2021-05-12 15:57:53 +02:00
|
|
|
},
|
2021-05-11 17:37:21 +02:00
|
|
|
extensions: [ '.tsx', '.ts', '.js', '.svelte' ],
|
2021-05-12 15:57:53 +02:00
|
|
|
mainFields: ['svelte', 'browser', 'module', 'main']
|
2020-04-03 14:56:21 +02:00
|
|
|
},
|
|
|
|
output: {
|
2021-03-04 19:00:00 +01:00
|
|
|
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-05-12 13:38:32 +02:00
|
|
|
return pathData.chunk?.name === 'main' ? 'js/[name].[contenthash].js': '[name].js';
|
2021-03-04 19:00:00 +01:00
|
|
|
},
|
2020-04-03 14:56:21 +02:00
|
|
|
path: path.resolve(__dirname, 'dist'),
|
2020-05-12 00:07:50 +02:00
|
|
|
publicPath: '/'
|
2020-04-03 14:56:21 +02:00
|
|
|
},
|
|
|
|
plugins: [
|
2021-05-17 14:30:54 +02:00
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
2021-05-17 16:09:42 +02:00
|
|
|
new ForkTsCheckerWebpackPlugin({
|
|
|
|
eslint: {
|
|
|
|
files: './src/**/*.ts'
|
|
|
|
}
|
|
|
|
}),
|
2021-05-17 14:30:54 +02:00
|
|
|
new MiniCssExtractPlugin({filename: '[name].[contenthash].css'}),
|
2020-06-01 11:53:12 +02:00
|
|
|
new HtmlWebpackPlugin(
|
|
|
|
{
|
2021-03-05 10:00:11 +01:00
|
|
|
template: './dist/index.tmpl.html.tmp',
|
2021-02-02 11:19:24 +01:00
|
|
|
minify: {
|
|
|
|
collapseWhitespace: true,
|
|
|
|
keepClosingSlash: true,
|
|
|
|
removeComments: false,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
removeScriptTypeAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true,
|
|
|
|
useShortDoctype: true
|
2021-03-04 19:00:00 +01:00
|
|
|
},
|
|
|
|
chunks: ['main']
|
2020-06-01 11:53:12 +02:00
|
|
|
}
|
|
|
|
),
|
2020-04-03 14:56:21 +02:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
Phaser: 'phaser'
|
2020-04-03 18:31:11 +02:00
|
|
|
}),
|
2021-05-17 16:30:19 +02:00
|
|
|
new NodePolyfillPlugin(),
|
2021-03-31 16:20:11 +02:00
|
|
|
new webpack.EnvironmentPlugin({
|
|
|
|
'API_URL': null,
|
2021-05-17 13:50:31 +02:00
|
|
|
'SKIP_RENDER_OPTIMIZATIONS': false,
|
|
|
|
'DISABLE_NOTIFICATIONS': false,
|
2021-03-31 16:20:11 +02:00
|
|
|
'PUSHER_URL': undefined,
|
|
|
|
'UPLOADER_URL': null,
|
|
|
|
'ADMIN_URL': null,
|
|
|
|
'DEBUG_MODE': null,
|
|
|
|
'STUN_SERVER': null,
|
|
|
|
'TURN_SERVER': null,
|
|
|
|
'TURN_USER': null,
|
|
|
|
'TURN_PASSWORD': null,
|
|
|
|
'JITSI_URL': null,
|
|
|
|
'JITSI_PRIVATE_MODE': null,
|
2021-05-12 10:35:14 +02:00
|
|
|
'START_ROOM_URL': null,
|
|
|
|
'MAX_USERNAME_LENGTH': 8,
|
|
|
|
'MAX_PER_GROUP': 4
|
2021-03-31 16:20:11 +02:00
|
|
|
})
|
2020-07-28 11:06:08 +02:00
|
|
|
],
|
|
|
|
|
2021-05-12 13:38:32 +02:00
|
|
|
} as Configuration & WebpackDevServer.Configuration;
|