diff --git a/build/webpack.dev.js b/build/webpack.dev.js index 9447fe67f..df8f05ab7 100644 --- a/build/webpack.dev.js +++ b/build/webpack.dev.js @@ -49,6 +49,7 @@ module.exports = { }, { test: /\.less$/, + sideEffects: true, use: [ 'style-loader', 'css-loader', @@ -63,10 +64,7 @@ module.exports = { }, { test: /\.md$/, - use: [ - 'vue-loader', - '@vant/markdown-loader' - ] + use: ['vue-loader', '@vant/markdown-loader'] }, { test: /\.(ttf|svg)$/, diff --git a/docs/src/router.js b/docs/src/router.js index 3ae381b6e..a7e6d3cd0 100644 --- a/docs/src/router.js +++ b/docs/src/router.js @@ -3,7 +3,9 @@ import docConfig from './doc.config'; import DemoList from './components/DemoList'; import DemoPages from './components/DemoPages'; import { demoWrapper } from './demo-common'; -import './utils/iframe-router'; +import { initIframeRouter } from './utils/iframe-router'; + +initIframeRouter(); const registerRoute = ({ mobile, componentMap }) => { const route = [ diff --git a/docs/src/utils/iframe-router.js b/docs/src/utils/iframe-router.js index 8a8b23e5d..45b1f664f 100644 --- a/docs/src/utils/iframe-router.js +++ b/docs/src/utils/iframe-router.js @@ -5,30 +5,32 @@ import { setLang } from './lang'; import { iframeReady, isMobile } from '.'; -window.syncPath = function () { - const router = window.vueRouter; - const isInIframe = window !== window.top; - const currentDir = router.history.current.path; - const pathParts = currentDir.split('/'); - let lang = pathParts[0]; - if (currentDir[0] === '/') { - lang = pathParts[1]; - } - - if (!isInIframe && !isMobile) { - const iframe = document.querySelector('iframe'); - if (iframe) { - iframeReady(iframe, () => { - iframe.contentWindow.changePath(lang, currentDir); - }); +export function initIframeRouter() { + window.syncPath = function () { + const router = window.vueRouter; + const isInIframe = window !== window.top; + const currentDir = router.history.current.path; + const pathParts = currentDir.split('/'); + let lang = pathParts[0]; + if (currentDir[0] === '/') { + lang = pathParts[1]; } - setLang(lang); - } else if (isInIframe) { - window.top.changePath(lang, currentDir); - } -}; -window.changePath = function (lang, path = '') { - setLang(lang); - window.vueRouter.replace(path); -}; + 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 = '') { + setLang(lang); + window.vueRouter.replace(path); + }; +}