Skip to content

Commit

Permalink
build: base url supports configuration (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
danranVm committed Nov 9, 2022
1 parent f7c84aa commit 99e4ddd
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 55 deletions.
26 changes: 0 additions & 26 deletions packages/site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
<meta charset="UTF-8" />
<link rel="preconnect" href="https://cdn.jsdelivr.net" />
<link rel="preconnect" href="https://api.github.com" />
<link rel="preconnect" href="https://vars.hotjar.com" />
<link rel="preconnect" href="https://script.hotjar.com" />
<link
rel="preload"
href="https://script.hotjar.com/font-hotjar_5.65042d.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link rel="preconnect" href="https://www.google-analytics.com" />
<link rel="dns-prefetch" href="https://www.google-analytics.com" />
<link rel="icon" href="/favicon.ico" />
Expand Down Expand Up @@ -65,23 +56,6 @@
<link rel="manifest" href="/manifest.json">
-->

<!-- Hotjar Tracking Code for idux.site -->
<script>
;(function (h, o, t, j, a, r) {
h.hj =
h.hj ||
function () {
;(h.hj.q = h.hj.q || []).push(arguments)
}
h._hjSettings = { hjid: 2394596, hjsv: 6 }
a = o.getElementsByTagName('head')[0]
r = o.createElement('script')
r.async = 1
r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv
a.appendChild(r)
})(window, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=')
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-150TJFGX9N"></script>
<script>
Expand Down
6 changes: 5 additions & 1 deletion packages/site/public/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
// https://username.github.io/repo-name/one/two?a=b&c=d#qwe becomes
// https://username.github.io/repo-name/?/one/two&a=b~and~c=d#qwe
// Otherwise, leave pathSegmentsToKeep as 0.
var pathSegmentsToKeep = 0;

// var pathSegmentsToKeep = 0;

var l = window.location;

var pathSegmentsToKeep = l.pathname.startsWith('/version') ? 2 : 0;

l.replace(
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
Expand Down
26 changes: 1 addition & 25 deletions packages/site/src/components/views/home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<IxRow class="home-comp-properties-wrapper">
<IxCol v-for="(item, index) of locale.compProperties" :key="index" xs="24" sm="12" class="home-comp-properties">
<dl>
<div class="home-comp-properties-img"></div>
<div class="home-comp-properties-img" :style="{ backgroundImage: `url(${item.image})` }"></div>
<dt>{{ item.title }}</dt>
<dd v-for="(desc, _index) of item.descs" :key="_index">{{ desc }}</dd>
</dl>
Expand Down Expand Up @@ -181,30 +181,6 @@ export default defineComponent({
background-repeat: no-repeat;
}
&:nth-child(1) {
.home-comp-properties-img {
background-image: url('/icons/comp-properties-1.png');
}
}
&:nth-child(2) {
.home-comp-properties-img {
background-image: url('/icons/comp-properties-2.png');
}
}
&:nth-child(3) {
.home-comp-properties-img {
background-image: url('/icons/comp-properties-3.png');
}
}
&:nth-child(4) {
.home-comp-properties-img {
background-image: url('/icons/comp-properties-4.png');
}
}
dl {
display: flex;
flex-direction: column;
Expand Down
4 changes: 4 additions & 0 deletions packages/site/src/components/views/home/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ export const homeLocales = {
{
title: '全新 Vue 3.x,无包袱更纯粹',
descs: ['全面拥抱 Composition API,从源码到文档', '完全使用 TypeScript 开发,提供完整的类型定义'],
image: __BASE_URL__ + 'icons/comp-properties-1.png',
},
{
title: '开箱即用,尽享高效',
descs: ['Monorepo模式:cdk,components,pro', '开箱即用的高质量组件'],
image: __BASE_URL__ + 'icons/comp-properties-2.png',
},
{
title: '百变百搭,灵活定制',
descs: ['灵活的全局配置,深入细节的主题定制能力', '国际化语言支持'],
image: __BASE_URL__ + 'icons/comp-properties-3.png',
},
{
title: '组件体验,持续迭代',
descs: ['基于业务需求及设计趋势', '专业团队持续维护,不断提升组件质量'],
image: __BASE_URL__ + 'icons/comp-properties-4.png',
},
],
sceneDesc: ['多场景跨业务产品案例', '云计算&安全多场景落地,未来实现集团内全产品覆盖'],
Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/docs/GlobalConfig.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { createApp } from 'vue'
import { createGlobalConfig } from '@idux/components/config'

const loadIconDynamically = (iconName: string) => {
return fetch(`/icon-svg/${iconName}.svg`).then(res => res.text())
return fetch(`/idux-icons/${iconName}.svg`).then(res => res.text())
}

const globalConfig = createGlobalConfig({
Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/iduxInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ addIconDefinitions(IDUX_ICON_DEPENDENCIES)

// 动态加载:不会被打包,可以减小包体积,需要加载的时候时候 http 请求加载
const loadIconDynamically = (iconName: string) => {
return fetch(`/idux-icons/${iconName}.svg`).then(res => res.text())
return fetch(__BASE_URL__ + `idux-icons/${iconName}.svg`).then(res => res.text())
}

const globalConfig = createGlobalConfig({
Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import './index.less'
import { routes } from './router'

const router = createRouter({
history: createWebHistory(),
history: createWebHistory(__BASE_URL__),
scrollBehavior: (to, _, savedPosition) => {
if (savedPosition) {
return savedPosition
Expand Down
3 changes: 3 additions & 0 deletions packages/site/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const componentPath: Record<string, string> = {

export default defineConfig(({ command }) => {
const isBuild = command === 'build'
const baseUrl = '/'

return {
plugins: [
Expand Down Expand Up @@ -77,6 +78,7 @@ export default defineConfig(({ command }) => {
__VERSION_CDK__: `'${cdkPackage.version}'`,
__VERSION_COMPONENTS__: `'${componentsPackage.version}'`,
__VERSION_PRO__: `'${proPackage.version}'`,
__BASE_URL__: `'${baseUrl}'`,
},
css: {
preprocessorOptions: {
Expand All @@ -86,6 +88,7 @@ export default defineConfig(({ command }) => {
},
},
},
base: baseUrl,
build: {
outDir: resolve(__dirname, '../../dist/site'),
emptyOutDir: true,
Expand Down
1 change: 1 addition & 0 deletions typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare global {
const __VERSION_CDK__: string
const __VERSION_COMPONENTS__: string
const __VERSION_PRO__: string
const __BASE_URL__: string
function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number
function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number
function clearInterval(handle?: number): void
Expand Down

0 comments on commit 99e4ddd

Please sign in to comment.