tweak
This commit is contained in:
parent
4f620c4a0d
commit
2d280b8f0b
|
@ -9,10 +9,6 @@
|
|||
<title><%= webpackConfig.name %></title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- import cdn js -->
|
||||
<% for(var js of htmlWebpackPlugin.options.cdn.js) { %>
|
||||
<script src="<%=js%>"></script>
|
||||
<% } %>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
</body>
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
const dynamicLoadScript = (src, callback) => {
|
||||
const existingScript = document.getElementById(src)
|
||||
const cb = callback || function() {}
|
||||
|
||||
if (!existingScript) {
|
||||
const script = document.createElement('script')
|
||||
script.src = src // src url for the third-party library being loaded.
|
||||
script.id = src
|
||||
document.body.appendChild(script)
|
||||
|
||||
script.onload = () => {
|
||||
if (cb) cb(null, script)
|
||||
}
|
||||
script.onerror = () => {
|
||||
cb(new Error('Failed to load ' + src), script)
|
||||
}
|
||||
}
|
||||
|
||||
if (existingScript && cb) cb()
|
||||
}
|
||||
|
||||
export default dynamicLoadScript
|
|
@ -15,6 +15,11 @@
|
|||
import editorImage from './components/EditorImage'
|
||||
import plugins from './plugins'
|
||||
import toolbar from './toolbar'
|
||||
import load from './dynamicLoadScript'
|
||||
|
||||
// inject tinymce into index.html
|
||||
// why use this cdn, detail see https://github.com/PanJiaChen/tinymce-all-in-one
|
||||
const tinymceCDN = 'https://cdn.jsdelivr.net/npm/tinymce-all-in-one@4.9.3/tinymce.min.js'
|
||||
|
||||
export default {
|
||||
name: 'Tinymce',
|
||||
|
@ -82,7 +87,13 @@ export default {
|
|||
}
|
||||
},
|
||||
mounted() {
|
||||
this.initTinymce()
|
||||
load(tinymceCDN, (err) => {
|
||||
if (err) {
|
||||
this.$message.error(err.message)
|
||||
return
|
||||
}
|
||||
this.initTinymce()
|
||||
})
|
||||
},
|
||||
activated() {
|
||||
this.initTinymce()
|
||||
|
|
|
@ -57,16 +57,6 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
chainWebpack(config) {
|
||||
const cdn = {
|
||||
// inject tinymce into index.html
|
||||
// why use this cdn, detail see https://github.com/PanJiaChen/tinymce-all-in-one
|
||||
js: ['https://cdn.jsdelivr.net/npm/tinymce-all-in-one@4.9.3/tinymce.min.js']
|
||||
}
|
||||
config.plugin('html')
|
||||
.tap(args => {
|
||||
args[0].cdn = cdn
|
||||
return args
|
||||
})
|
||||
config.plugins.delete('preload') // TODO: need test
|
||||
config.plugins.delete('prefetch') // TODO: need test
|
||||
|
||||
|
|
Loading…
Reference in New Issue