tweak webpack build

This commit is contained in:
Pig Fang 2020-03-14 16:13:56 +08:00
parent b1801f0819
commit 76a504bb9c
25 changed files with 55 additions and 71 deletions

View File

@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import styles from './Toast.scss' import styles from './Toast.module.scss'
export type ToastType = 'success' | 'info' | 'warning' | 'error' export type ToastType = 'success' | 'info' | 'warning' | 'error'

View File

@ -1,7 +1,7 @@
import React, { useState, useEffect, useRef } from 'react' import React, { useState, useEffect, useRef } from 'react'
import * as skinview3d from 'skinview3d' import * as skinview3d from 'skinview3d'
import { t } from '../scripts/i18n' import { t } from '@/scripts/i18n'
import styles from './Viewer.scss' import styles from './Viewer.module.scss'
import SkinSteve from '../../../misc/textures/steve.png' import SkinSteve from '../../../misc/textures/steve.png'
export const PICTURES_COUNT = 7 export const PICTURES_COUNT = 7

View File

@ -5,7 +5,7 @@ import { FitAddon } from 'xterm-addon-fit'
import { Shell } from 'blessing-skin-shell' import { Shell } from 'blessing-skin-shell'
import 'xterm/css/xterm.css' import 'xterm/css/xterm.css'
import Draggable from 'react-draggable' import Draggable from 'react-draggable'
import styles from '@/styles/terminal.scss' import styles from '@/styles/terminal.module.scss'
let launched = false let launched = false

View File

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import { t } from '@/scripts/i18n' import { t } from '@/scripts/i18n'
import { Plugin } from './types' import { Plugin } from './types'
import styles from './InfoBox.scss' import styles from './InfoBox.module.scss'
interface Props { interface Props {
plugin: Plugin plugin: Plugin

View File

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import { trans } from '../../../scripts/i18n' import { t } from '@/scripts/i18n'
import * as scoreUtils from './scoreUtils' import * as scoreUtils from './scoreUtils'
interface Props { interface Props {
@ -28,7 +28,7 @@ const SignButton: React.FC<Props> = props => {
onClick={props.onClick} onClick={props.onClick}
> >
<i className="far fa-calendar-check" aria-hidden="true" /> &nbsp; <i className="far fa-calendar-check" aria-hidden="true" /> &nbsp;
{canSign ? trans('user.sign') : remainingTimeText} {canSign ? t('user.sign') : remainingTimeText}
</button> </button>
) )
} }

View File

@ -1,12 +1,12 @@
import React, { useState, useEffect, useCallback } from 'react' import React, { useState, useEffect, useCallback } from 'react'
import { hot } from 'react-hot-loader/root' import { hot } from 'react-hot-loader/root'
import { trans } from '../../../scripts/i18n' import { t } from '@/scripts/i18n'
import * as fetch from '../../../scripts/net' import * as fetch from '@/scripts/net'
import { toast } from '../../../scripts/notify' import { toast } from '@/scripts/notify'
import useTween from '../../../scripts/hooks/useTween' import useTween from '@/scripts/hooks/useTween'
import InfoBox from './InfoBox' import InfoBox from './InfoBox'
import SignButton from './SignButton' import SignButton from './SignButton'
import scoreStyle from './score.scss' import scoreStyle from './score.module.scss'
type ScoreInfo = { type ScoreInfo = {
signAfterZero: boolean signAfterZero: boolean
@ -71,7 +71,7 @@ const Dashboard: React.FC = () => {
return ( return (
<div className="card card-primary card-outline"> <div className="card card-primary card-outline">
<div className="card-header"> <div className="card-header">
<h3 className="card-title">{trans('user.used.title')}</h3> <h3 className="card-title">{t('user.used.title')}</h3>
</div> </div>
<div className="card-body"> <div className="card-body">
<div className="row"> <div className="row">
@ -80,7 +80,7 @@ const Dashboard: React.FC = () => {
<InfoBox <InfoBox
color="teal" color="teal"
icon="gamepad" icon="gamepad"
name={trans('user.used.players')} name={t('user.used.players')}
used={players.used} used={players.used}
total={players.total} total={players.total}
unit="" unit=""
@ -89,7 +89,7 @@ const Dashboard: React.FC = () => {
<InfoBox <InfoBox
color="maroon" color="maroon"
icon="hdd" icon="hdd"
name={trans('user.used.storage')} name={t('user.used.storage')}
used={~~(storage.used / 1024)} used={~~(storage.used / 1024)}
total={~~(storage.total / 1024)} total={~~(storage.total / 1024)}
unit="MB" unit="MB"
@ -98,7 +98,7 @@ const Dashboard: React.FC = () => {
<InfoBox <InfoBox
color="maroon" color="maroon"
icon="hdd" icon="hdd"
name={trans('user.used.storage')} name={t('user.used.storage')}
used={storage.used} used={storage.used}
total={storage.total} total={storage.total}
unit="KB" unit="KB"
@ -106,7 +106,7 @@ const Dashboard: React.FC = () => {
)} )}
</div> </div>
<div className="col-md-4 text-center"> <div className="col-md-4 text-center">
<p className={scoreStyle.title}>{trans('user.cur-score')}</p> <p className={scoreStyle.title}>{t('user.cur-score')}</p>
<p <p
className={scoreStyle.number} className={scoreStyle.number}
data-toggle="modal" data-toggle="modal"
@ -114,7 +114,7 @@ const Dashboard: React.FC = () => {
> >
{~~score} {~~score}
</p> </p>
<p className={scoreStyle.notice}>{trans('user.score-notice')}</p> <p className={scoreStyle.notice}>{t('user.score-notice')}</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,4 +1,4 @@
import { trans } from '../../../scripts/i18n' import { t } from '@/scripts/i18n'
const ONE_MINUTE = 60 * 1000 const ONE_MINUTE = 60 * 1000
const ONE_HOUR = 60 * ONE_MINUTE const ONE_HOUR = 60 * ONE_MINUTE
@ -23,12 +23,12 @@ export function remainingTime(
export function remainingTimeText(remainingTime: number): string { export function remainingTimeText(remainingTime: number): string {
const time = remainingTime / ONE_MINUTE const time = remainingTime / ONE_MINUTE
return time < 60 return time < 60
? trans('user.sign-remain-time', { ? t('user.sign-remain-time', {
time: ~~time, time: ~~time,
unit: trans('user.time-unit-min'), unit: t('user.time-unit-min'),
}) })
: trans('user.sign-remain-time', { : t('user.sign-remain-time', {
time: ~~(time / 60), time: ~~(time / 60),
unit: trans('user.time-unit-hour'), unit: t('user.time-unit-hour'),
}) })
} }

View File

@ -1,6 +1,6 @@
import React, { useState } from 'react' import React, { useState } from 'react'
import { t } from '../../../scripts/i18n' import { t } from '@/scripts/i18n'
import Modal from '../../../components/Modal' import Modal from '@/components/Modal'
interface Props { interface Props {
show: boolean show: boolean

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import { trans } from '../../../scripts/i18n' import { t } from '@/scripts/i18n'
import ButtonEdit from '../../../components/ButtonEdit' import ButtonEdit from '@/components/ButtonEdit'
import { App } from './types' import { App } from './types'
interface Props { interface Props {
@ -19,7 +19,7 @@ const Row: React.FC<Props> = props => {
<td> <td>
<span>{app.name}</span> <span>{app.name}</span>
<ButtonEdit <ButtonEdit
title={trans('user.oauth.modifyName')} title={t('user.oauth.modifyName')}
onClick={props.onEditName} onClick={props.onEditName}
/> />
</td> </td>
@ -27,13 +27,13 @@ const Row: React.FC<Props> = props => {
<td> <td>
<span>{app.redirect}</span> <span>{app.redirect}</span>
<ButtonEdit <ButtonEdit
title={trans('user.oauth.modifyUrl')} title={t('user.oauth.modifyUrl')}
onClick={props.onEditRedirect} onClick={props.onEditRedirect}
/> />
</td> </td>
<td> <td>
<button className="btn btn-danger" onClick={props.onDelete}> <button className="btn btn-danger" onClick={props.onDelete}>
{trans('report.delete')} {t('report.delete')}
</button> </button>
</td> </td>
</tr> </tr>

View File

@ -2,7 +2,7 @@ import React from 'react'
import { t } from '@/scripts/i18n' import { t } from '@/scripts/i18n'
import ButtonEdit from '@/components/ButtonEdit' import ButtonEdit from '@/components/ButtonEdit'
import { Player } from '@/scripts/types' import { Player } from '@/scripts/types'
import styles from './Row.scss' import styles from './Row.module.scss'
interface Props { interface Props {
player: Player player: Player

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import { t } from '@/scripts/i18n' import { t } from '@/scripts/i18n'
import styles from './Viewer2d.scss' import styles from './Viewer2d.module.scss'
interface Props { interface Props {
skin: string skin: string

View File

@ -1,5 +1,5 @@
import { post, ResponseBody } from '../../../scripts/net' import { post, ResponseBody } from '@/scripts/net'
import { showModal } from '../../../scripts/notify' import { showModal } from '@/scripts/notify'
export default async function handler(event: Event) { export default async function handler(event: Event) {
event.preventDefault() event.preventDefault()

View File

@ -1,5 +1,5 @@
import { post, ResponseBody } from '../../../scripts/net' import { post, ResponseBody } from '@/scripts/net'
import { showModal } from '../../../scripts/notify' import { showModal } from '@/scripts/notify'
export default async function handler(event: Event) { export default async function handler(event: Event) {
event.preventDefault() event.preventDefault()

View File

@ -1,5 +1,5 @@
import { post, ResponseBody } from '../../../scripts/net' import { post, ResponseBody } from '@/scripts/net'
import { showModal } from '../../../scripts/notify' import { showModal } from '@/scripts/notify'
export default async function handler(event: Event) { export default async function handler(event: Event) {
event.preventDefault() event.preventDefault()

View File

@ -1,6 +1,6 @@
import { post, ResponseBody } from '../../../scripts/net' import { post, ResponseBody } from '@/scripts/net'
import { trans } from '../../../scripts/i18n' import { trans } from '@/scripts/i18n'
import { showModal, toast } from '../../../scripts/notify' import { showModal, toast } from '@/scripts/notify'
export default async function handler(event: Event) { export default async function handler(event: Event) {
event.preventDefault() event.preventDefault()

View File

@ -1,20 +1,20 @@
import { showModal, toast } from '../../../scripts/notify' import { showModal, toast } from '@/scripts/notify'
import { trans } from '../../../scripts/i18n' import { t } from '@/scripts/i18n'
import { post, ResponseBody } from '../../../scripts/net' import { post, ResponseBody } from '@/scripts/net'
export default async function resetAvatar() { export default async function resetAvatar() {
try { try {
await showModal({ text: trans('user.resetAvatarConfirm') }) await showModal({ text: t('user.resetAvatarConfirm') })
} catch { } catch {
return return
} }
const { message }: ResponseBody = await post( const { message }: ResponseBody = await post('/user/profile/avatar', {
'/user/profile/avatar', tid: 0,
{ tid: 0 }, })
)
toast.success(message) toast.success(message)
document.querySelectorAll<HTMLImageElement>('[alt="User Image"]') document
.querySelectorAll<HTMLImageElement>('[alt="User Image"]')
.forEach(el => { .forEach(el => {
el.src += `?${new Date().getTime()}` el.src += `?${new Date().getTime()}`
}) })

View File

@ -12,26 +12,10 @@ export const walkFetch = {} as jest.Mock<
type FetchFn = <T = any>(url: string, data?: object) => Promise<T> type FetchFn = <T = any>(url: string, data?: object) => Promise<T>
export const get = {} as jest.Mock< export const get = {} as jest.Mock<any, Parameters<typeof net.get>> & FetchFn
ReturnType<typeof net.get>,
Parameters<typeof net.get>
> &
FetchFn
export const post = {} as jest.Mock< export const post = {} as jest.Mock<any, Parameters<typeof net.post>> & FetchFn
ReturnType<typeof net.post>,
Parameters<typeof net.post>
> &
FetchFn
export const put = {} as jest.Mock< export const put = {} as jest.Mock<any, Parameters<typeof net.put>> & FetchFn
ReturnType<typeof net.post>,
Parameters<typeof net.post>
> &
FetchFn
export const del = {} as jest.Mock< export const del = {} as jest.Mock<any, Parameters<typeof net.del>> & FetchFn
ReturnType<typeof net.post>,
Parameters<typeof net.post>
> &
FetchFn

View File

@ -60,7 +60,7 @@ const config = {
], ],
}, },
{ {
test: /\.scss$/, test: /\.module\.scss$/,
use: [ use: [
'style-loader', 'style-loader',
{ {