Closed
Description
Bug report
Such as Baidu Statistics code,we usually add a piece of pure js code to index.html :
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement(“script”);
hm.src = “//hm.baidu.com/hm.js?XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”;
var s = document.getElementsByTagName(“script”)[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
How can I add those code to Vuepress ?
Version
Vuepress 0.14.2
Steps to reproduce
I try to add those code to config.js
:
module.exports = {
head: [ ['script', { ... }] ]
}
But I don't know how to do it.
Then I use a third part library vue-ba
install
yarn add vue-ba
then I modified enhanceApp.js
:
import ba from 'vue-ba'
export default ({
Vue, options, router, siteData
}) => {
Vue.use(ba, 'xxxxxx')
}
when compiling,some error were outputed in console:
[10:47:08 AM] Compiled Server in 41s
[10:47:10 AM] Compiled Client in 43s
FAIL WAIT Rendering static HTML...
Rendering page: /infoError rendering /:
Visit ReferenceError: window is not defined
at Object.<anonymous> (/Users/DYT/Desktop/www.xiaoyulive.top/node_modules/vue-ba/dist/index.js:1:4368)
at n (/Users/DYT/Desktop/www.xiaoyulive.top/node_modules/vue-ba/dist/index.js:1:408)
at /Users/DYT/Desktop/www.xiaoyulive.top/node_modules/vue-ba/dist/index.js:1:791
at /Users/DYT/Desktop/www.xiaoyulive.top/node_modules/vue-ba/dist/index.js:1:801
at /Users/DYT/Desktop/www.xiaoyulive.top/node_modules/vue-ba/dist/index.js:1:146
at Object.<anonymous> (/Users/DYT/Desktop/www.xiaoyulive.top/node_modules/vue-ba/dist/index.js:1:285)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)https://yarnpkg.com/en/docs/cli/run
at r (/Users/DYT/Desktop/www.xiaoyulive.top/node_modules/vue-server-renderer/build.js:8346:16)
at Object.<anonymous> (webpack:/external "vue-ba":1:0)
at __webpack_require__ (webpack/bootstrap:25:0)
error Command failed with exit code 1.
error Command failed with exit code 1.
for documentation about this command.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Process finished with exit code 1
What is expected?
Expose window
in enhanceApp.js, or a mechanism for adding pure js code.
What is actually happening?
Other relevant information
- Your OS: macOS High Sierra 10.13.6
- Node.js version: v10.6.0
- Browser version: Chrome 68.0.3440.106
- Is this a global or local install? local
- Which package manager did you use for the install? yarn