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 99 < title > < %= webpackConfig.name %> </ title >
1010 </ head >
1111 < body >
12- <!-- import cdn js -->
13- < % for(var js of htmlWebpackPlugin.options.cdn.js) { %>
14- < script src ="<%=js%> "> </ script >
15- < % } %>
1612 < div id ="app "> </ div >
1713 <!-- built files will be auto injected -->
1814 </ 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 1515import editorImage from ' ./components/EditorImage'
1616import plugins from ' ./plugins'
1717import 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' 1822
1923export default {
2024 name: ' Tinymce' ,
@@ -91,10 +95,12 @@ export default {
9195 }
9296 },
9397 mounted () {
94- this .initTinymce ()
98+ this .init ()
9599 },
96100 activated () {
97- this .initTinymce ()
101+ if (window .tinymce ) {
102+ this .initTinymce ()
103+ }
98104 },
99105 deactivated () {
100106 this .destroyTinymce ()
@@ -103,6 +109,16 @@ export default {
103109 this .destroyTinymce ()
104110 },
105111 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+ },
106122 initTinymce () {
107123 const _this = this
108124 window .tinymce .init ({
Original file line number Diff line number Diff line change @@ -57,16 +57,6 @@ module.exports = {
5757 }
5858 } ,
5959 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- } )
7060 config . plugins . delete ( 'preload' ) // TODO: need test
7161 config . plugins . delete ( 'prefetch' ) // TODO: need test
7262
You can’t perform that action at this time.
0 commit comments