[Doc] fix tree shaking when build site

This commit is contained in:
陈嘉涵 2019-06-21 15:53:28 +08:00
parent 8564a5b1f1
commit 6e93c93d46
3 changed files with 32 additions and 30 deletions

View File

@ -49,6 +49,7 @@ module.exports = {
}, },
{ {
test: /\.less$/, test: /\.less$/,
sideEffects: true,
use: [ use: [
'style-loader', 'style-loader',
'css-loader', 'css-loader',
@ -63,10 +64,7 @@ module.exports = {
}, },
{ {
test: /\.md$/, test: /\.md$/,
use: [ use: ['vue-loader', '@vant/markdown-loader']
'vue-loader',
'@vant/markdown-loader'
]
}, },
{ {
test: /\.(ttf|svg)$/, test: /\.(ttf|svg)$/,

View File

@ -3,7 +3,9 @@ import docConfig from './doc.config';
import DemoList from './components/DemoList'; import DemoList from './components/DemoList';
import DemoPages from './components/DemoPages'; import DemoPages from './components/DemoPages';
import { demoWrapper } from './demo-common'; import { demoWrapper } from './demo-common';
import './utils/iframe-router'; import { initIframeRouter } from './utils/iframe-router';
initIframeRouter();
const registerRoute = ({ mobile, componentMap }) => { const registerRoute = ({ mobile, componentMap }) => {
const route = [ const route = [

View File

@ -5,30 +5,32 @@
import { setLang } from './lang'; import { setLang } from './lang';
import { iframeReady, isMobile } from '.'; import { iframeReady, isMobile } from '.';
window.syncPath = function () { export function initIframeRouter() {
const router = window.vueRouter; window.syncPath = function () {
const isInIframe = window !== window.top; const router = window.vueRouter;
const currentDir = router.history.current.path; const isInIframe = window !== window.top;
const pathParts = currentDir.split('/'); const currentDir = router.history.current.path;
let lang = pathParts[0]; const pathParts = currentDir.split('/');
if (currentDir[0] === '/') { let lang = pathParts[0];
lang = pathParts[1]; if (currentDir[0] === '/') {
} lang = pathParts[1];
if (!isInIframe && !isMobile) {
const iframe = document.querySelector('iframe');
if (iframe) {
iframeReady(iframe, () => {
iframe.contentWindow.changePath(lang, currentDir);
});
} }
setLang(lang);
} else if (isInIframe) {
window.top.changePath(lang, currentDir);
}
};
window.changePath = function (lang, path = '') { if (!isInIframe && !isMobile) {
setLang(lang); const iframe = document.querySelector('iframe');
window.vueRouter.replace(path); if (iframe) {
}; iframeReady(iframe, () => {
iframe.contentWindow.changePath(lang, currentDir);
});
}
setLang(lang);
} else if (isInIframe) {
window.top.changePath(lang, currentDir);
}
};
window.changePath = function (lang, path = '') {
setLang(lang);
window.vueRouter.replace(path);
};
}