diff --git a/buildAppJSPlugin.js b/buildAppJSPlugin.js index 794db82..3577af7 100644 --- a/buildAppJSPlugin.js +++ b/buildAppJSPlugin.js @@ -17,14 +17,12 @@ class BuildAppJSPlugin { // 遍历所有编译过的资源文件, // 对于每个文件名称,都添加一行内容。 for (let filename in compilation.assets) { - if (process.env.NODE_ENV === "production") { - filename = (process.env.VUE_APP_PUBLIC_PATH || "/") + filename; - } else { - filename = "/" + filename; - } - // filename = "/" + filename; - if (filename.match(".*\\.js$")) { + if (process.env.NODE_ENV === "production") { + filename = (process.env.VUE_APP_PUBLIC_PATH || "/") + filename; + } else { + filename = "/" + filename; + } jsarr.push(filename); } if (filename.match(".*\\.css$")) { @@ -47,33 +45,32 @@ class BuildAppJSPlugin { .map((e) => e.css)); } let content = ` - var styles = ${JSON.stringify(cssarr)}; var scripts = ${JSON.stringify(jsarr)}; ${cdnjs} - document.write('
'); - var title = document.getElementsByTagName('title') - styles.forEach((item) => { - let link = document.createElement('link'); - link.href=item; - link.rel = 'preload'; - link.as = 'style'; - title[0].parentNode.insertBefore(link,title[0]) - link = document.createElement('link'); - link.href=item; - link.rel = 'stylesheet'; - title[0].parentNode.insertBefore(link,title[0]) - }); scripts.forEach((item) => { document.write(''); }); `; + let cssContent = '' + cssarr.forEach(item=>{ + cssContent += `@import url(${item});\n` + }) // 将这个列表作为一个新的文件资源,插入到 webpack 构建中: compilation.assets["app.js"] = { source: function() { return content; }, size: function() { - return cssarr.length + jsarr.length; + return jsarr.length; + }, + }; + + compilation.assets["style.css"] = { + source: function() { + return cssContent; + }, + size: function() { + return cssarr.length; }, }; diff --git a/dependencies-cdn.js b/dependencies-cdn.js index 228d4f8..29096d3 100644 --- a/dependencies-cdn.js +++ b/dependencies-cdn.js @@ -18,7 +18,7 @@ module.exports = [ // { name: 'brace/snippets/javascript', library: 'javascript', js: ' https://cdn.jsdelivr.net/npm/brace@0.11.1/snippets/javascript.js', css: '' }, // { name: 'vue2-ace-editor', library: 'Vue2ACEEditor', js: 'https://cdn.jsdelivr.net/npm/vue2-ace-editor@0.0.15/index.min.js', css: '' }, { name: 'markdown-it', library: 'markdownit', js: 'https://cdn.jsdelivr.net/npm/markdown-it@10.0.0/dist/markdown-it.min.js', css: '' }, - { name: '', library: '', js: 'https://at.alicdn.com/t/font_1760192_zf96psu0uo.js', css: '' }, + { name: '', library: '', js: 'https://at.alicdn.com/t/font_1760192_axq33n6snd.js', css: '' }, { name: '', library: '', js: '', css: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css' }, { name: '', library: '', js: '', css: 'https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css' }, { name: '', library: '', js: '', css: 'https://cdn.jsdelivr.net/npm/font-awesome-animation@0.2.1/dist/font-awesome-animation.min.css' }, diff --git a/public/index.html b/public/index.html index 9612800..f3480ff 100644 --- a/public/index.html +++ b/public/index.html @@ -43,11 +43,11 @@ <% for (var i in htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.js) { %> <% } %> - - + +