File tree Expand file tree Collapse file tree 4 files changed +57
-16
lines changed Expand file tree Collapse file tree 4 files changed +57
-16
lines changed Original file line number Diff line number Diff line change 9
9
< title > < %= webpackConfig.name %> </ title >
10
10
</ head >
11
11
< body >
12
- <!-- import cdn js -->
13
- < % for(var js of htmlWebpackPlugin.options.cdn.js) { %>
14
- < script src ="<%=js%> "> </ script >
15
- < % } %>
16
12
< div id ="app "> </ div >
17
13
<!-- built files will be auto injected -->
18
14
</ body >
Original file line number Diff line number Diff line change
1
+ const dynamicLoadScript = ( src , callback ) => {
2
+ const existingScript = document . getElementById ( src )
3
+ const cb = callback || function ( ) { }
4
+
5
+ if ( ! existingScript ) {
6
+ const script = document . createElement ( 'script' )
7
+ script . src = src // src url for the third-party library being loaded.
8
+ script . id = src
9
+ document . body . appendChild ( script )
10
+
11
+ const onEnd = 'onload' in script ? stdOnEnd : ieOnEnd
12
+ onEnd ( script , cb )
13
+ }
14
+
15
+ if ( existingScript && cb ) cb ( null , existingScript )
16
+
17
+ function stdOnEnd ( script , cb ) {
18
+ script . onload = function ( ) {
19
+ // this.onload = null here is necessary
20
+ // because even IE9 works not like others
21
+ this . onerror = this . onload = null
22
+ cb ( null , script )
23
+ }
24
+ script . onerror = function ( ) {
25
+ this . onerror = this . onload = null
26
+ cb ( new Error ( 'Failed to load ' + src ) , script )
27
+ }
28
+ }
29
+
30
+ function ieOnEnd ( script , cb ) {
31
+ script . onreadystatechange = function ( ) {
32
+ if ( this . readyState !== 'complete' && this . readyState !== 'loaded' ) return
33
+ this . onreadystatechange = null
34
+ cb ( null , script ) // there is no way to catch loading errors in IE8
35
+ }
36
+ }
37
+ }
38
+
39
+ export default dynamicLoadScript
Original file line number Diff line number Diff line change 15
15
import editorImage from ' ./components/EditorImage'
16
16
import plugins from ' ./plugins'
17
17
import toolbar from ' ./toolbar'
18
+ import load from ' ./dynamicLoadScript'
19
+
20
+ // why use this cdn, detail see https://github.com/PanJiaChen/tinymce-all-in-one
21
+ const tinymceCDN = ' https://cdn.jsdelivr.net/npm/[email protected] /tinymce.min.js'
18
22
19
23
export default {
20
24
name: ' Tinymce' ,
@@ -91,10 +95,12 @@ export default {
91
95
}
92
96
},
93
97
mounted () {
94
- this .initTinymce ()
98
+ this .init ()
95
99
},
96
100
activated () {
97
- this .initTinymce ()
101
+ if (window .tinymce ) {
102
+ this .initTinymce ()
103
+ }
98
104
},
99
105
deactivated () {
100
106
this .destroyTinymce ()
@@ -103,6 +109,16 @@ export default {
103
109
this .destroyTinymce ()
104
110
},
105
111
methods: {
112
+ init () {
113
+ // dynamic load tinymce from cdn
114
+ load (tinymceCDN, (err ) => {
115
+ if (err) {
116
+ this .$message .error (err .message )
117
+ return
118
+ }
119
+ this .initTinymce ()
120
+ })
121
+ },
106
122
initTinymce () {
107
123
const _this = this
108
124
window .tinymce .init ({
Original file line number Diff line number Diff line change @@ -57,16 +57,6 @@ module.exports = {
57
57
}
58
58
} ,
59
59
chainWebpack ( config ) {
60
- const cdn = {
61
- // inject tinymce into index.html
62
- // why use this cdn, detail see https://github.com/PanJiaChen/tinymce-all-in-one
63
- js :
[ 'https://cdn.jsdelivr.net/npm/[email protected] /tinymce.min.js' ]
64
- }
65
- config . plugin ( 'html' )
66
- . tap ( args => {
67
- args [ 0 ] . cdn = cdn
68
- return args
69
- } )
70
60
config . plugins . delete ( 'preload' ) // TODO: need test
71
61
config . plugins . delete ( 'prefetch' ) // TODO: need test
72
62
You can’t perform that action at this time.
0 commit comments