Skip to content

Commit

Permalink
feat: .env add LOGO_(BLACK|WHITE)_FILENAME can mod default logo
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidZORO committed Jun 4, 2020
1 parent bc3965d commit 4978e30
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 20 deletions.
6 changes: 6 additions & 0 deletions packages/leaa-dashboard/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# for PROJECT
SITE_NAME=Leaa
API_URL=http://localhost:5555
API_VERSION=v1

# PATH in /public/assets/images/logo/*
LOGO_BLACK_FILENAME=default-logo-black.svg
LOGO_WHITE_FILENAME=default-logo-white.svg

ANALYTICS_CODE=console.log('ANALYTICS_CODE DASHBOARD')


Expand Down
2 changes: 2 additions & 0 deletions packages/leaa-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"antd": "4.3.1",
"axios": "^0.19.2",
"classnames": "^2.2.6",
"copy-webpack-plugin": "^6.0.2",
"core-js": "3.6.5",
"currency.js": "^1.2.2",
"dotenv": "^8.2.0",
Expand Down Expand Up @@ -86,6 +87,7 @@
"@types/case-sensitive-paths-webpack-plugin": "^2.1.4",
"@types/classnames": "2.2.10",
"@types/clientjs": "^0.1.0",
"@types/copy-webpack-plugin": "^6.0.0",
"@types/core-js": "2.5.3",
"@types/dinero.js": "^1.6.4",
"@types/dotenv-webpack": "^1.7.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/leaa-dashboard/public/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
robots.txt
assets/images/logo/*
!assets/images/logo/default-logo-*
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IRouteItem } from '@leaa/dashboard/src/interfaces';
import { masterRoutes, flateMasterRoutes } from '@leaa/dashboard/src/routes/master.route';
import { getAuthInfo, isMobile } from '@leaa/dashboard/src/utils';
import { Rcon } from '@leaa/dashboard/src/components';
import logo from '@leaa/dashboard/src/assets/images/logo/logo-white.svg';
import { envConfig } from '@leaa/dashboard/src/configs';

import { ALLOW_PERMISSION, SIDERBAR_COLLAPSED_SL_KEY, CREATE_BUTTON_ICON } from '@leaa/dashboard/src/constants';

Expand All @@ -21,6 +21,8 @@ interface IProps extends RouteComponentProps {
collapsedHash?: number;
}

const LOGO_WHITE = `/assets/images/logo/${envConfig.LOGO_WHITE_FILENAME || 'default-logo-white.svg'}`;

const getMenuName = (menu: IRouteItem) => {
if (menu.namei18n) {
return i18n.t(`${menu.namei18n}`);
Expand Down Expand Up @@ -162,7 +164,7 @@ export const LayoutSidebar = (props: IProps) => {
>
<div className={style['logo-wrapper']}>
<Link to="/">
<img src={logo} alt="" width={40} />
<img src={LOGO_WHITE} alt="" width={40} />
</Link>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface IProps<T> extends TableProps<T> {
route: IRouteItem;
}

export const TableCard = <T extends Record<string, unknown>>(props: IProps<T>) => {
export const TableCard = <T extends any>(props: IProps<T>) => {
const { t } = useTranslation();
const { crudQuery } = props;

Expand Down
2 changes: 2 additions & 0 deletions packages/leaa-dashboard/src/interfaces/config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export interface IDotEnv {
DEMO_MODE: boolean;
DEBUG_MODE: boolean;
SITE_NAME: string;
LOGO_BLACK_FILENAME: string;
LOGO_WHITE_FILENAME: string;
SERVER_PROTOCOL: 'http' | 'https';
SERVER_PORT: number;
SERVER_HOST: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/leaa-dashboard/src/pages/Auth/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import { AuthLoginReq } from '@leaa/common/src/dtos/auth';
import { envConfig } from '@leaa/dashboard/src/configs';
import { HtmlMeta, SwitchLanguage, BuildInfo, AuthGithubButton } from '@leaa/dashboard/src/components';

import logo from '@leaa/dashboard/src/assets/images/logo/logo-black.svg';

import { LoginForm } from './_components/LoginForm/LoginForm';

import style from './style.module.less';

const LOGO_BLACK = `/assets/images/logo/${envConfig.LOGO_BLACK_FILENAME || 'default-logo-black.svg'}`;

export default (props: IPage) => {
const { t } = useTranslation();
const urlObject = qs.parse(window.location.search, { ignoreQueryPrefix: true });
Expand Down Expand Up @@ -118,7 +118,7 @@ export default (props: IPage) => {
<Col xs={24} lg={16} xl={12} xxl={10}>
<div className={style['login-box']}>
<div className={style['logo']}>
<img src={logo} alt="" />
<img src={LOGO_BLACK} alt="" />
</div>

<div className={style['title']}>{t('_page:Auth.Login.title')}</div>
Expand Down
6 changes: 3 additions & 3 deletions packages/leaa-dashboard/tools/webpack/_const.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ WPCONST.VIEWS_DIR = path.resolve(`${WPCONST.SRC_DIR}/views`);
// BUILD PATH
WPCONST.BUILD_DIR_NAME = WPCONST.__DEV__ ? '.cache' : '_build';

WPCONST.CDN_DIR_URL = '/statics';
WPCONST.BUILD_DIR = path.resolve(`${WPCONST.ROOT_DIR}/${WPCONST.BUILD_DIR_NAME}`);
WPCONST.BUILD_PUBLIC_DIR = path.resolve(`${WPCONST.BUILD_DIR}`);
WPCONST.BUILD_STATICS_DIR = path.resolve(`${WPCONST.BUILD_PUBLIC_DIR}/statics`);
WPCONST.CDN_DIR_PATH = '/statics/';
// WPCONST.BUILD_PUBLIC_DIR = path.resolve(`${WPCONST.BUILD_DIR}/public`);
WPCONST.BUILD_STATICS_DIR = path.resolve(`${WPCONST.BUILD_DIR}${WPCONST.CDN_DIR_URL}`);

//
// CHUNK PATH
Expand Down
2 changes: 1 addition & 1 deletion packages/leaa-dashboard/tools/webpack/_devServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { stats } = require('./_stats');

module.exports = {
devServer: {
contentBase: WPCONST.BUILD_PUBLIC_DIR,
contentBase: WPCONST.BUILD_DIR,
https: Boolean(`${process.env.SERVER_PROTOCOL}` === 'https'),
port: process.env.SERVER_PORT,
hot: true,
Expand Down
24 changes: 20 additions & 4 deletions packages/leaa-dashboard/tools/webpack/_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const _ = require('lodash');
const moment = require('moment');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const WriteFilePlugin = require('write-file-webpack-plugin');
Expand Down Expand Up @@ -38,8 +39,8 @@ const htmlWebpackPluginOption = {
).toString('base64'),
__ANALYTICS_CODE__: (!WPCONST.__DEV__ && env && env.ANALYTICS_CODE && `<script>${env.ANALYTICS_CODE}</script>`) || '',
title: `${env.SITE_NAME || '-'}`,
manifest: `${WPCONST.CDN_DIR_PATH}manifest.json`,
filename: `${WPCONST.BUILD_PUBLIC_DIR}/index.html`,
manifest: `${WPCONST.CDN_DIR_URL}/manifest.json`,
filename: `${WPCONST.BUILD_DIR}/index.html`,
template: `${WPCONST.VIEWS_DIR}/index.ejs`,
favicon: `${WPCONST.SRC_DIR}/assets/favicons/favicon.ico`,
inject: true,
Expand Down Expand Up @@ -81,15 +82,30 @@ const lodashModuleReplacementPluginOption = {
};

const plugins = [
// new WriteFilePlugin(),
new WriteFilePlugin({ test: /(favicon\.ico$|index\.html$|robots\.|\/assets\/|\/libs\/)/, useHashIndex: true }),
new webpack.ProvidePlugin(provide),
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /zh-cn/),
new HtmlWebpackPlugin(htmlWebpackPluginOption),
new LodashModuleReplacementPlugin(lodashModuleReplacementPluginOption),
// new CaseSensitivePathsPlugin(),
new ManifestPlugin(),
new ShowEnvInfoWebpackPlugin(),
new WriteFilePlugin(),
// new WriteFilePlugin({
// test: /(index\.html$|robots\.txt|\/assets\/|\/libs\/)/,
// useHashIndex: true,
// }),
new CopyPlugin({
patterns: [
{
from: `${WPCONST.PUBLIC_DIR}/assets/**/*`,
to: `${WPCONST.BUILD_DIR}`,
transformPath(targetPath) {
return `${targetPath}`.replace('public/', '');
},
cacheTransform: true,
},
],
}),

//
// DEV ONLY
Expand Down
4 changes: 2 additions & 2 deletions packages/leaa-dashboard/tools/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ let webpackConfig = {

// # for Project
pathinfo: WPCONST.__DEV__,
path: WPCONST.__PROD__ ? WPCONST.BUILD_STATICS_DIR : undefined,
path: WPCONST.BUILD_STATICS_DIR,
// webpack uses `publicPath` to determine where the app is being served from.
// It requires a trailing slash, or the file assets will get an incorrect path.
// We inferred the "public path" (such as / or /my-project) from homepage.
publicPath: WPCONST.CDN_DIR_PATH,
publicPath: WPCONST.CDN_DIR_URL,
// futureEmitAssets: true,
// There will be one main bundle, and one file per asynchronous chunk.
// In development, it does not produce real files.
Expand Down
54 changes: 50 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,14 @@
dependencies:
"@types/node" "*"

"@types/copy-webpack-plugin@^6.0.0":
version "6.0.0"
resolved "https://registry.npm.taobao.org/@types/copy-webpack-plugin/download/@types/copy-webpack-plugin-6.0.0.tgz#ad4a4d7be859ba6a6adcb970aab3256a705cd049"
integrity sha1-rUpNe+hZumpq3LlwqrMlanBc0Ek=
dependencies:
"@types/node" "*"
"@types/webpack" "*"

"@types/core-js@2.5.3":
version "2.5.3"
resolved "https://registry.npm.taobao.org/@types/core-js/download/@types/core-js-2.5.3.tgz#d2f307f708f897f875d312501e3b4a2fd4481d41"
Expand Down Expand Up @@ -3034,7 +3042,7 @@
resolved "https://registry.npm.taobao.org/@types/js-cookie/download/@types/js-cookie-2.2.6.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fjs-cookie%2Fdownload%2F%40types%2Fjs-cookie-2.2.6.tgz#f1a1cb35aff47bc5cfb05cb0c441ca91e914c26f"
integrity sha1-8aHLNa/0e8XPsFywxEHKkekUwm8=

"@types/json-schema@*", "@types/json-schema@^7.0.3":
"@types/json-schema@*", "@types/json-schema@^7.0.3", "@types/json-schema@^7.0.4":
version "7.0.4"
resolved "https://registry.npm.taobao.org/@types/json-schema/download/@types/json-schema-7.0.4.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fjson-schema%2Fdownload%2F%40types%2Fjson-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339"
integrity sha1-OP1z3f2bVaux4bLtV4y1W9e30zk=
Expand Down Expand Up @@ -3827,7 +3835,7 @@ ajv-keywords@^3.1.0, ajv-keywords@^3.4.1:
resolved "https://registry.npm.taobao.org/ajv-keywords/download/ajv-keywords-3.4.1.tgz#ef916e271c64ac12171fd8384eaae6b2345854da"
integrity sha1-75FuJxxkrBIXH9g4TqrmsjRYVNo=

ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.0, ajv@^6.5.5:
ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.0, ajv@^6.12.2, ajv@^6.5.5:
version "6.12.2"
resolved "https://registry.npm.taobao.org/ajv/download/ajv-6.12.2.tgz?cache=0&sync_timestamp=1587338460514&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fajv%2Fdownload%2Fajv-6.12.2.tgz#c629c5eced17baf314437918d2da88c99d5958cd"
integrity sha1-xinF7O0XuvMUQ3kY0tqIyZ1ZWM0=
Expand Down Expand Up @@ -6245,6 +6253,23 @@ copy-to@^2.0.1:
resolved "https://registry.npm.taobao.org/copy-to/download/copy-to-2.0.1.tgz#2680fbb8068a48d08656b6098092bdafc906f4a5"
integrity sha1-JoD7uAaKSNCGVrYJgJK9r8kG9KU=

copy-webpack-plugin@^6.0.2:
version "6.0.2"
resolved "https://registry.npm.taobao.org/copy-webpack-plugin/download/copy-webpack-plugin-6.0.2.tgz?cache=0&sync_timestamp=1591198586927&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcopy-webpack-plugin%2Fdownload%2Fcopy-webpack-plugin-6.0.2.tgz#10efc6ad219a61acbf2f5fb50af83da38431bc34"
integrity sha1-EO/GrSGaYay/L1+1Cvg9o4QxvDQ=
dependencies:
cacache "^15.0.4"
fast-glob "^3.2.2"
find-cache-dir "^3.3.1"
glob-parent "^5.1.1"
globby "^11.0.1"
loader-utils "^2.0.0"
normalize-path "^3.0.0"
p-limit "^2.3.0"
schema-utils "^2.7.0"
serialize-javascript "^3.1.0"
webpack-sources "^1.4.3"

core-js-compat@^3.6.2:
version "3.6.5"
resolved "https://registry.npm.taobao.org/core-js-compat/download/core-js-compat-3.6.5.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcore-js-compat%2Fdownload%2Fcore-js-compat-3.6.5.tgz#2a51d9a4e25dfd6e690251aa81f99e3c05481f1c"
Expand Down Expand Up @@ -8062,7 +8087,7 @@ fast-glob@^2.0.2, fast-glob@^2.2.6:
merge2 "^1.2.3"
micromatch "^3.1.10"

fast-glob@^3.1.1:
fast-glob@^3.1.1, fast-glob@^3.2.2:
version "3.2.2"
resolved "https://registry.npm.taobao.org/fast-glob/download/fast-glob-3.2.2.tgz#ade1a9d91148965d4bf7c51f72e1ca662d32e63d"
integrity sha1-reGp2RFIll1L98UfcuHKZi0y5j0=
Expand Down Expand Up @@ -8705,7 +8730,7 @@ glob-parent@^3.1.0:
is-glob "^3.1.0"
path-dirname "^1.0.0"

glob-parent@^5.0.0, glob-parent@^5.1.0, glob-parent@~5.1.0:
glob-parent@^5.0.0, glob-parent@^5.1.0, glob-parent@^5.1.1, glob-parent@~5.1.0:
version "5.1.1"
resolved "https://registry.npm.taobao.org/glob-parent/download/glob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229"
integrity sha1-tsHvQXxOVmPqSY8cRa+saRa7wik=
Expand Down Expand Up @@ -8826,6 +8851,18 @@ globby@^11.0.0:
merge2 "^1.3.0"
slash "^3.0.0"

globby@^11.0.1:
version "11.0.1"
resolved "https://registry.npm.taobao.org/globby/download/globby-11.0.1.tgz?cache=0&sync_timestamp=1591083812416&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fglobby%2Fdownload%2Fglobby-11.0.1.tgz#9a2bf107a068f3ffeabc49ad702c79ede8cfd357"
integrity sha1-mivxB6Bo8//qvEmtcCx57ejP01c=
dependencies:
array-union "^2.1.0"
dir-glob "^3.0.1"
fast-glob "^3.1.1"
ignore "^5.1.4"
merge2 "^1.3.0"
slash "^3.0.0"

globby@^6.1.0:
version "6.1.0"
resolved "https://registry.npm.taobao.org/globby/download/globby-6.1.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fglobby%2Fdownload%2Fglobby-6.1.0.tgz#f5a6d70e8395e21c858fb0489d64df02424d506c"
Expand Down Expand Up @@ -15419,6 +15456,15 @@ schema-utils@^2.6.5, schema-utils@^2.6.6:
ajv "^6.12.0"
ajv-keywords "^3.4.1"

schema-utils@^2.7.0:
version "2.7.0"
resolved "https://registry.npm.taobao.org/schema-utils/download/schema-utils-2.7.0.tgz#17151f76d8eae67fbbf77960c33c676ad9f4efc7"
integrity sha1-FxUfdtjq5n+793lgwzxnatn078c=
dependencies:
"@types/json-schema" "^7.0.4"
ajv "^6.12.2"
ajv-keywords "^3.4.1"

scroll-into-view-if-needed@^2.2.20:
version "2.2.24"
resolved "https://registry.npm.taobao.org/scroll-into-view-if-needed/download/scroll-into-view-if-needed-2.2.24.tgz#12bca532990769bd509115a49edcfa755e92a0ea"
Expand Down

0 comments on commit 4978e30

Please sign in to comment.