Browse Source

Rollback to webpack 4

master
Eduard Kuzmenko 3 years ago
parent
commit
a0d960f463
  1. 4
      .env
  2. 2
      README.md
  3. 13
      keepAsset.js
  4. 51334
      package-lock.json
  5. 82
      package.json
  6. 2
      postcss.config.js
  7. 5
      src/components/privacySection.ts
  8. 31
      src/helpers/dom/anchorCopy.ts
  9. 1
      src/lang.ts
  10. 14
      src/lib/mtproto/apiManager.ts
  11. 1
      src/lib/mtproto/mtprotoworker.ts
  12. 3
      src/lib/mtproto/networker.ts
  13. 2
      src/scss/partials/_chat.scss
  14. 16
      src/scss/partials/_chatBubble.scss
  15. 2
      src/scss/partials/_peerTyping.scss
  16. 169
      webpack.common.js
  17. 2
      webpack.dev.js
  18. 43
      webpack.prod.js

4
.env

@ -1,5 +1,5 @@
API_ID=1025907 API_ID=1025907
API_HASH=452b0359b988148995f22ff0f4229750 API_HASH=452b0359b988148995f22ff0f4229750
VERSION=1.4.0 VERSION=1.4.0
VERSION_FULL=1.4.0 (132) VERSION_FULL=1.4.0 (133)
BUILD=132 BUILD=133

2
README.md

@ -21,7 +21,7 @@ Run `npm run build` to build the minimized production version of the app. Copy `
### Dependencies ### Dependencies
* [leemon](https://github.com/zerobias/leemon) ([MIT License](https://github.com/zerobias/leemon/blob/master/LICENSE)) * [BigInteger.js](https://github.com/peterolson/BigInteger.js) ([Unlicense](https://github.com/peterolson/BigInteger.js/blob/master/LICENSE))
* [pako](https://github.com/nodeca/pako) ([MIT License](https://github.com/nodeca/pako/blob/master/LICENSE)) * [pako](https://github.com/nodeca/pako) ([MIT License](https://github.com/nodeca/pako/blob/master/LICENSE))
* [cryptography](https://github.com/spalt08/cryptography) ([Apache License 2.0](https://github.com/spalt08/cryptography/blob/master/LICENSE)) * [cryptography](https://github.com/spalt08/cryptography) ([Apache License 2.0](https://github.com/spalt08/cryptography/blob/master/LICENSE))
* [emoji-data](https://github.com/iamcal/emoji-data) ([MIT License](https://github.com/iamcal/emoji-data/blob/master/LICENSE)) * [emoji-data](https://github.com/iamcal/emoji-data) ([MIT License](https://github.com/iamcal/emoji-data/blob/master/LICENSE))

13
keepAsset.js

@ -0,0 +1,13 @@
module.exports = function(asset) {
if(asset.includes('.xml')
|| asset.includes('version')
|| asset.includes('assets/')
|| asset.includes('changelogs/')
|| asset.includes('.webmanifest')
|| asset.includes('.wasm')
|| asset.includes('rlottie-wasm')
|| asset.includes('Worker.min.js')
|| asset.includes('recorder.min.js')
|| asset.includes('.hbs')) return true;
return false;
}

51334
package-lock.json generated

File diff suppressed because it is too large Load Diff

82
package.json

@ -20,62 +20,62 @@
"author": "", "author": "",
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"dependencies": { "dependencies": {
"webpack-dev-server": "^4.7.4" "webpack-dev-server": "^3.11.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.17.6", "@babel/cli": "^7.13.16",
"@babel/core": "^7.17.8", "@babel/core": "^7.14.2",
"@babel/plugin-proposal-class-properties": "^7.16.7", "@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-transform-typescript": "^7.16.8", "@babel/plugin-transform-typescript": "^7.13.0",
"@babel/polyfill": "^7.12.1", "@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.16.11", "@babel/preset-env": "^7.14.2",
"@babel/preset-es2015": "^7.0.0-beta.53", "@babel/preset-es2015": "^7.0.0-beta.53",
"@babel/preset-typescript": "^7.16.7", "@babel/preset-typescript": "^7.13.0",
"@cryptography/aes": "^0.1.1", "@cryptography/aes": "^0.1.1",
"@cryptography/sha1": "^0.2.0", "@cryptography/sha1": "^0.2.0",
"@cryptography/sha256": "^0.2.0", "@cryptography/sha256": "^0.2.0",
"@peculiar/webcrypto": "^1.3.2", "@peculiar/webcrypto": "^1.1.7",
"@types/big-integer": "^0.0.31", "@types/big-integer": "^0.0.31",
"@types/chrome": "0.0.180", "@types/chrome": "0.0.139",
"@types/jest": "^27.4.1", "@types/jest": "^26.0.23",
"@types/serviceworker-webpack-plugin": "^1.0.3", "@types/serviceworker-webpack-plugin": "^1.0.2",
"autoprefixer": "^10.4.4", "babel-jest": "^26.6.3",
"babel-jest": "^27.5.1", "babel-loader": "^8.2.2",
"babel-loader": "^8.2.4",
"babel-preset-es2015": "^6.24.1", "babel-preset-es2015": "^6.24.1",
"big-integer": "^1.6.51", "big-integer": "^1.6.51",
"compression": "^1.7.4", "compression": "^1.7.4",
"css-loader": "^6.7.1", "css-loader": "^3.6.0",
"cssnano": "^5.1.5", "dotenv-webpack": "^7.0.3",
"dotenv-webpack": "^7.1.0", "express": "^4.17.1",
"express": "^4.17.3", "fast-png": "^5.0.4",
"fast-png": "^6.1.0",
"handlebars": "^4.7.7", "handlebars": "^4.7.7",
"handlebars-loader": "^1.7.1", "handlebars-loader": "^1.7.1",
"html-webpack-plugin": "^5.5.0", "html-webpack-plugin": "^4.5.2",
"ifdef-loader": "^2.3.2", "ifdef-loader": "^2.3.0",
"jest": "^27.5.1", "jest": "^26.6.3",
"media-query-plugin": "^1.5.0", "media-query-plugin": "^1.4.0",
"mini-css-extract-plugin": "^2.6.0", "mini-css-extract-plugin": "^0.9.0",
"npm": "^8.5.5", "npm": "^7.12.1",
"optimize-css-assets-webpack-plugin": "^6.0.1", "on-build-webpack": "^0.1.0",
"pako": "^2.0.4", "optimize-css-assets-webpack-plugin": "^5.0.4",
"postcss-import": "^14.1.0", "pako": "^2.0.3",
"postcss-loader": "^6.2.1", "postcss": "^8.2.10",
"postcss-preset-env": "^7.4.3", "postcss-loader": "^3.0.0",
"qr-code-styling": "^1.5.0", "postcss-preset-env": "^6.7.0",
"sass": "^1.49.9", "qr-code-styling": "^1.3.4",
"sass-loader": "^12.6.0", "sass": "^1.32.13",
"style-loader": "^3.3.1", "sass-loader": "^8.0.2",
"serviceworker-webpack-plugin": "^1.0.1",
"style-loader": "^1.3.0",
"text-encoding": "^0.7.0", "text-encoding": "^0.7.0",
"ts-jest": "^27.1.4", "ts-jest": "^26.5.6",
"ts-loader": "^9.2.8", "ts-loader": "^8.2.0",
"typescript": "^4.6.3", "typescript": "^4.4.3",
"webpack": "^5.70.0", "webpack": "^4.46.0",
"webpack-bundle-analyzer": "^4.5.0", "webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.9.2", "webpack-cli": "^3.3.12",
"webpack-merge": "^5.8.0", "webpack-merge": "^4.2.2",
"webpack-retry-chunk-load-plugin": "^3.0.0", "webpack-retry-chunk-load-plugin": "^1.5.0",
"worker-loader": "^3.0.8" "worker-loader": "^3.0.8"
} }
} }

2
postcss.config.js

@ -1,5 +1,5 @@
module.exports = { module.exports = {
// parser: 'sugarss', parser: 'sugarss',
plugins: { plugins: {
'postcss-import': {}, 'postcss-import': {},
'postcss-preset-env': {}, 'postcss-preset-env': {},

5
src/components/privacySection.ts

@ -4,6 +4,7 @@
* https://github.com/morethanwords/tweb/blob/master/LICENSE * https://github.com/morethanwords/tweb/blob/master/LICENSE
*/ */
import replaceContent from "../helpers/dom/replaceContent";
import { randomLong } from "../helpers/random"; import { randomLong } from "../helpers/random";
import { InputPrivacyKey, InputPrivacyRule } from "../layer"; import { InputPrivacyKey, InputPrivacyRule } from "../layer";
import appPrivacyManager, { PrivacyType } from "../lib/appManagers/appPrivacyManager"; import appPrivacyManager, { PrivacyType } from "../lib/appManagers/appPrivacyManager";
@ -16,7 +17,7 @@ import { SettingSection, generateSection } from "./sidebarLeft";
import AppAddMembersTab from "./sidebarLeft/tabs/addMembers"; import AppAddMembersTab from "./sidebarLeft/tabs/addMembers";
import { SliderSuperTabEventable } from "./sliderTab"; import { SliderSuperTabEventable } from "./sliderTab";
type PrivacySectionStr = LangPackKey | ''; export type PrivacySectionStr = LangPackKey | '' | HTMLElement;
export default class PrivacySection { export default class PrivacySection {
public radioRows: Map<PrivacyType, Row>; public radioRows: Map<PrivacyType, Row>;
public radioSection: SettingSection; public radioSection: SettingSection;
@ -216,6 +217,8 @@ export default class PrivacySection {
const captionElement = this.radioSection.caption; const captionElement = this.radioSection.caption;
if(!caption) { if(!caption) {
captionElement.innerHTML = ''; captionElement.innerHTML = '';
} else if(caption instanceof HTMLElement) {
replaceContent(captionElement, caption);
} else { } else {
_i18n(captionElement, caption); _i18n(captionElement, caption);
} }

31
src/helpers/dom/anchorCopy.ts

@ -0,0 +1,31 @@
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
import { toastNew } from "../../components/toast";
import { copyTextToClipboard } from "../clipboard";
import { cancelEvent } from "./cancelEvent";
import { attachClickEvent } from "./clickEvent";
export default function anchorCopy(options: Partial<{
// href: string,
mePath: string
}> = {}) {
const anchor = document.createElement('a');
anchor.classList.add('anchor-copy');
if(options.mePath) {
const href = 'https://t.me/' + options.mePath;
anchor.href = anchor.innerText = href;
}
attachClickEvent(anchor, (e) => {
cancelEvent(e);
copyTextToClipboard(anchor.href);
toastNew({langPackKey: 'LinkCopied'});
});
return anchor;
}

1
src/lang.ts

@ -685,6 +685,7 @@ const lang = {
"EditCantEditPermissionsPublic": "This permission is not available in public groups.", "EditCantEditPermissionsPublic": "This permission is not available in public groups.",
"VoipUserMicrophoneIsOff": "%s\'s microphone is off", "VoipUserMicrophoneIsOff": "%s\'s microphone is off",
"VoipUserCameraIsOff": "%s\'s camera is off", "VoipUserCameraIsOff": "%s\'s camera is off",
"PrivacyPhoneInfo4": "This public link opens a chat with you:",
// * macos // * macos
"AccountSettings.Filters": "Chat Folders", "AccountSettings.Filters": "Chat Folders",

14
src/lib/mtproto/apiManager.ts

@ -39,6 +39,7 @@ import rootScope from '../rootScope';
/// #if MTPROTO_AUTO /// #if MTPROTO_AUTO
import transportController from './transports/controller'; import transportController from './transports/controller';
import MTTransport from './transports/transport';
/// #endif /// #endif
/* var networker = apiManager.cachedNetworkers.websocket.upload[2]; /* var networker = apiManager.cachedNetworkers.websocket.upload[2];
@ -205,7 +206,7 @@ export class ApiManager {
this.iterateNetworkers((info) => { this.iterateNetworkers((info) => {
const transportType = this.getTransportType(info.connectionType); const transportType = this.getTransportType(info.connectionType);
const transport = this.chooseServer(info.dcId, info.connectionType, transportType); const transport = this.chooseServer(info.dcId, info.connectionType, transportType);
info.networker.changeTransport(transport); this.changeNetworkerTransport(info.networker, transport);
}); });
} }
@ -397,13 +398,22 @@ export class ApiManager {
throw error; throw error;
} }
networker.changeTransport(transport); this.changeNetworkerTransport(networker, transport);
networkers.unshift(networker); networkers.unshift(networker);
this.setOnDrainIfNeeded(networker); this.setOnDrainIfNeeded(networker);
return networker; return networker;
}); });
} }
private changeNetworkerTransport(networker: MTPNetworker, transport: MTTransport) {
const oldTransport = networker.transport;
if(oldTransport) {
DcConfigurator.removeTransport(dcConfigurator.chosenServers, oldTransport);
}
networker.changeTransport(transport);
}
public setOnDrainIfNeeded(networker: MTPNetworker) { public setOnDrainIfNeeded(networker: MTPNetworker) {
if(networker.onDrain) { if(networker.onDrain) {
return; return;

1
src/lib/mtproto/mtprotoworker.ts

@ -374,6 +374,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
// return; // return;
const worker = new MTProtoWorker(); const worker = new MTProtoWorker();
// const worker = new Worker(new URL('./mtproto.worker.ts', import.meta.url));
//const worker = window; //const worker = window;
worker.addEventListener('message', this.onWorkerFirstMessage.bind(this, worker), {once: true}); worker.addEventListener('message', this.onWorkerFirstMessage.bind(this, worker), {once: true});
worker.addEventListener('message', this.onWorkerMessage); worker.addEventListener('message', this.onWorkerMessage);

3
src/lib/mtproto/networker.ts

@ -33,7 +33,6 @@ import type TcpObfuscated from './transports/tcpObfuscated';
import bigInt from 'big-integer'; import bigInt from 'big-integer';
import { ConnectionStatus } from './connectionStatus'; import { ConnectionStatus } from './connectionStatus';
import ctx from '../../environment/ctx'; import ctx from '../../environment/ctx';
import dcConfigurator, { DcConfigurator } from './dcConfigurator';
import bufferConcats from '../../helpers/bytes/bufferConcats'; import bufferConcats from '../../helpers/bytes/bufferConcats';
import bytesCmp from '../../helpers/bytes/bytesCmp'; import bytesCmp from '../../helpers/bytes/bytesCmp';
import bytesToHex from '../../helpers/bytes/bytesToHex'; import bytesToHex from '../../helpers/bytes/bytesToHex';
@ -371,8 +370,6 @@ export default class MTPNetworker {
if(oldTransport) { if(oldTransport) {
oldTransport.destroy(); oldTransport.destroy();
DcConfigurator.removeTransport(dcConfigurator.chosenServers, this.transport);
if(this.nextReqTimeout) { if(this.nextReqTimeout) {
clearTimeout(this.nextReqTimeout); clearTimeout(this.nextReqTimeout);
this.nextReqTimeout = 0; this.nextReqTimeout = 0;

2
src/scss/partials/_chat.scss

@ -11,7 +11,7 @@ $chat-helper-size: 45px;
$chat-input-box-shadow: 0px 1px 8px 1px rgb(0 0 0 / 18%); $chat-input-box-shadow: 0px 1px 8px 1px rgb(0 0 0 / 18%);
$input-transition-time: .2s; $input-transition-time: .2s;
$input-half-transition-time: math.div($input-transition-time, 2); $input-half-transition-time: $input-transition-time / 2;
$background-transition-time: 0.05s; $background-transition-time: 0.05s;
$background-transition-total-time: #{$input-transition-time - $background-transition-time}; $background-transition-total-time: #{$input-transition-time - $background-transition-time};

16
src/scss/partials/_chatBubble.scss

@ -105,8 +105,8 @@ $bubble-beside-button-width: 38px;
left: -50%; left: -50%;
/* top: 0; /* top: 0;
bottom: 0; */ bottom: 0; */
top: -#{math.div($bubble-margin, 2)}; top: -#{$bubble-margin / 2};
bottom: -#{math.div($bubble-margin, 2)}; bottom: -#{$bubble-margin / 2};
content: " "; content: " ";
z-index: -1; z-index: -1;
} }
@ -114,13 +114,13 @@ $bubble-beside-button-width: 38px;
/* &.is-highlighted, &.is-selected { /* &.is-highlighted, &.is-selected {
&:not(.is-group-last):after { &:not(.is-group-last):after {
height: calc(100% + #{math.div($bubble-margin, 2)}) !important; height: calc(100% + #{$bubble-margin / 2}) !important;
} }
& + &:not(.is-group-last) { & + &:not(.is-group-last) {
&:after { &:after {
top: .125rem !important; top: .125rem !important;
height: calc(100% - #{math.div($bubble-margin, 2)}) !important; height: calc(100% - #{$bubble-margin / 2}) !important;
} }
} }
} */ } */
@ -128,7 +128,7 @@ $bubble-beside-button-width: 38px;
// ! if turn this on, there will be an empty space // ! if turn this on, there will be an empty space
/* &.is-highlighted, &.is-selected { /* &.is-highlighted, &.is-selected {
&.is-group-last:after { &.is-group-last:after {
bottom: #{math.div($bubble-margin, 2)} !important; bottom: #{$bubble-margin / 2} !important;
} }
} */ } */
@ -164,7 +164,7 @@ $bubble-beside-button-width: 38px;
&.is-highlighted, &.is-selected { &.is-highlighted, &.is-selected {
&:after { &:after {
top: calc(#{math.div($bubble-margin, 2)} + 30px); top: calc(#{$bubble-margin / 2} + 30px);
} }
} }
} }
@ -1549,7 +1549,7 @@ $bubble-beside-button-width: 38px;
&:first-of-type { &:first-of-type {
.document-selection { .document-selection {
top: -#{math.div($bubble-margin, 2)}; // * padding inner + half padding outer top: -#{$bubble-margin / 2}; // * padding inner + half padding outer
} }
.document-wrapper { .document-wrapper {
@ -1561,7 +1561,7 @@ $bubble-beside-button-width: 38px;
&:last-of-type { &:last-of-type {
.document-selection { .document-selection {
bottom: -#{math.div($bubble-margin, 2)}; bottom: -#{$bubble-margin / 2};
} }
.document-wrapper { .document-wrapper {

2
src/scss/partials/_peerTyping.scss

@ -137,7 +137,7 @@
} }
$scale-max: 1; $scale-max: 1;
$scale-step: math.div(1, 6); $scale-step: 1 / 6;
$scale-mid: $scale-max - $scale-step; $scale-mid: $scale-max - $scale-step;
$scale-min: $scale-max - ($scale-step * 2); $scale-min: $scale-max - ($scale-step * 2);
$opacity-max: 1; $opacity-max: 1;

169
webpack.common.js

@ -3,6 +3,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const MediaQueryPlugin = require('media-query-plugin'); const MediaQueryPlugin = require('media-query-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const postcssPresetEnv = require('postcss-preset-env'); const postcssPresetEnv = require('postcss-preset-env');
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
const { RetryChunkLoadPlugin } = require('webpack-retry-chunk-load-plugin'); const { RetryChunkLoadPlugin } = require('webpack-retry-chunk-load-plugin');
const fs = require('fs'); const fs = require('fs');
const Dotenv = require('dotenv-webpack'); const Dotenv = require('dotenv-webpack');
@ -38,6 +39,26 @@ const opts = {
const domain = 'yourdomain.com'; const domain = 'yourdomain.com';
const localIp = '192.168.93.183'; const localIp = '192.168.93.183';
const middleware = (req, res, next) => {
let IP = '';
if(req.headers['cf-connecting-ip']) {
IP = req.headers['cf-connecting-ip'];
} else {
IP = req.connection.remoteAddress.split(':').pop();
}
if(!allowedIPs.includes(IP) && !/^192\.168\.\d{1,3}\.\d{1,3}$/.test(IP)) {
console.log('Bad IP connecting: ' + IP, req.url);
res.status(404).send('Nothing interesting here.');
} else {
if(req.url.indexOf('/assets/') !== 0) {
console.log(req.url, IP);
}
next();
}
};
module.exports = { module.exports = {
module: { module: {
rules: [ rules: [
@ -51,21 +72,33 @@ module.exports = {
reloadAll: true, reloadAll: true,
} }
}, */ }, */
{
loader: 'css-loader', // Webpack 4
options: { 'css-loader?url=false',
url: false // Webpack 5
} // {
}, // loader: 'css-loader',
// options: {
// url: false
// }
// },
devMode ? undefined : MediaQueryPlugin.loader, devMode ? undefined : MediaQueryPlugin.loader,
{ {
loader: 'postcss-loader', loader: 'postcss-loader',
options: { options: {
postcssOptions: { // Webpack 4
plugins: [ ident: 'postcss',
postcssPresetEnv(), plugins: [
] postcssPresetEnv(),
} ],
// Webpack 5
// postcssOptions: {
// plugins: [
// postcssPresetEnv(),
// ]
// }
} }
}, },
{ {
@ -74,14 +107,14 @@ module.exports = {
sourceMap: devMode sourceMap: devMode
} }
} }
].filter(l => !!l) ].filter(Boolean)
}, },
{ {
test: /\.ts?$/, test: /\.ts?$/,
use: [ use: [
//{ loader: 'babel-loader', options: require('./babel.config') }, //{ loader: 'babel-loader', options: require('./babel.config') },
'ts-loader', 'ts-loader',
{ loader: 'ifdef-loader', options: opts } {loader: 'ifdef-loader', options: opts}
], ],
exclude: /node_modules/, exclude: /node_modules/,
}, },
@ -98,10 +131,11 @@ module.exports = {
extensions: ['.ts', '.js'], extensions: ['.ts', '.js'],
}, },
entry: { entry: './src/index.ts',
index: './src/index.ts', // entry: {
sw: {import: './src/lib/serviceWorker/index.service.ts', filename: 'sw.js'} // index: './src/index.ts',
}, // sw: {import: './src/lib/serviceWorker/index.service.ts', filename: 'sw.js'}
// },
/* entry: { /* entry: {
index: './src/index.ts', index: './src/index.ts',
pluralPolyfill: './src/lib/pluralPolyfill.ts' pluralPolyfill: './src/lib/pluralPolyfill.ts'
@ -113,27 +147,28 @@ module.exports = {
path: path.resolve(__dirname, 'public'), path: path.resolve(__dirname, 'public'),
filename: '[name].[chunkhash].bundle.js', filename: '[name].[chunkhash].bundle.js',
chunkFilename: '[name].[chunkhash].chunk.js', chunkFilename: '[name].[chunkhash].chunk.js',
clean: {
keep(asset) { // Webpack 5
if(asset.includes('.xml') // clean: {
|| asset.includes('version') // keep: keepAsset,
|| asset.includes('assets/') // }
|| asset.includes('changelogs/')
|| asset.includes('.webmanifest')
|| asset.includes('.wasm')
|| asset.includes('rlottie-wasm')
|| asset.includes('Worker.min.js')
|| asset.includes('recorder.min.js')
|| asset.includes('.hbs')) return true;
return false;
}
}
}, },
devServer: { devServer: {
// Webpack 4 options
contentBase: path.join(__dirname, 'public'),
watchContentBase: true,
before: useLocal ? undefined : function(app, server, compiler) {
app.use(middleware);
},
public: useLocal ? undefined : domain,
sockHost: useLocal ? undefined : domain,
overlay: true,
// static: { // static: {
// directory: path.join(__dirname, 'public') // directory: path.join(__dirname, 'public')
// }, // },
// hot: false,
compress: true, compress: true,
http2: useLocalNotLocal ? true : (useLocal ? undefined : true), http2: useLocalNotLocal ? true : (useLocal ? undefined : true),
https: useLocal ? undefined : { https: useLocal ? undefined : {
@ -146,40 +181,50 @@ module.exports = {
host: useLocalNotLocal ? localIp : (useLocal ? undefined : '0.0.0.0'), host: useLocalNotLocal ? localIp : (useLocal ? undefined : '0.0.0.0'),
//host: domain, // '0.0.0.0' //host: domain, // '0.0.0.0'
port: useLocal ? undefined : 443, port: useLocal ? undefined : 443,
client: {
overlay: true,
progress: true
},
setupMiddlewares: useLocal ? undefined : (middlewares, devServer) => {
middlewares.push((req, res) => {
let IP = '';
if(req.headers['cf-connecting-ip']) {
IP = req.headers['cf-connecting-ip'];
} else {
IP = req.connection.remoteAddress.split(':').pop();
}
if(!allowedIPs.includes(IP) && !/^192\.168\.\d{1,3}\.\d{1,3}$/.test(IP)) {
console.log('Bad IP connecting: ' + IP, req.url);
res.status(404).send('Nothing interesting here.');
} else {
if(req.url.indexOf('/assets/') !== 0) {
console.log(req.url, IP);
}
next();
}
});
return middlewares; // Webpack 5
}, // setupMiddlewares: useLocal ? undefined : (middlewares, devServer) => {
/* public: useLocal ? undefined : domain, // middlewares.push(middleware);
sockHost: useLocal ? undefined : domain, */
// return middlewares;
// },
// client: {
// overlay: true,
// progress: true
// },
}, },
plugins: [ plugins: [
devMode ? undefined : new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
generateStatsFile: false,
defaultSizes: 'gzip'
}),
new Dotenv(), new Dotenv(),
new ServiceWorkerWebpackPlugin({
entry: path.join(__dirname, 'src/lib/serviceWorker/index.service.ts'),
filename: 'sw.js',
//excludes: ['**/*'],
includes: [
'**/*.js',
'**/*.css',
'**/*.json',
'**/*.wasm',
'**/*.mp3',
'**/*.svg',
'**/*.tgs',
'**/*.ico',
'**/*.woff',
'**/*.woff2',
'**/*.ttf',
'**/*.webmanifest'
],
}),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
filename: `index.html`, filename: `index.html`,
//template: 'public/index_template.html', //template: 'public/index_template.html',
@ -235,11 +280,5 @@ module.exports = {
// if not set - nothing will happen and error will be returned to the chunk loader. // if not set - nothing will happen and error will be returned to the chunk loader.
//lastResortScript: "window.location.href='/500.html';", //lastResortScript: "window.location.href='/500.html';",
}), }),
devMode ? undefined : new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
generateStatsFile: false
}),
].filter(Boolean), ].filter(Boolean),
}; };

2
webpack.dev.js

@ -1,7 +1,7 @@
process.env.NODE_ENV = 'development'; process.env.NODE_ENV = 'development';
const webpack = require('webpack'); const webpack = require('webpack');
const {merge} = require('webpack-merge'); const merge = require('webpack-merge');
const common = require('./webpack.common.js'); const common = require('./webpack.common.js');

43
webpack.prod.js

@ -1,11 +1,17 @@
process.env.NODE_ENV = 'production'; process.env.NODE_ENV = 'production';
const {merge} = require('webpack-merge'); const path = require('path');
const merge = require('webpack-merge');
const common = require('./webpack.common.js'); const common = require('./webpack.common.js');
const keepAsset = require('./keepAsset.js');
//const CompressionPlugin = require("compression-webpack-plugin"); //const CompressionPlugin = require("compression-webpack-plugin");
const WebpackOnBuildPlugin = require('on-build-webpack');
//const TerserJSPlugin = require('terser-webpack-plugin'); //const TerserJSPlugin = require('terser-webpack-plugin');
//const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); //const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const fs = require('fs');
const buildDir = __dirname + '/public/';
module.exports = merge(common, { module.exports = merge(common, {
mode: 'production', mode: 'production',
@ -52,5 +58,40 @@ module.exports = merge(common, {
minRatio: 0.8, minRatio: 0.8,
deleteOriginalAssets: false, deleteOriginalAssets: false,
}), */ }), */
new WebpackOnBuildPlugin(function(stats) {
const newlyCreatedAssets = stats.compilation.assets;
const unlinked = [];
fs.readdir(path.resolve(buildDir), (err, files) => {
files.forEach(file => {
//console.log('to unlink 1:', file);
if(keepAsset(file)) {
return;
}
// if(file.includes('.xml')
// || file.includes('.webmanifest')
// || file.includes('.wasm')
// || file.includes('rlottie-wasm')
// || file.includes('Worker.min.js')
// || file.includes('recorder.min.js')
// || file.includes('.hbs')) return;
let p = path.resolve(buildDir + file);
if(!newlyCreatedAssets[file] && ['.gz', '.js', '.ts', '.map', '.css', '.txt'].find(ext => file.endsWith(ext)) !== undefined) {
//console.log('to unlink 2:', file);
fs.unlinkSync(p);
unlinked.push(file);
}
});
if(unlinked.length > 0) {
console.log('Removed old assets: ', unlinked);
}
});
})
] ]
}); });

Loading…
Cancel
Save