|
|
@ -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,39 +181,49 @@ 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(); |
|
|
|
|
|
|
|
} |
|
|
|
// Webpack 5
|
|
|
|
}); |
|
|
|
// setupMiddlewares: useLocal ? undefined : (middlewares, devServer) => {
|
|
|
|
|
|
|
|
// middlewares.push(middleware);
|
|
|
|
return middlewares; |
|
|
|
|
|
|
|
}, |
|
|
|
// return middlewares;
|
|
|
|
/* public: useLocal ? undefined : domain, |
|
|
|
// },
|
|
|
|
sockHost: useLocal ? undefined : domain, */ |
|
|
|
// 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`, |
|
|
@ -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), |
|
|
|
}; |
|
|
|
}; |
|
|
|