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. 58288
      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. 163
      webpack.common.js
  17. 2
      webpack.dev.js
  18. 43
      webpack.prod.js

4
.env

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

2
README.md

@ -21,7 +21,7 @@ Run `npm run build` to build the minimized production version of the app. Copy ` @@ -21,7 +21,7 @@ Run `npm run build` to build the minimized production version of the app. Copy `
### 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))
* [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))

13
keepAsset.js

@ -0,0 +1,13 @@ @@ -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;
}

58288
package-lock.json generated

File diff suppressed because it is too large Load Diff

82
package.json

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

2
postcss.config.js

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

5
src/components/privacySection.ts

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

31
src/helpers/dom/anchorCopy.ts

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

14
src/lib/mtproto/apiManager.ts

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

1
src/lib/mtproto/mtprotoworker.ts

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

3
src/lib/mtproto/networker.ts

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

2
src/scss/partials/_chat.scss

@ -11,7 +11,7 @@ $chat-helper-size: 45px; @@ -11,7 +11,7 @@ $chat-helper-size: 45px;
$chat-input-box-shadow: 0px 1px 8px 1px rgb(0 0 0 / 18%);
$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-total-time: #{$input-transition-time - $background-transition-time};

16
src/scss/partials/_chatBubble.scss

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

2
src/scss/partials/_peerTyping.scss

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

163
webpack.common.js

@ -3,6 +3,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); @@ -3,6 +3,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const MediaQueryPlugin = require('media-query-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const postcssPresetEnv = require('postcss-preset-env');
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
const { RetryChunkLoadPlugin } = require('webpack-retry-chunk-load-plugin');
const fs = require('fs');
const Dotenv = require('dotenv-webpack');
@ -38,6 +39,26 @@ const opts = { @@ -38,6 +39,26 @@ const opts = {
const domain = 'yourdomain.com';
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: {
rules: [
@ -51,21 +72,33 @@ module.exports = { @@ -51,21 +72,33 @@ module.exports = {
reloadAll: true,
}
}, */
{
loader: 'css-loader',
options: {
url: false
}
},
// Webpack 4
'css-loader?url=false',
// Webpack 5
// {
// loader: 'css-loader',
// options: {
// url: false
// }
// },
devMode ? undefined : MediaQueryPlugin.loader,
{
loader: 'postcss-loader',
options: {
postcssOptions: {
// Webpack 4
ident: 'postcss',
plugins: [
postcssPresetEnv(),
]
}
],
// Webpack 5
// postcssOptions: {
// plugins: [
// postcssPresetEnv(),
// ]
// }
}
},
{
@ -74,14 +107,14 @@ module.exports = { @@ -74,14 +107,14 @@ module.exports = {
sourceMap: devMode
}
}
].filter(l => !!l)
].filter(Boolean)
},
{
test: /\.ts?$/,
use: [
//{ loader: 'babel-loader', options: require('./babel.config') },
'ts-loader',
{ loader: 'ifdef-loader', options: opts }
{loader: 'ifdef-loader', options: opts}
],
exclude: /node_modules/,
},
@ -98,10 +131,11 @@ module.exports = { @@ -98,10 +131,11 @@ module.exports = {
extensions: ['.ts', '.js'],
},
entry: {
index: './src/index.ts',
sw: {import: './src/lib/serviceWorker/index.service.ts', filename: 'sw.js'}
},
entry: './src/index.ts',
// entry: {
// index: './src/index.ts',
// sw: {import: './src/lib/serviceWorker/index.service.ts', filename: 'sw.js'}
// },
/* entry: {
index: './src/index.ts',
pluralPolyfill: './src/lib/pluralPolyfill.ts'
@ -113,27 +147,28 @@ module.exports = { @@ -113,27 +147,28 @@ module.exports = {
path: path.resolve(__dirname, 'public'),
filename: '[name].[chunkhash].bundle.js',
chunkFilename: '[name].[chunkhash].chunk.js',
clean: {
keep(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;
}
}
// Webpack 5
// clean: {
// keep: keepAsset,
// }
},
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: {
// directory: path.join(__dirname, 'public')
// },
// hot: false,
compress: true,
http2: useLocalNotLocal ? true : (useLocal ? undefined : true),
https: useLocal ? undefined : {
@ -146,40 +181,50 @@ module.exports = { @@ -146,40 +181,50 @@ module.exports = {
host: useLocalNotLocal ? localIp : (useLocal ? undefined : '0.0.0.0'),
//host: domain, // '0.0.0.0'
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();
}
});
// Webpack 5
// setupMiddlewares: useLocal ? undefined : (middlewares, devServer) => {
// middlewares.push(middleware);
return middlewares;
},
/* public: useLocal ? undefined : domain,
sockHost: useLocal ? undefined : domain, */
// return middlewares;
// },
// client: {
// overlay: true,
// progress: true
// },
},
plugins: [
devMode ? undefined : new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
generateStatsFile: false,
defaultSizes: 'gzip'
}),
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({
filename: `index.html`,
//template: 'public/index_template.html',
@ -235,11 +280,5 @@ module.exports = { @@ -235,11 +280,5 @@ module.exports = {
// if not set - nothing will happen and error will be returned to the chunk loader.
//lastResortScript: "window.location.href='/500.html';",
}),
devMode ? undefined : new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
generateStatsFile: false
}),
].filter(Boolean),
};

2
webpack.dev.js

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

43
webpack.prod.js

@ -1,11 +1,17 @@ @@ -1,11 +1,17 @@
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 keepAsset = require('./keepAsset.js');
//const CompressionPlugin = require("compression-webpack-plugin");
const WebpackOnBuildPlugin = require('on-build-webpack');
//const TerserJSPlugin = require('terser-webpack-plugin');
//const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const fs = require('fs');
const buildDir = __dirname + '/public/';
module.exports = merge(common, {
mode: 'production',
@ -52,5 +58,40 @@ module.exports = merge(common, { @@ -52,5 +58,40 @@ module.exports = merge(common, {
minRatio: 0.8,
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