[Dev] Remove unused webpack config vars

This commit is contained in:
Alexander Zinchuk 2022-08-05 19:22:46 +02:00
parent a55b410e6a
commit 6fc3bb2416
2 changed files with 32 additions and 24 deletions

View File

@ -4,12 +4,11 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"dev": "cross-env APP_ENV=development webpack serve --env mode=dev --env isDevServer --mode development --config ./webpack.config.js", "dev": "cross-env APP_ENV=development webpack serve --mode development",
"dev:mocked": "cross-env APP_ENV=test APP_MOCKED_CLIENT=1 webpack serve --env mode=dev --env isDevServer --mode development --config ./webpack.config.js --port 1235", "dev:mocked": "cross-env APP_ENV=test APP_MOCKED_CLIENT=1 webpack serve --mode development --port 1235",
"build": "webpack --mode production", "build:mocked": "cross-env APP_ENV=test APP_MOCKED_CLIENT=1 webpack --mode development",
"build:mocked": "cross-env APP_ENV=test APP_MOCKED_CLIENT=1 webpack --env mode=dev --mode development --config ./webpack.config.js", "build:staging": "APP_ENV=staging APP_VERSION=$(npm run print_version --silent) webpack --mode development && ./deploy/copy_to_dist.sh",
"build:staging": "rm -rf dist/ && APP_ENV=staging APP_VERSION=$(npm run print_version --silent) npm run build && ./deploy/copy_to_dist.sh", "build:production": "npm i && APP_VERSION=$(npm run inc_version --silent) webpack && ./deploy/copy_to_dist.sh",
"build:production": "npm i && rm -rf dist/ && APP_VERSION=$(npm run inc_version --silent) APP_ENV=production npm run build && ./deploy/copy_to_dist.sh",
"deploy:production": "npm run build:production && git add -A && git commit -a -m '[Build]' --no-verify && git push", "deploy:production": "npm run build:production && git add -A && git commit -a -m '[Build]' --no-verify && git push",
"print_version": "node -p -e \"require('./package.json').version\"", "print_version": "node -p -e \"require('./package.json').version\"",
"inc_version": "echo $((`cat .patch-version` + 1)) > .patch-version && echo \"$(node -p -e \"require('./package.json').version.match(/^\\d+\\.\\d+/)[0]\").$(cat .patch-version)\"", "inc_version": "echo $((`cat .patch-version` + 1)) > .patch-version && echo \"$(node -p -e \"require('./package.json').version.match(/^\\d+\\.\\d+/)[0]\").$(cat .patch-version)\"",

View File

@ -15,13 +15,20 @@ const StatoscopeWebpackPlugin = require('@statoscope/webpack-plugin').default;
const WebpackContextExtension = require('./dev/webpackContextExtension'); const WebpackContextExtension = require('./dev/webpackContextExtension');
const appVersion = require('./package.json').version; const appVersion = require('./package.json').version;
const {
HEAD,
APP_ENV = 'production',
APP_MOCKED_CLIENT = '',
} = process.env;
dotenv.config(); dotenv.config();
module.exports = (env = {}, argv = {}) => { module.exports = (_env, { mode = 'production' }) => {
return { return {
mode: argv.mode, mode,
entry: './src/index.tsx', entry: './src/index.tsx',
target: 'web', target: 'web',
devServer: { devServer: {
port: 1234, port: 1234,
host: '0.0.0.0', host: '0.0.0.0',
@ -55,9 +62,11 @@ module.exports = (env = {}, argv = {}) => {
output: { output: {
filename: '[name].[contenthash].js', filename: '[name].[contenthash].js',
chunkFilename: '[id].[chunkhash].js', chunkFilename: '[id].[chunkhash].js',
assetModuleFilename: '[name].[contenthash].[ext]', assetModuleFilename: '[name].[contenthash][ext]',
path: path.resolve(__dirname, argv['output-path'] || 'dist'), path: path.resolve(__dirname, 'dist'),
clean: true,
}, },
module: { module: {
rules: [ rules: [
{ {
@ -88,7 +97,7 @@ module.exports = (env = {}, argv = {}) => {
modules: { modules: {
exportLocalsConvention: 'camelCase', exportLocalsConvention: 'camelCase',
auto: true, auto: true,
localIdentName: argv['optimize-minimize'] ? '[hash:base64]' : '[path][name]__[local]' localIdentName: mode === 'production' ? '[hash:base64]' : '[name]__[local]'
} }
} }
}, },
@ -110,6 +119,7 @@ module.exports = (env = {}, argv = {}) => {
}, },
], ],
}, },
resolve: { resolve: {
extensions: ['.js', '.ts', '.tsx'], extensions: ['.js', '.ts', '.tsx'],
fallback: { fallback: {
@ -119,20 +129,21 @@ module.exports = (env = {}, argv = {}) => {
fs: false, fs: false,
}, },
}, },
plugins: [ plugins: [
// Clearing of the unused files for code highlight for smaller chunk count // Clearing of the unused files for code highlight for smaller chunk count
new ContextReplacementPlugin( new ContextReplacementPlugin(
/highlight\.js\/lib\/languages/, /highlight\.js\/lib\/languages/,
/^((?!\.js\.js).)*$/ /^((?!\.js\.js).)*$/
), ),
...(process.env.APP_MOCKED_CLIENT === '1' ? [new NormalModuleReplacementPlugin( ...(APP_MOCKED_CLIENT === '1' ? [new NormalModuleReplacementPlugin(
/src\/lib\/gramjs\/client\/TelegramClient\.js/, /src\/lib\/gramjs\/client\/TelegramClient\.js/,
'./MockClient.ts' './MockClient.ts'
)] : []), )] : []),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
appName: process.env.APP_ENV === 'production' ? 'Telegram Web' : 'Telegram Web Beta', appName: APP_ENV === 'production' ? 'Telegram Web' : 'Telegram Web Beta',
appleIcon: process.env.APP_ENV === 'production' ? 'apple-touch-icon' : 'apple-touch-icon-dev', appleIcon: APP_ENV === 'production' ? 'apple-touch-icon' : 'apple-touch-icon-dev',
mainIcon: process.env.APP_ENV === 'production' ? 'icon-192x192' : 'icon-dev-192x192', mainIcon: APP_ENV === 'production' ? 'icon-192x192' : 'icon-dev-192x192',
template: 'src/index.html', template: 'src/index.html',
}), }),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
@ -141,8 +152,8 @@ module.exports = (env = {}, argv = {}) => {
ignoreOrder: true, ignoreOrder: true,
}), }),
new EnvironmentPlugin({ new EnvironmentPlugin({
APP_ENV: 'production', APP_ENV,
APP_MOCKED_CLIENT: '', APP_MOCKED_CLIENT,
APP_NAME: null, APP_NAME: null,
APP_VERSION: appVersion, APP_VERSION: appVersion,
TELEGRAM_T_API_ID: undefined, TELEGRAM_T_API_ID: undefined,
@ -152,9 +163,9 @@ module.exports = (env = {}, argv = {}) => {
new DefinePlugin({ new DefinePlugin({
APP_REVISION: DefinePlugin.runtimeValue(() => { APP_REVISION: DefinePlugin.runtimeValue(() => {
const { branch, commit } = getGitMetadata(); const { branch, commit } = getGitMetadata();
const shouldDisplayCommit = process.env.APP_ENV === 'staging' || !branch || branch === 'HEAD'; const shouldDisplayCommit = APP_ENV === 'staging' || !branch || branch === 'HEAD';
return JSON.stringify(shouldDisplayCommit ? commit : branch); return JSON.stringify(shouldDisplayCommit ? commit : branch);
}, argv.mode === 'development' ? true : []), }, mode === 'development' ? true : []),
}), }),
new ProvidePlugin({ new ProvidePlugin({
Buffer: ['buffer', 'Buffer'], Buffer: ['buffer', 'Buffer'],
@ -171,11 +182,9 @@ module.exports = (env = {}, argv = {}) => {
}), }),
], ],
...(!env.noSourceMap && { devtool: 'source-map',
devtool: 'source-map',
}),
...(process.env.APP_ENV !== 'production' && { ...(APP_ENV !== 'production' && {
optimization: { optimization: {
chunkIds: 'named', chunkIds: 'named',
} }
@ -185,7 +194,7 @@ module.exports = (env = {}, argv = {}) => {
function getGitMetadata() { function getGitMetadata() {
const gitRevisionPlugin = new GitRevisionPlugin(); const gitRevisionPlugin = new GitRevisionPlugin();
const branch = process.env.HEAD || gitRevisionPlugin.branch(); const branch = HEAD || gitRevisionPlugin.branch();
const commit = gitRevisionPlugin.commithash().substring(0, 7); const commit = gitRevisionPlugin.commithash().substring(0, 7);
return { branch, commit }; return { branch, commit };
} }