I'm just going to do a blog project these days , Then I added a few blogs in the background , Then introduce the marked
and highlight.js
No problem . Used backstage vue. Then yesterday, I was going to do a blog for the client , That's the mistake , The hint is that my module highlight.js
Compile failed .
Then we will discuss how to solve various searches .
There has been no way .
Guess if the module error is .js
But obviously not , I import it according to the package in the background , And the wrong guide is not such a mistake , It's not a version issue , After all, if the backstage can be used , The version of the follow-up package should not matter much .
And when I opened the project this morning , Another error occurred suddenly in the compilation , Say my antd
Can't find package.json
, I wondered , I haven't even moved , Later I thought about , For the front desk umi+ts, And package manager yarn
, But it was installed yesterday marked
and highlight.js
It seems to be used npm
, Just thinking that there was a mistake, I would reload the bag . Sure enough, it's useless .
The key is coming. , Suddenly something came to mind , Before I think about it
webpack
It's like learning a configuration , Yes, external import can be configured js. I suddenly feelwebpack
How useful , So I went to the official website umi To see how to match , I also sawwebpack
Configuration of , The configuration found isexternals
.
externals : {
'highlight.js' : "window.hljs"
},
scripts : ["https://cdn.bootcdn.net/ajax/libs/highlight.js/11.4.0/highlight.min.js"]
Because there is umi Yes scripts Configuration item , So I didn't move umi Compile template for .
Here's to say umi Of html Templates
stay src/pages Create... Under the directory document.ejs
File can rewrite template file
Because there is still no solution to the problem , But it also provides a comparison flexible The idea of , When the template compilation fails , If time is tight , You can try to configure the external cdn link , Import code from elsewhere , Expose global variables , And pass
externals
Configure import package not to compile , And tell how the variables are exposed .
If a friend knows the nature of this mistake , Feel free to leave a comment below .