diff --git a/_test_project/dist/index.html b/_test_project/dist/index.html index ef3994e..e758e93 100644 --- a/_test_project/dist/index.html +++ b/_test_project/dist/index.html @@ -10,6 +10,7 @@ test + diff --git a/_test_project/dist/src/assets/js/index.js b/_test_project/dist/src/assets/js/index.js index 90cb92e..dc6f862 100644 --- a/_test_project/dist/src/assets/js/index.js +++ b/_test_project/dist/src/assets/js/index.js @@ -1,4 +1,4 @@ -(function(){const o=['color:#808080;font-size:12px;font-family:"Helvetica Light", "Helvetica",Arial,sans-serif;font-weight:lighter;',"0010003701120010003700980010001096009608960081959608961796089617960881959608960096088195003281959608960096088195960896049617960881959608960096008195003281959608960096088195960896049617960881959608960096000010961796089617819596009604960096049600819596089604960881950032819596089604960881959608961796009608819596089608960481950032819596089604960881959608961796009608819596089608960400100037009700100037009900100037010800109986003294809480948094809480948094809480948094809480948094809480948094809480948094809480948094809480948094809480948094809480001000670082006900680073008400830045007600790071003290040032005000490049".match(new RegExp(".{1,4}","g")).map(r=>String.fromCodePoint(r)).join("").replace("%p","Project: Test project name").replace("%a",`Author: +import"./vendor.d6c9cb9d.js";(function(){const o=['color:#808080;font-size:12px;font-family:"Helvetica Light", "Helvetica",Arial,sans-serif;font-weight:lighter;',"0010003701120010003700980010001096009608960081959608961796089617960881959608960096088195003281959608960096088195960896049617960881959608960096008195003281959608960096088195960896049617960881959608960096000010961796089617819596009604960096049600819596089604960881950032819596089604960881959608961796009608819596089608960481950032819596089604960881959608961796009608819596089608960400100037009700100037009900100037010800109986003294809480948094809480948094809480948094809480948094809480948094809480948094809480948094809480948094809480948094809480001000670082006900680073008400830045007600790071003290040032005000490049".match(new RegExp(".{1,4}","g")).map(r=>String.fromCodePoint(r)).join("").replace("%p","Project: Test project name").replace("%a",`Author: Anton Sychev (https://dm211.com)`).replace("%c",`Contributors: Contributor name 1 (https://webpage.com) - Contributor name 2 (https://webpage.com)`).replace("%l","License: MIT").replace("%b","Build: 2.1.1")];console.info("%c "+o[1],o[0])})();(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))i(e);new MutationObserver(e=>{for(const t of e)if(t.type==="childList")for(const n of t.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&i(n)}).observe(document,{childList:!0,subtree:!0});function r(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerpolicy&&(t.referrerPolicy=e.referrerpolicy),e.crossorigin==="use-credentials"?t.credentials="include":e.crossorigin==="anonymous"?t.credentials="omit":t.credentials="same-origin",t}function i(e){if(e.ep)return;e.ep=!0;const t=r(e);fetch(e.href,t)}})();console.log("Main.js content"); + Contributor name 2 (https://webpage.com)`).replace("%l","License: MIT").replace("%b","Build: 2.1.1")];console.info("%c "+o[1],o[0])})();(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))i(e);new MutationObserver(e=>{for(const t of e)if(t.type==="childList")for(const n of t.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&i(n)}).observe(document,{childList:!0,subtree:!0});function r(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerpolicy&&(t.referrerPolicy=e.referrerpolicy),e.crossorigin==="use-credentials"?t.credentials="include":e.crossorigin==="anonymous"?t.credentials="omit":t.credentials="same-origin",t}function i(e){if(e.ep)return;e.ep=!0;const t=r(e);fetch(e.href,t)}})(); diff --git a/_test_project/dist/src/assets/js/vendor.d6c9cb9d.js b/_test_project/dist/src/assets/js/vendor.d6c9cb9d.js new file mode 100644 index 0000000..66b50b9 --- /dev/null +++ b/_test_project/dist/src/assets/js/vendor.d6c9cb9d.js @@ -0,0 +1 @@ +class o{constructor(){}log(){console.log("ok test.js")}}console.log("Main.js content");const s=new o;s.log(); diff --git a/_test_project/src/lib/test.js b/_test_project/src/lib/test.js new file mode 100644 index 0000000..b839df8 --- /dev/null +++ b/_test_project/src/lib/test.js @@ -0,0 +1,9 @@ +class Test { + constructor() {} + + log() { + console.log("ok test.js"); + } +} + +export default Test; diff --git a/_test_project/src/main.js b/_test_project/src/main.js index 141fff2..05509f5 100644 --- a/_test_project/src/main.js +++ b/_test_project/src/main.js @@ -1 +1,6 @@ -console.log("Main.js content") \ No newline at end of file +import Test from "./lib/test"; + +console.log("Main.js content"); + +const test = new Test(); +test.log(); diff --git a/_test_project/vite.config.js b/_test_project/vite.config.js index c49a7c5..fe3ddc7 100644 --- a/_test_project/vite.config.js +++ b/_test_project/vite.config.js @@ -30,12 +30,10 @@ export default defineConfig({ chunkFileNames: "src/assets/js/[name].[hash].js", entryFileNames: "src/assets/js/[name].js", manualChunks: (id) => { - if (id.includes("node_modules")) - return id - .toString() - .split("node_modules/")[1] - .split("/")[0] - .toString(); + //added for separate scripts + if (id.includes("node_modules") || id.includes("src")) { + return "vendor"; + } }, }, }, diff --git a/index.js b/index.js index 85822fc..0e2a861 100644 --- a/index.js +++ b/index.js @@ -12,46 +12,48 @@ module.exports = function (options = {}) { return { name: "credits-log", - banner() { - const pkg = require(resolve(".", "package.json")); + async renderChunk(code, chunk) { + if (chunk.isEntry) { + const pkg = require(resolve(".", "package.json")); - if (!pkg.credits) { - console.log( - "No credits array found in your 'pkg.json' file. Run command 'credits-log help'." - ); - return; - } + if (!pkg.credits) { + console.log( + "No credits array found in your 'pkg.json' file. Run command 'credits-log help'." + ); + return; + } - const cl_data = pkg.credits.join(""); - let authorEntry = `.replace("%a", "")`; - let contributorsEntry = `.replace("%c", "")`; - let licenseEntry = `.replace("%l", "")`; - const version = `.replace("%b", "Build: ${pkg.version}")`; + const cl_data = pkg.credits.join(""); + let authorEntry = `.replace("%a", "")`; + let contributorsEntry = `.replace("%c", "")`; + let licenseEntry = `.replace("%l", "")`; + const version = `.replace("%b", "Build: ${pkg.version}")`; - const name = pkg.projectName || pkg.name; - let projectName = `.replace("%p", "Project: ${name}")`; + const name = pkg.projectName || pkg.name; + let projectName = `.replace("%p", "Project: ${name}")`; - if (pkg.author) { - const author = /string/gim.test(typeof pkg.author) - ? "\\t" + pkg.author - : "\\t" + pkg.author.join("\\n"); - authorEntry = `.replace("%a", "Author: \\n${author}")`; - } + if (pkg.author) { + const author = /string/gim.test(typeof pkg.author) + ? "\\t" + pkg.author + : "\\t" + pkg.author.join("\\n"); + authorEntry = `.replace("%a", "Author: \\n${author}")`; + } - if (pkg.contributors) { - const contributors = /string/gim.test(typeof pkg.contributors) - ? "\\t" + pkg.contributors - : "\\t" + pkg.contributors.join("\\n\\t"); + if (pkg.contributors) { + const contributors = /string/gim.test(typeof pkg.contributors) + ? "\\t" + pkg.contributors + : "\\t" + pkg.contributors.join("\\n\\t"); - contributorsEntry = `.replace("%c", "Contributors: \\n${contributors}")`; - } + contributorsEntry = `.replace("%c", "Contributors: \\n${contributors}")`; + } - if (pkg.license) - licenseEntry = `.replace("%l", "License: ${pkg.license}")`; + if (pkg.license) + licenseEntry = `.replace("%l", "License: ${pkg.license}")`; - const banner = String.raw`(function(){const d="${cl_data}";const c=['color:#808080;font-size:12px;font-family:"Helvetica Light", "Helvetica",Arial,sans-serif;font-weight:lighter;', d.match(new RegExp(".{1,4}", "g")).map((r) => String.fromCodePoint(r)).join("")${projectName}${authorEntry}${contributorsEntry}${licenseEntry}${version}];console.info("%c "+c[1],c[0])})()`; + const resultOut = String.raw`(function(){const d="${cl_data}";const c=['color:#808080;font-size:12px;font-family:"Helvetica Light", "Helvetica",Arial,sans-serif;font-weight:lighter;', d.match(new RegExp(".{1,4}", "g")).map((r) => String.fromCodePoint(r)).join("")${projectName}${authorEntry}${contributorsEntry}${licenseEntry}${version}];console.info("%c "+c[1],c[0])})();`; - return banner; + return `${resultOut}${code}`; + } }, buildEnd() { diff --git a/package.json b/package.json index 767384c..9482587 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "credits-log", - "version": "1.0.1", + "version": "1.0.2", "description": "Rollup plugin to add credits message on debug console", "main": "index.js", "type": "commonjs",