File tree 4 files changed +57
-16
lines changed
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' ,
@@ -82,10 +86,12 @@ export default {
82
86
}
83
87
},
84
88
mounted () {
85
- this .initTinymce ()
89
+ this .init ()
86
90
},
87
91
activated () {
88
- this .initTinymce ()
92
+ if (window .tinymce ) {
93
+ this .initTinymce ()
94
+ }
89
95
},
90
96
deactivated () {
91
97
this .destroyTinymce ()
@@ -94,6 +100,16 @@ export default {
94
100
this .destroyTinymce ()
95
101
},
96
102
methods: {
103
+ init () {
104
+ // dynamic load tinymce from cdn
105
+ load (tinymceCDN, (err ) => {
106
+ if (err) {
107
+ this .$message .error (err .message )
108
+ return
109
+ }
110
+ this .initTinymce ()
111
+ })
112
+ },
97
113
initTinymce () {
98
114
const _this = this
99
115
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