From f5b4ac97c06e1b5c9c0493e298034802c7e60ac2 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Sat, 27 Nov 2021 19:20:20 +0700 Subject: [PATCH] Fix webpack build Exclude dev resources from webpack build Signed-off-by: Andrey Sobolev --- dev/prod/src/main-dev.ts | 30 ++++++++++++++++++++++++++++ dev/prod/src/main.ts | 1 - dev/prod/src/platform-dev.ts | 38 ++++++++++++++++++++++++++++++++++++ dev/prod/src/platform.ts | 22 --------------------- dev/prod/webpack.config.js | 3 ++- 5 files changed, 70 insertions(+), 24 deletions(-) create mode 100644 dev/prod/src/main-dev.ts create mode 100644 dev/prod/src/platform-dev.ts diff --git a/dev/prod/src/main-dev.ts b/dev/prod/src/main-dev.ts new file mode 100644 index 0000000000..b069439be2 --- /dev/null +++ b/dev/prod/src/main-dev.ts @@ -0,0 +1,30 @@ +// +// Copyright © 2020, 2021 Anticrm Platform Contributors. +// Copyright © 2021 Hardcore Engineering, Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import { createApp } from '@anticrm/ui' +import { configurePlatform } from './platform' +import { configurePlatformDev, configurePlatformDevServer } from './platform-dev' + +configurePlatform() + +if (process.env.CLIENT_TYPE === 'dev') { + configurePlatformDev() +} +if (process.env.CLIENT_TYPE === 'dev-server') { + configurePlatformDevServer() +} + +createApp(document.body) diff --git a/dev/prod/src/main.ts b/dev/prod/src/main.ts index c5647f645d..6901716185 100644 --- a/dev/prod/src/main.ts +++ b/dev/prod/src/main.ts @@ -18,5 +18,4 @@ import { createApp } from '@anticrm/ui' import { configurePlatform } from './platform' configurePlatform() - createApp(document.body) diff --git a/dev/prod/src/platform-dev.ts b/dev/prod/src/platform-dev.ts new file mode 100644 index 0000000000..f9a5394ce2 --- /dev/null +++ b/dev/prod/src/platform-dev.ts @@ -0,0 +1,38 @@ +// +// Copyright © 2020 Anticrm Platform Contributors. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import { addLocation } from '@anticrm/platform' + +import login from '@anticrm/login' +import { clientId } from '@anticrm/client' +import { serverChunterId } from '@anticrm/server-chunter' +import { serverRecruitId } from '@anticrm/server-recruit' +import { serverViewId } from '@anticrm/server-view' + +import { setMetadata } from '@anticrm/platform' +export function configurePlatformDev() { + setMetadata(login.metadata.OverrideLoginToken, process.env.LOGIN_TOKEN_DEV) + setMetadata(login.metadata.OverrideEndpoint, process.env.LOGIN_ENDPOINT_DEV) + console.log('Use DEV server') + addLocation(clientId, () => import(/* webpackChunkName: "client-dev" */ '@anticrm/dev-client-resources')) + addLocation(serverChunterId, () => import(/* webpackChunkName: "server-chunter" */ '@anticrm/dev-server-chunter-resources')) + addLocation(serverRecruitId, () => import(/* webpackChunkName: "server-recruit" */ '@anticrm/server-recruit-resources')) + addLocation(serverViewId, () => import(/* webpackChunkName: "server-view" */ '@anticrm/server-view-resources')) +} + +export function configurePlatformDevServer() { + console.log('Use Endpoint override:', process.env.LOGIN_ENDPOINT) + setMetadata(login.metadata.OverrideEndpoint, process.env.LOGIN_ENDPOINT) +} diff --git a/dev/prod/src/platform.ts b/dev/prod/src/platform.ts index 05fb77e4da..32d30a91f1 100644 --- a/dev/prod/src/platform.ts +++ b/dev/prod/src/platform.ts @@ -16,7 +16,6 @@ import { addLocation } from '@anticrm/platform' import login, { loginId } from '@anticrm/login' -import { clientId } from '@anticrm/client' import { workbenchId } from '@anticrm/workbench' import { viewId } from '@anticrm/view' import { taskId } from '@anticrm/task' @@ -27,10 +26,6 @@ import { activityId } from '@anticrm/activity' import { settingId } from '@anticrm/setting' import { telegramId } from '@anticrm/telegram' -import { serverChunterId } from '@anticrm/server-chunter' -import { serverRecruitId } from '@anticrm/server-recruit' -import { serverViewId } from '@anticrm/server-view' - import '@anticrm/login-assets' import '@anticrm/task-assets' import '@anticrm/view-assets' @@ -51,23 +46,6 @@ export function configurePlatform() { }) setMetadata(login.metadata.TelegramUrl, process.env.TELEGRAM_URL ?? 'http://localhost:8086') setMetadata(login.metadata.OverrideEndpoint, process.env.LOGIN_ENDPOINT) - - if (process.env.CLIENT_TYPE === 'dev') { - setMetadata(login.metadata.OverrideLoginToken, process.env.LOGIN_TOKEN_DEV) - setMetadata(login.metadata.OverrideEndpoint, process.env.LOGIN_ENDPOINT_DEV) - console.log('Use DEV server') - addLocation(clientId, () => import(/* webpackChunkName: "client-dev" */ '@anticrm/dev-client-resources')) - addLocation(serverChunterId, () => import(/* webpackChunkName: "server-chunter" */ '@anticrm/dev-server-chunter-resources')) - addLocation(serverRecruitId, () => import(/* webpackChunkName: "server-recruit" */ '@anticrm/server-recruit-resources')) - addLocation(serverViewId, () => import(/* webpackChunkName: "server-view" */ '@anticrm/server-view-resources')) - } else { - if (process.env.CLIENT_TYPE === 'dev-server') { - console.log('Use Endpoint override:', process.env.LOGIN_ENDPOINT) - setMetadata(login.metadata.OverrideEndpoint, process.env.LOGIN_ENDPOINT) - } - console.log('Use server') - addLocation(clientId, () => import(/* webpackChunkName: "client" */ '@anticrm/client-resources')) - } addLocation(loginId, () => import(/* webpackChunkName: "login" */ '@anticrm/login-resources')) addLocation(workbenchId, () => import(/* webpackChunkName: "workbench" */ '@anticrm/workbench-resources')) diff --git a/dev/prod/webpack.config.js b/dev/prod/webpack.config.js index 6635ace3fe..e5165b386b 100644 --- a/dev/prod/webpack.config.js +++ b/dev/prod/webpack.config.js @@ -23,12 +23,13 @@ const DefinePlugin = require('webpack').DefinePlugin const mode = process.env.NODE_ENV || 'development' const prod = mode === 'production' const devServer = (process.env.CLIENT_TYPE ?? '') === 'dev-server' +const dev = (process.env.CLIENT_TYPE ?? '') === 'dev' || devServer module.exports = { entry: { bundle: [ '@anticrm/theme/styles/global.scss', - './src/main.ts' + ...(dev ? ['./src/main-dev.ts']: ['./src/main.ts'] ) ] }, resolve: {