@master/css-compiler 2.0.0-beta.7 → 2.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{esm/compiler.d.ts → compiler.d.ts} +2 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +2 -2
- package/dist/{esm/index.d.ts → index.d.ts} +0 -0
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/{esm/options → options}/extract.d.ts +0 -0
- package/dist/{esm/options → options}/index.d.ts +0 -0
- package/dist/{esm/utils → utils}/write-file.d.ts +0 -0
- package/dist/{esm/vite.d.ts → vite.d.ts} +0 -0
- package/dist/{esm/webpack.d.ts → webpack.d.ts} +0 -0
- package/package.json +11 -9
- package/dist/esm/compiler.js +0 -58
- package/dist/esm/compiler.js.map +0 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/options/extract.js +0 -61
- package/dist/esm/options/extract.js.map +0 -1
- package/dist/esm/options/index.js +0 -18
- package/dist/esm/options/index.js.map +0 -1
- package/dist/esm/utils/write-file.js +0 -10
- package/dist/esm/utils/write-file.js.map +0 -1
- package/dist/esm/vite.js +0 -78
- package/dist/esm/vite.js.map +0 -1
- package/dist/esm/webpack.js +0 -94
- package/dist/esm/webpack.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MasterCSSCompilerOptions, MasterCSSCompilerSource } from './options';
|
|
2
2
|
import MasterCSS from '@master/css';
|
|
3
3
|
export default class MasterCSSCompiler {
|
|
4
|
-
options
|
|
5
|
-
constructor(options
|
|
4
|
+
options?: MasterCSSCompilerOptions;
|
|
5
|
+
constructor(options?: MasterCSSCompilerOptions);
|
|
6
6
|
css: MasterCSS;
|
|
7
7
|
extractions: Set<string>;
|
|
8
8
|
extract({ name, content }: MasterCSSCompilerSource): string[];
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _=Object.create;var b=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var G=(t,e)=>{for(var s in e)b(t,s,{get:e[s],enumerable:!0})},j=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of z(e))!B.call(t,o)&&o!==s&&b(t,o,{get:()=>e[o],enumerable:!(r=W(e,o))||r.enumerable});return t};var h=(t,e,s)=>(s=t!=null?_(U(t)):{},j(e||!t||!t.__esModule?b(s,"default",{value:t,enumerable:!0}):s,t)),V=t=>j(b({},"__esModule",{value:!0}),t);var K={};G(K,{MasterCSSCompiler:()=>m,MasterCSSVitePlugin:()=>N,MasterCSSWebpackPlugin:()=>x});module.exports=V(K);var $=h(require("path")),p=h(require("chalk"));var D=require("@master/css");function R({content:t}){let e=t.match(/[^\s]+/g)??[],s=new Set;for(let r of e){let o=H(r);if(o.size)for(let n of o)s.add(n);else s.add(T(r))}return[...s].filter(r=>r&&!J(r))}var T=t=>{let e=t;return t=t.replace(/^([\w={[(\\]*["'`])/,""),t.match(/^content:((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)$/)||(t=t.replace(/(\.*|[([{\\:#]*|["'`].*)$/,"")),e===t?t:T(t)},H=t=>{let e=new Set,s=/((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)/g,r;for(;(r=s.exec(t))!==null;){r.index===s.lastIndex&&s.lastIndex++;let o=H(r[2]);if(o.size)for(let n of o)e.add(n);else e.add(T(r[2]))}return e},J=t=>!t||!t.match(/(?:^[\w-]+:[\w$#]+)|(?:^[@~][\w-]+$)/)&&!Object.keys(D.defaultSemantics).includes(t)||t.match(/\*\*/)||t.match(/:\[/)||t.match(/\$\{/)||t.match(/\{\{/)||t.match(/\(\{[^}]*\}/)||t.match(/<\w+>|<\/\w+>/);var L={output:{name:"master.css",dir:""},accept({name:t}){if(t.match(/[\\/]node_modules[\\/]/))return!1;if(t.match(/\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i))return!0},extract:R},P=L;var S=h(require("@master/css")),E=require("perf_hooks"),m=class{constructor(e){this.options=e;this.options=(0,S.extend)(P,e);let s;try{s=require($.default.resolve(process.cwd(),e.config||"./master.css.js"))}catch{}this.css=new S.default((0,S.configure)(s))}css;extractions=new Set;extract({name:e,content:s}){if(!e||!s||!this.options.accept?.({content:s,name:e}))return[];let r=[];this.log("accepts",` \u2192 ${$.default.relative(process.cwd(),e)}`);for(let o of this.options.extract({content:s,name:e}))this.extractions.has(o)||(this.extractions.add(o),r.push(o));return r}insert(e){let s=E.performance.now();for(let n of e)this.css.findAndInsert(n);let r=Math.round((E.performance.now()-s)*1e3),o=this.css.rules.map(n=>n.className);console.log(`[Master CSS] process ${p.default.green(e.length)} extractions in ${p.default.green(r)} \xB5s [${p.default.green(this.css.rules.length)} rules in ${p.default.green($.default.join(this.options.output.dir,this.options.output.name))}]`),this.log("extractions",` \u2192 ${p.default.green(e.length)} extractions: ${p.default.blue(e.join(" "))}`),this.log("validClasses",` \u2192 ${p.default.green(o.length)} total valid classes: ${p.default.blue(o.join(" "))}`)}log(e,s){(this.options.debug===!0||Array.isArray(this.options.debug)&&this.options.debug.includes(e))&&console.log(s)}};var F=h(require("path"));var C="MasterCSSWebpackPlugin",x=class extends m{apply(e){let{webpack:s}=e,{Template:r,RuntimeGlobals:o,RuntimeModule:n}=s,{RawSource:w}=s.sources,{Compilation:M}=s,{options:i}=this,l=F.default.join(i.output.dir||"",i.output.name),k=l.replace(/\\/g,"/");e.hooks.thisCompilation.tap(C,a=>{let u=new WeakSet,f=(d,c)=>{u.has(d)||(u.add(d),c.add(o.publicPath),a.addRuntimeModule(d,new A(c)))};a.hooks.runtimeRequirementInTree.for(o.ensureChunkHandlers).tap(C,f),a.hooks.runtimeRequirementInTree.for(o.hmrDownloadUpdateHandlers).tap(C,f);class A extends n{runtimeRequirements;constructor(c){super("master-css-loading",10),this.runtimeRequirements=c}generate(){let{runtimeRequirements:c}=this;return c.has(o.hmrDownloadUpdateHandlers)?r.asString([Date.now().toString(),`const link = document.querySelector('[href*=\\'${k}\\'][rel=stylesheet]')`,"if (link) {",r.indent(["link.href = link.href.replace(/ts=[0-9]+/, 'ts=' + Date.now())"]),"}"]):""}}}),e.hooks.compilation.tap(C,a=>{a.hooks.finishModules.tap(C,u=>{let{modifiedFiles:f,watching:A}=e,d=[];for(let c of u){let g=c.resource,y=c._source?.source();A&&f?.size&&!f.has(g)||d.push(...this.extract({name:g,content:y}))}if(d.length){let c=this.css.text;this.insert(d);let g=this.css.text;if(g!==c){let y=new w(g);a.getAsset(l)?a.updateAsset(l,y):a.emitAsset(l,y)}}}),a.hooks.processAssets.tap({name:C,stage:M.PROCESS_ASSETS_STAGE_ADDITIONS},()=>{a.chunks.forEach(u=>{u.files.add(l)})})})}};var I=h(require("path"));var
|
|
1
|
+
var _=Object.create;var b=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var G=(t,e)=>{for(var s in e)b(t,s,{get:e[s],enumerable:!0})},j=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of z(e))!B.call(t,o)&&o!==s&&b(t,o,{get:()=>e[o],enumerable:!(r=W(e,o))||r.enumerable});return t};var h=(t,e,s)=>(s=t!=null?_(U(t)):{},j(e||!t||!t.__esModule?b(s,"default",{value:t,enumerable:!0}):s,t)),V=t=>j(b({},"__esModule",{value:!0}),t);var K={};G(K,{MasterCSSCompiler:()=>m,MasterCSSVitePlugin:()=>N,MasterCSSWebpackPlugin:()=>x});module.exports=V(K);var $=h(require("path"),1),p=h(require("chalk"),1);var D=require("@master/css");function R({content:t}){let e=t.match(/[^\s]+/g)??[],s=new Set;for(let r of e){let o=H(r);if(o.size)for(let n of o)s.add(n);else s.add(T(r))}return[...s].filter(r=>r&&!J(r))}var T=t=>{let e=t;return t=t.replace(/^([\w={[(\\]*["'`])/,""),t.match(/^content:((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)$/)||(t=t.replace(/(\.*|[([{\\:#]*|["'`].*)$/,"")),e===t?t:T(t)},H=t=>{let e=new Set,s=/((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)/g,r;for(;(r=s.exec(t))!==null;){r.index===s.lastIndex&&s.lastIndex++;let o=H(r[2]);if(o.size)for(let n of o)e.add(n);else e.add(T(r[2]))}return e},J=t=>!t||!t.match(/(?:^[\w-]+:[\w$#]+)|(?:^[@~][\w-]+$)/)&&!Object.keys(D.defaultSemantics).includes(t)||t.match(/\*\*/)||t.match(/:\[/)||t.match(/\$\{/)||t.match(/\{\{/)||t.match(/\(\{[^}]*\}/)||t.match(/<\w+>|<\/\w+>/);var L={output:{name:"master.css",dir:""},accept({name:t}){if(t.match(/[\\/]node_modules[\\/]/))return!1;if(t.match(/\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i))return!0},extract:R},P=L;var S=h(require("@master/css"),1),E=require("perf_hooks"),m=class{constructor(e){this.options=e;this.options=(0,S.extend)(P,e);let s;try{s=require($.default.resolve(process.cwd(),e.config||"./master.css.js"))}catch{}this.css=new S.default((0,S.configure)(s))}css;extractions=new Set;extract({name:e,content:s}){if(!e||!s||!this.options.accept?.({content:s,name:e}))return[];let r=[];this.log("accepts",` \u2192 ${$.default.relative(process.cwd(),e)}`);for(let o of this.options.extract({content:s,name:e}))this.extractions.has(o)||(this.extractions.add(o),r.push(o));return r}insert(e){let s=E.performance.now();for(let n of e)this.css.findAndInsert(n);let r=Math.round((E.performance.now()-s)*1e3),o=this.css.rules.map(n=>n.className);console.log(`[Master CSS] process ${p.default.green(e.length)} extractions in ${p.default.green(r)} \xB5s [${p.default.green(this.css.rules.length)} rules in ${p.default.green($.default.join(this.options.output.dir,this.options.output.name))}]`),this.log("extractions",` \u2192 ${p.default.green(e.length)} extractions: ${p.default.blue(e.join(" "))}`),this.log("validClasses",` \u2192 ${p.default.green(o.length)} total valid classes: ${p.default.blue(o.join(" "))}`)}log(e,s){(this.options.debug===!0||Array.isArray(this.options.debug)&&this.options.debug.includes(e))&&console.log(s)}};var F=h(require("path"),1);var C="MasterCSSWebpackPlugin",x=class extends m{apply(e){let{webpack:s}=e,{Template:r,RuntimeGlobals:o,RuntimeModule:n}=s,{RawSource:w}=s.sources,{Compilation:M}=s,{options:i}=this,l=F.default.join(i.output.dir||"",i.output.name),k=l.replace(/\\/g,"/");e.hooks.thisCompilation.tap(C,a=>{let u=new WeakSet,f=(d,c)=>{u.has(d)||(u.add(d),c.add(o.publicPath),a.addRuntimeModule(d,new A(c)))};a.hooks.runtimeRequirementInTree.for(o.ensureChunkHandlers).tap(C,f),a.hooks.runtimeRequirementInTree.for(o.hmrDownloadUpdateHandlers).tap(C,f);class A extends n{runtimeRequirements;constructor(c){super("master-css-loading",10),this.runtimeRequirements=c}generate(){let{runtimeRequirements:c}=this;return c.has(o.hmrDownloadUpdateHandlers)?r.asString([Date.now().toString(),`const link = document.querySelector('[href*=\\'${k}\\'][rel=stylesheet]')`,"if (link) {",r.indent(["link.href = link.href.replace(/ts=[0-9]+/, 'ts=' + Date.now())"]),"}"]):""}}}),e.hooks.compilation.tap(C,a=>{a.hooks.finishModules.tap(C,u=>{let{modifiedFiles:f,watching:A}=e,d=[];for(let c of u){let g=c.resource,y=c._source?.source();A&&f?.size&&!f.has(g)||d.push(...this.extract({name:g,content:y}))}if(d.length){let c=this.css.text;this.insert(d);let g=this.css.text;if(g!==c){let y=new w(g);a.getAsset(l)?a.updateAsset(l,y):a.emitAsset(l,y)}}}),a.hooks.processAssets.tap({name:C,stage:M.PROCESS_ASSETS_STAGE_ADDITIONS},()=>{a.chunks.forEach(u=>{u.files.add(l)})})})}};var I=h(require("path"),1);var O=h(require("fs"),1),q=h(require("path"),1);function v(t,e,s){let r=q.default.dirname(t);O.default.existsSync(r)||O.default.mkdirSync(r,{recursive:!0}),O.default.writeFileSync(t,e,s)}function N(t){let e=new m(t),s=I.default.join(e.options.output.dir||"",e.options.output.name),r,o,n,w=!1,M=(i,l)=>{let k=e.extract({name:i,content:l});if(k.length){let a=e.css.text;e.insert(k);let u=e.css.text;if(u!==a&&r){v(o,u);let f=()=>{r.ws.send({type:"update",updates:[{path:n,timestamp:Date.now()}]})};w?f():(setTimeout(f,500),w=!0)}}};return{name:"vite-plugin-master-css",enforce:"pre",configureServer(i){r=i},buildStart(){o=I.default.resolve(r?.config.cacheDir??process.cwd(),s),r&&(v(o,""),n=(r.config.cacheDir.slice(process.cwd().length)+"/"+s).replace(/\\/g,"/"))},resolveId(i){if(i.endsWith("master.css?direct"))return"\0"+i},transform(i,l){M(l,i)},transformIndexHtml(i){return i.replace(/(<head>)/,`$1<link rel="stylesheet" href="${n}">`)},async handleHotUpdate(i){M(i.file,await i.read())},generateBundle(){let i=this.emitFile({type:"asset",name:s,source:e.css.text});n="/"+this.getFileName(i)}}}0&&(module.exports={MasterCSSCompiler,MasterCSSVitePlugin,MasterCSSWebpackPlugin});
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/compiler.ts", "../src/options/extract.ts", "../src/options/index.ts", "../src/webpack.ts", "../src/vite.ts", "../src/utils/write-file.ts"],
|
|
4
|
-
"sourcesContent": ["\nexport { default as MasterCSSCompiler } from './compiler'\nexport { default as MasterCSSWebpackPlugin } from './webpack'\nexport { default as MasterCSSVitePlugin } from './vite'\n", "import path from 'path'\nimport chalk from 'chalk'\nimport defaultOptions, { MasterCSSCompilerOptions, MasterCSSCompilerSource } from './options'\nimport MasterCSS, { configure, extend } from '@master/css'\nimport { performance } from 'perf_hooks'\nimport type { MasterCSSConfig } from '@master/css'\n\nexport default class MasterCSSCompiler {\n\n constructor(\n public options: Partial<MasterCSSCompilerOptions>\n ) {\n this.options = extend(defaultOptions, options)\n let userConfig: MasterCSSConfig\n try {\n userConfig = require(path.resolve(process.cwd(), options.config || './master.css.js'))\n // eslint-disable-next-line no-empty\n } catch (err) { }\n this.css = new MasterCSS(configure(userConfig))\n }\n\n css: MasterCSS\n extractions = new Set<string>()\n\n extract({ name, content }: MasterCSSCompilerSource) {\n if (\n !name || !content\n || !this.options.accept?.({ content, name })\n ) {\n return []\n }\n const eachExtractions: string[] = []\n\n this.log('accepts', ` \u2192 ${path.relative(process.cwd(), name)}`)\n\n for (const eachNewExtraction of this.options.extract({ content, name })) {\n if (this.extractions.has(eachNewExtraction)) {\n continue\n } else {\n this.extractions.add(eachNewExtraction)\n eachExtractions.push(eachNewExtraction)\n }\n }\n return eachExtractions\n }\n\n insert(extractions) {\n const p1 = performance.now()\n\n /* \u6839\u64DA\u985E\u540D\u5C0B\u627E\u4E26\u63D2\u5165\u898F\u5247 ( MasterCSS \u672C\u8EAB\u5E36\u6709\u5FEB\u53D6\u6A5F\u5236\uFF0C\u91CD\u8907\u7684\u985E\u540D\u4E0D\u6703\u518D\u7DE8\u8B6F\u53CA\u7522\u751F ) */\n for (const eachExtraction of extractions) {\n this.css.findAndInsert(eachExtraction)\n }\n\n const spent = Math.round((performance.now() - p1) * 1000)\n const validClasses = this.css.rules.map((rule) => rule.className)\n\n /* \u5370\u51FA Master CSS \u7DE8\u8B6F\u6642\u9593 */\n console.log(`[Master CSS] process ${chalk.green(extractions.length)} extractions in ${chalk.green(spent)} \u00B5s [${chalk.green(this.css.rules.length)} rules in ${chalk.green(path.join(this.options.output.dir, this.options.output.name))}]`)\n\n this.log('extractions', ` \u2192 ${chalk.green(extractions.length)} extractions: ${chalk.blue(extractions.join(' '))}`)\n this.log('validClasses', ` \u2192 ${chalk.green(validClasses.length)} total valid classes: ${chalk.blue(validClasses.join(' '))}`)\n }\n\n log(name, content) {\n if (this.options.debug === true || Array.isArray(this.options.debug) && this.options.debug.includes(name)) {\n console.log(content)\n }\n }\n}", "import { defaultSemantics } from '@master/css'\nimport type { MasterCSSCompilerSource } from './index'\n\nexport default function extract({ content }: MasterCSSCompilerSource) {\n const blocks = content.match(/[^\\s]+/g) ?? []\n const strings = new Set<string>()\n for (const block of blocks) {\n const result = peelString(block)\n if (result.size) {\n for (const string of result) {\n strings.add(string)\n }\n } else {\n strings.add(trimString(block))\n }\n }\n return [...strings].filter(x => x && !checkToExclude(x))\n}\n\nconst trimString = (content) => {\n const originContent = content\n content = content.replace(/^([\\w={[(\\\\]*[\"'`])/, '')\n if (!content.match(/^content:((?<!\\\\)[\"'`])((?:\\\\\\1|(?:(?!\\1))[\\S\\s])*)((?<!\\\\)\\1)$/)) {\n content = content.replace(/(\\.*|[([{\\\\:#]*|[\"'`].*)$/, '')\n }\n if (originContent === content) {\n return content\n } else {\n return trimString(content)\n }\n}\n\nconst peelString = (content) => {\n const strings = new Set<string>()\n const stringRegx = /((?<!\\\\)[\"'`])((?:\\\\\\1|(?:(?!\\1))[\\S\\s])*)((?<!\\\\)\\1)/g\n let m\n while ((m = stringRegx.exec(content)) !== null) {\n if (m.index === stringRegx.lastIndex) {\n stringRegx.lastIndex++\n }\n const result = peelString(m[2])\n if (result.size) {\n for (const string of result) {\n strings.add(string)\n }\n } else {\n strings.add(trimString(m[2]))\n }\n }\n return strings\n}\n\nconst checkToExclude = (content) => {\n return !content\n || (!content.match(/(?:^[\\w-]+:[\\w$#]+)|(?:^[@~][\\w-]+$)/) && !Object.keys(defaultSemantics).includes(content))\n || content.match(/\\*\\*/)\n || content.match(/:\\[/)\n || content.match(/\\$\\{/)\n || content.match(/\\{\\{/)\n || content.match(/\\(\\{[^}]*\\}/)\n || content.match(/<\\w+>|<\\/\\w+>/)\n}", "import extract from './extract'\n\nconst defaultOptions: MasterCSSCompilerOptions = {\n output: {\n name: 'master.css',\n dir: ''\n },\n accept({ name }) {\n if (name.match(/[\\\\/]node_modules[\\\\/]/)) {\n return false\n }\n if (name.match(/\\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i)) {\n return true\n }\n },\n extract\n}\n\nexport declare type MasterCSSCompilerSource = {\n name: string\n content: string\n}\n\nexport interface MasterCSSCompilerOptions {\n output?: {\n name: string\n dir: string\n },\n accept?: (source: MasterCSSCompilerSource) => boolean\n extract?: (source: MasterCSSCompilerSource) => string[]\n config?: string\n debug?: string[] | boolean\n}\n\nexport default defaultOptions", "import path from 'path'\nimport MasterCSSCompiler from './compiler'\nimport type { Compiler } from 'webpack'\n\nconst NAME = 'MasterCSSWebpackPlugin'\n\nexport default class MasterCSSWebpackPlugin extends MasterCSSCompiler {\n\n apply(compiler: Compiler) {\n const { webpack } = compiler\n const { Template, RuntimeGlobals, RuntimeModule } = webpack\n const { RawSource } = webpack.sources\n const { Compilation } = webpack\n const { options } = this\n const outputPath = path.join(options.output.dir || '', options.output.name)\n const linkHref = outputPath.replace(/\\\\/g, '/')\n\n compiler.hooks.thisCompilation.tap(NAME, (compilation) => {\n\n const enabledChunks = new WeakSet()\n\n const handler = (chunk, set) => {\n if (enabledChunks.has(chunk))\n return\n\n enabledChunks.add(chunk)\n\n set.add(RuntimeGlobals.publicPath)\n\n compilation.addRuntimeModule(chunk, new CssLoadingRuntimeModule(set))\n }\n\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.ensureChunkHandlers)\n .tap(NAME, handler)\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.hmrDownloadUpdateHandlers)\n .tap(NAME, handler)\n\n class CssLoadingRuntimeModule extends RuntimeModule {\n\n runtimeRequirements: Set<string>\n\n constructor(runtimeRequirements: Set<string>) {\n super('master-css-loading', 10)\n\n this.runtimeRequirements = runtimeRequirements\n }\n\n generate() {\n const { runtimeRequirements } = this\n const withHmr = runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers)\n if (!withHmr)\n return ''\n\n return Template.asString([\n Date.now().toString(),\n `const link = document.querySelector('[href*=\\\\'${linkHref}\\\\'][rel=stylesheet]')`,\n 'if (link) {',\n Template.indent([\n 'link.href = link.href.replace(/ts=[0-9]+/, \\'ts=\\' + Date.now())'\n ]),\n '}'\n ])\n }\n }\n })\n\n compiler.hooks.compilation.tap(NAME, (compilation) => {\n // \u589E\u52A0\u984D\u5916\u7684 `master.css` assets\n compilation.hooks.finishModules.tap(NAME, (modules) => {\n const { modifiedFiles, watching } = compiler\n const eachExtractions: string[] = []\n\n for (const eachModule of modules) {\n const name = eachModule['resource']\n // \u5F9E\u8A18\u61B6\u9AD4\u6216\u5FEB\u53D6\u53D6\u5F97\u7576\u524D module \u7684\u539F\u59CB\u78BC\n const content = eachModule['_source']?.source()\n // \u5728 watch \u6A21\u5F0F\u4E0B\u50C5\u8655\u7406\u7576\u4E0B\u8B8A\u66F4\u7684\u6A94\u6848\n if (watching && modifiedFiles?.size && !modifiedFiles.has(name)) { continue }\n eachExtractions.push(...this.extract({ name, content }))\n }\n\n if (eachExtractions.length) {\n const originalCssText = this.css.text\n /* \u6BD4\u5C0D\u63D0\u53D6\u7269\u4E26\u63D2\u5165 CSS \u898F\u5247 */\n this.insert(eachExtractions)\n /* \u6839\u64DA cssText \u751F\u6210 `master.css` \u4E26\u52A0\u5165\u5230 Webpack \u7684 assets \u4E2D */\n const cssText = this.css.text\n if (cssText !== originalCssText) {\n const newSource = new RawSource(cssText)\n if (compilation.getAsset(outputPath)) {\n compilation.updateAsset(outputPath, newSource)\n } else {\n compilation.emitAsset(outputPath, newSource)\n }\n }\n }\n })\n\n compilation.hooks.processAssets.tap({\n name: NAME,\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n }, () => {\n compilation.chunks.forEach((chunk) => {\n chunk.files.add(outputPath)\n })\n })\n })\n }\n}\n", "import MasterCSSCompiler from './compiler'\nimport path from 'path'\nimport writeFile from './utils/write-file'\nimport type { MasterCSSCompilerOptions } from './options'\nimport type { PluginOption } from 'vite'\n\nexport default function (options?: MasterCSSCompilerOptions): PluginOption {\n const compiler = new MasterCSSCompiler(options)\n const outputPath = path.join(compiler.options.output.dir || '', compiler.options.output.name)\n\n let server\n let outputFilePath: string\n let linkHref: string\n let rendered = false\n\n const extract = (name, content) => {\n const eachExtractions = compiler.extract({ name, content })\n if (eachExtractions.length) {\n const originalCssText = compiler.css.text\n /* \u6BD4\u5C0D\u63D0\u53D6\u7269\u4E26\u63D2\u5165 CSS \u898F\u5247 */\n compiler.insert(eachExtractions)\n /* \u6839\u64DA cssText \u751F\u6210 `master.css` \u4E26\u52A0\u5165\u5230 Webpack \u7684 assets \u4E2D */\n const cssText = compiler.css.text\n if (cssText !== originalCssText) {\n if (server) {\n writeFile(outputFilePath, cssText)\n\n const notify = () => {\n server.ws.send({\n type: 'update',\n updates: [{\n path: linkHref,\n timestamp: Date.now()\n }]\n })\n }\n\n if (rendered) {\n notify()\n } else {\n setTimeout(notify, 500)\n\n rendered = true\n }\n }\n }\n }\n }\n\n return {\n name: 'vite-plugin-master-css',\n enforce: 'pre',\n configureServer(_server) {\n server = _server\n },\n buildStart() {\n outputFilePath = path.resolve(server?.config.cacheDir ?? process.cwd(), outputPath)\n if (server) {\n writeFile(outputFilePath, '')\n\n linkHref = (server.config.cacheDir.slice(process.cwd().length) + '/' + outputPath).replace(/\\\\/g, '/')\n }\n },\n resolveId(source) {\n if (source.endsWith('master.css?direct'))\n return '\\0' + source\n },\n transform(code, id) {\n extract(id, code)\n },\n transformIndexHtml(html) {\n return html.replace(\n /(<head>)/,\n `$1<link rel=\"stylesheet\" href=\"${linkHref}\">`\n )\n },\n async handleHotUpdate(hmrContext) {\n extract(hmrContext.file, await hmrContext.read())\n },\n generateBundle() {\n const referenceId = this.emitFile({\n type: 'asset',\n name: outputPath,\n source: compiler.css.text\n })\n linkHref = '/' + this.getFileName(referenceId)\n }\n }\n}", "import fs from 'fs'\nimport path from 'path'\n\nexport default function writeFile(filePath: string, data: string | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions) {\n const dirname = path.dirname(filePath)\n if (!fs.existsSync(dirname)) {\n fs.mkdirSync(dirname, { recursive: true })\n }\n fs.writeFileSync(filePath, data, options)\n\n}\n"],
|
|
5
|
-
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,wBAAAC,EAAA,2BAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAAiB,
|
|
4
|
+
"sourcesContent": ["\nexport { default as MasterCSSCompiler } from './compiler'\nexport { default as MasterCSSWebpackPlugin } from './webpack'\nexport { default as MasterCSSVitePlugin } from './vite'\n", "import path from 'path'\nimport chalk from 'chalk'\nimport defaultOptions, { MasterCSSCompilerOptions, MasterCSSCompilerSource } from './options'\nimport MasterCSS, { configure, extend } from '@master/css'\nimport { performance } from 'perf_hooks'\nimport type { MasterCSSConfig } from '@master/css'\n\nexport default class MasterCSSCompiler {\n\n constructor(\n public options?: MasterCSSCompilerOptions\n ) {\n this.options = extend(defaultOptions, options)\n let userConfig: MasterCSSConfig\n try {\n userConfig = require(path.resolve(process.cwd(), options.config || './master.css.js'))\n // eslint-disable-next-line no-empty\n } catch (err) { }\n this.css = new MasterCSS(configure(userConfig))\n }\n\n css: MasterCSS\n extractions = new Set<string>()\n\n extract({ name, content }: MasterCSSCompilerSource) {\n if (\n !name || !content\n || !this.options.accept?.({ content, name })\n ) {\n return []\n }\n const eachExtractions: string[] = []\n\n this.log('accepts', ` \u2192 ${path.relative(process.cwd(), name)}`)\n\n for (const eachNewExtraction of this.options.extract({ content, name })) {\n if (this.extractions.has(eachNewExtraction)) {\n continue\n } else {\n this.extractions.add(eachNewExtraction)\n eachExtractions.push(eachNewExtraction)\n }\n }\n return eachExtractions\n }\n\n insert(extractions) {\n const p1 = performance.now()\n\n /* \u6839\u64DA\u985E\u540D\u5C0B\u627E\u4E26\u63D2\u5165\u898F\u5247 ( MasterCSS \u672C\u8EAB\u5E36\u6709\u5FEB\u53D6\u6A5F\u5236\uFF0C\u91CD\u8907\u7684\u985E\u540D\u4E0D\u6703\u518D\u7DE8\u8B6F\u53CA\u7522\u751F ) */\n for (const eachExtraction of extractions) {\n this.css.findAndInsert(eachExtraction)\n }\n\n const spent = Math.round((performance.now() - p1) * 1000)\n const validClasses = this.css.rules.map((rule) => rule.className)\n\n /* \u5370\u51FA Master CSS \u7DE8\u8B6F\u6642\u9593 */\n console.log(`[Master CSS] process ${chalk.green(extractions.length)} extractions in ${chalk.green(spent)} \u00B5s [${chalk.green(this.css.rules.length)} rules in ${chalk.green(path.join(this.options.output.dir, this.options.output.name))}]`)\n\n this.log('extractions', ` \u2192 ${chalk.green(extractions.length)} extractions: ${chalk.blue(extractions.join(' '))}`)\n this.log('validClasses', ` \u2192 ${chalk.green(validClasses.length)} total valid classes: ${chalk.blue(validClasses.join(' '))}`)\n }\n\n log(name, content) {\n if (this.options.debug === true || Array.isArray(this.options.debug) && this.options.debug.includes(name)) {\n console.log(content)\n }\n }\n}", "import { defaultSemantics } from '@master/css'\nimport type { MasterCSSCompilerSource } from './index'\n\nexport default function extract({ content }: MasterCSSCompilerSource) {\n const blocks = content.match(/[^\\s]+/g) ?? []\n const strings = new Set<string>()\n for (const block of blocks) {\n const result = peelString(block)\n if (result.size) {\n for (const string of result) {\n strings.add(string)\n }\n } else {\n strings.add(trimString(block))\n }\n }\n return [...strings].filter(x => x && !checkToExclude(x))\n}\n\nconst trimString = (content) => {\n const originContent = content\n content = content.replace(/^([\\w={[(\\\\]*[\"'`])/, '')\n if (!content.match(/^content:((?<!\\\\)[\"'`])((?:\\\\\\1|(?:(?!\\1))[\\S\\s])*)((?<!\\\\)\\1)$/)) {\n content = content.replace(/(\\.*|[([{\\\\:#]*|[\"'`].*)$/, '')\n }\n if (originContent === content) {\n return content\n } else {\n return trimString(content)\n }\n}\n\nconst peelString = (content) => {\n const strings = new Set<string>()\n const stringRegx = /((?<!\\\\)[\"'`])((?:\\\\\\1|(?:(?!\\1))[\\S\\s])*)((?<!\\\\)\\1)/g\n let m\n while ((m = stringRegx.exec(content)) !== null) {\n if (m.index === stringRegx.lastIndex) {\n stringRegx.lastIndex++\n }\n const result = peelString(m[2])\n if (result.size) {\n for (const string of result) {\n strings.add(string)\n }\n } else {\n strings.add(trimString(m[2]))\n }\n }\n return strings\n}\n\nconst checkToExclude = (content) => {\n return !content\n || (!content.match(/(?:^[\\w-]+:[\\w$#]+)|(?:^[@~][\\w-]+$)/) && !Object.keys(defaultSemantics).includes(content))\n || content.match(/\\*\\*/)\n || content.match(/:\\[/)\n || content.match(/\\$\\{/)\n || content.match(/\\{\\{/)\n || content.match(/\\(\\{[^}]*\\}/)\n || content.match(/<\\w+>|<\\/\\w+>/)\n}", "import extract from './extract'\n\nconst defaultOptions: MasterCSSCompilerOptions = {\n output: {\n name: 'master.css',\n dir: ''\n },\n accept({ name }) {\n if (name.match(/[\\\\/]node_modules[\\\\/]/)) {\n return false\n }\n if (name.match(/\\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i)) {\n return true\n }\n },\n extract\n}\n\nexport declare type MasterCSSCompilerSource = {\n name: string\n content: string\n}\n\nexport interface MasterCSSCompilerOptions {\n output?: {\n name: string\n dir: string\n },\n accept?: (source: MasterCSSCompilerSource) => boolean\n extract?: (source: MasterCSSCompilerSource) => string[]\n config?: string\n debug?: string[] | boolean\n}\n\nexport default defaultOptions", "import path from 'path'\nimport MasterCSSCompiler from './compiler'\nimport type { Compiler } from 'webpack'\n\nconst NAME = 'MasterCSSWebpackPlugin'\n\nexport default class MasterCSSWebpackPlugin extends MasterCSSCompiler {\n\n apply(compiler: Compiler) {\n const { webpack } = compiler\n const { Template, RuntimeGlobals, RuntimeModule } = webpack\n const { RawSource } = webpack.sources\n const { Compilation } = webpack\n const { options } = this\n const outputPath = path.join(options.output.dir || '', options.output.name)\n const linkHref = outputPath.replace(/\\\\/g, '/')\n\n compiler.hooks.thisCompilation.tap(NAME, (compilation) => {\n\n const enabledChunks = new WeakSet()\n\n const handler = (chunk, set) => {\n if (enabledChunks.has(chunk))\n return\n\n enabledChunks.add(chunk)\n\n set.add(RuntimeGlobals.publicPath)\n\n compilation.addRuntimeModule(chunk, new CssLoadingRuntimeModule(set))\n }\n\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.ensureChunkHandlers)\n .tap(NAME, handler)\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.hmrDownloadUpdateHandlers)\n .tap(NAME, handler)\n\n class CssLoadingRuntimeModule extends RuntimeModule {\n\n runtimeRequirements: Set<string>\n\n constructor(runtimeRequirements: Set<string>) {\n super('master-css-loading', 10)\n\n this.runtimeRequirements = runtimeRequirements\n }\n\n generate() {\n const { runtimeRequirements } = this\n const withHmr = runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers)\n if (!withHmr)\n return ''\n\n return Template.asString([\n Date.now().toString(),\n `const link = document.querySelector('[href*=\\\\'${linkHref}\\\\'][rel=stylesheet]')`,\n 'if (link) {',\n Template.indent([\n 'link.href = link.href.replace(/ts=[0-9]+/, \\'ts=\\' + Date.now())'\n ]),\n '}'\n ])\n }\n }\n })\n\n compiler.hooks.compilation.tap(NAME, (compilation) => {\n // \u589E\u52A0\u984D\u5916\u7684 `master.css` assets\n compilation.hooks.finishModules.tap(NAME, (modules) => {\n const { modifiedFiles, watching } = compiler\n const eachExtractions: string[] = []\n\n for (const eachModule of modules) {\n const name = eachModule['resource']\n // \u5F9E\u8A18\u61B6\u9AD4\u6216\u5FEB\u53D6\u53D6\u5F97\u7576\u524D module \u7684\u539F\u59CB\u78BC\n const content = eachModule['_source']?.source()\n // \u5728 watch \u6A21\u5F0F\u4E0B\u50C5\u8655\u7406\u7576\u4E0B\u8B8A\u66F4\u7684\u6A94\u6848\n if (watching && modifiedFiles?.size && !modifiedFiles.has(name)) { continue }\n eachExtractions.push(...this.extract({ name, content }))\n }\n\n if (eachExtractions.length) {\n const originalCssText = this.css.text\n /* \u6BD4\u5C0D\u63D0\u53D6\u7269\u4E26\u63D2\u5165 CSS \u898F\u5247 */\n this.insert(eachExtractions)\n /* \u6839\u64DA cssText \u751F\u6210 `master.css` \u4E26\u52A0\u5165\u5230 Webpack \u7684 assets \u4E2D */\n const cssText = this.css.text\n if (cssText !== originalCssText) {\n const newSource = new RawSource(cssText)\n if (compilation.getAsset(outputPath)) {\n compilation.updateAsset(outputPath, newSource)\n } else {\n compilation.emitAsset(outputPath, newSource)\n }\n }\n }\n })\n\n compilation.hooks.processAssets.tap({\n name: NAME,\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n }, () => {\n compilation.chunks.forEach((chunk) => {\n chunk.files.add(outputPath)\n })\n })\n })\n }\n}\n", "import MasterCSSCompiler from './compiler'\nimport path from 'path'\nimport writeFile from './utils/write-file'\nimport type { MasterCSSCompilerOptions } from './options'\nimport type { PluginOption } from 'vite'\n\nexport default function (options?: MasterCSSCompilerOptions): PluginOption {\n const compiler = new MasterCSSCompiler(options)\n const outputPath = path.join(compiler.options.output.dir || '', compiler.options.output.name)\n\n let server\n let outputFilePath: string\n let linkHref: string\n let rendered = false\n\n const extract = (name, content) => {\n const eachExtractions = compiler.extract({ name, content })\n if (eachExtractions.length) {\n const originalCssText = compiler.css.text\n /* \u6BD4\u5C0D\u63D0\u53D6\u7269\u4E26\u63D2\u5165 CSS \u898F\u5247 */\n compiler.insert(eachExtractions)\n /* \u6839\u64DA cssText \u751F\u6210 `master.css` \u4E26\u52A0\u5165\u5230 Webpack \u7684 assets \u4E2D */\n const cssText = compiler.css.text\n if (cssText !== originalCssText) {\n if (server) {\n writeFile(outputFilePath, cssText)\n\n const notify = () => {\n server.ws.send({\n type: 'update',\n updates: [{\n path: linkHref,\n timestamp: Date.now()\n }]\n })\n }\n\n if (rendered) {\n notify()\n } else {\n setTimeout(notify, 500)\n\n rendered = true\n }\n }\n }\n }\n }\n\n return {\n name: 'vite-plugin-master-css',\n enforce: 'pre',\n configureServer(_server) {\n server = _server\n },\n buildStart() {\n outputFilePath = path.resolve(server?.config.cacheDir ?? process.cwd(), outputPath)\n if (server) {\n writeFile(outputFilePath, '')\n\n linkHref = (server.config.cacheDir.slice(process.cwd().length) + '/' + outputPath).replace(/\\\\/g, '/')\n }\n },\n resolveId(source) {\n if (source.endsWith('master.css?direct'))\n return '\\0' + source\n },\n transform(code, id) {\n extract(id, code)\n },\n transformIndexHtml(html) {\n return html.replace(\n /(<head>)/,\n `$1<link rel=\"stylesheet\" href=\"${linkHref}\">`\n )\n },\n async handleHotUpdate(hmrContext) {\n extract(hmrContext.file, await hmrContext.read())\n },\n generateBundle() {\n const referenceId = this.emitFile({\n type: 'asset',\n name: outputPath,\n source: compiler.css.text\n })\n linkHref = '/' + this.getFileName(referenceId)\n }\n } as PluginOption\n}", "import fs from 'fs'\nimport path from 'path'\n\nexport default function writeFile(filePath: string, data: string | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions) {\n const dirname = path.dirname(filePath)\n if (!fs.existsSync(dirname)) {\n fs.mkdirSync(dirname, { recursive: true })\n }\n fs.writeFileSync(filePath, data, options)\n\n}\n"],
|
|
5
|
+
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,wBAAAC,EAAA,2BAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAAiB,qBACjBC,EAAkB,sBCDlB,IAAAC,EAAiC,uBAGlB,SAARC,EAAyB,CAAE,QAAAC,CAAQ,EAA4B,CAClE,IAAMC,EAASD,EAAQ,MAAM,SAAS,GAAK,CAAC,EACtCE,EAAU,IAAI,IACpB,QAAWC,KAASF,EAAQ,CACxB,IAAMG,EAASC,EAAWF,CAAK,EAC/B,GAAIC,EAAO,KACP,QAAWE,KAAUF,EACjBF,EAAQ,IAAII,CAAM,OAGtBJ,EAAQ,IAAIK,EAAWJ,CAAK,CAAC,CAErC,CACA,MAAO,CAAC,GAAGD,CAAO,EAAE,OAAOM,GAAKA,GAAK,CAACC,EAAeD,CAAC,CAAC,CAC3D,CAEA,IAAMD,EAAcP,GAAY,CAC5B,IAAMU,EAAgBV,EAK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EAAQ,CACd,GAAIA,EAAO,SAAS,mBAAmB,EACnC,MAAO,KAAOA,CACtB,EACA,UAAUC,EAAMC,EAAI,CAChBX,EAAQW,EAAID,CAAI,CACpB,EACA,mBAAmBE,EAAM,CACrB,OAAOA,EAAK,QACR,WACA,kCAAkCd,KACtC,CACJ,EACA,MAAM,gBAAgBe,EAAY,CAC9Bb,EAAQa,EAAW,KAAM,MAAMA,EAAW,KAAK,CAAC,CACpD,EACA,gBAAiB,CACb,IAAMC,EAAc,KAAK,SAAS,CAC9B,KAAM,QACN,KAAMpB,EACN,OAAQF,EAAS,IAAI,IACzB,CAAC,EACDM,EAAW,IAAM,KAAK,YAAYgB,CAAW,CACjD,CACJ,CACJ",
|
|
6
6
|
"names": ["src_exports", "__export", "MasterCSSCompiler", "vite_default", "MasterCSSWebpackPlugin", "__toCommonJS", "import_path", "import_chalk", "import_css", "extract", "content", "blocks", "strings", "block", "result", "peelString", "string", "trimString", "x", "checkToExclude", "originContent", "stringRegx", "m", "defaultOptions", "name", "extract", "options_default", "import_css", "import_perf_hooks", "MasterCSSCompiler", "options", "options_default", "userConfig", "path", "MasterCSS", "name", "content", "eachExtractions", "eachNewExtraction", "extractions", "p1", "eachExtraction", "spent", "validClasses", "rule", "chalk", "import_path", "NAME", "MasterCSSWebpackPlugin", "MasterCSSCompiler", "compiler", "webpack", "Template", "RuntimeGlobals", "RuntimeModule", "RawSource", "Compilation", "options", "outputPath", "path", "linkHref", "compilation", "enabledChunks", "handler", "chunk", "set", "CssLoadingRuntimeModule", "runtimeRequirements", "modules", "modifiedFiles", "watching", "eachExtractions", "eachModule", "name", "content", "originalCssText", "cssText", "newSource", "import_path", "import_fs", "import_path", "writeFile", "filePath", "data", "options", "dirname", "path", "fs", "vite_default", "options", "compiler", "MasterCSSCompiler", "outputPath", "path", "server", "outputFilePath", "linkHref", "rendered", "extract", "name", "content", "eachExtractions", "originalCssText", "cssText", "writeFile", "notify", "_server", "source", "code", "id", "html", "hmrContext", "referenceId"]
|
|
7
7
|
}
|
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var A=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,s)=>(typeof require<"u"?require:e)[s]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});import O from"path";import f from"chalk";import{defaultSemantics as j}from"@master/css";function b({content:t}){let e=t.match(/[^\s]+/g)??[],s=new Set;for(let r of e){let o=R(r);if(o.size)for(let n of o)s.add(n);else s.add($(r))}return[...s].filter(r=>r&&!D(r))}var $=t=>{let e=t;return t=t.replace(/^([\w={[(\\]*["'`])/,""),t.match(/^content:((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)$/)||(t=t.replace(/(\.*|[([{\\:#]*|["'`].*)$/,"")),e===t?t:$(t)},R=t=>{let e=new Set,s=/((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)/g,r;for(;(r=s.exec(t))!==null;){r.index===s.lastIndex&&s.lastIndex++;let o=R(r[2]);if(o.size)for(let n of o)e.add(n);else e.add($(r[2]))}return e},D=t=>!t||!t.match(/(?:^[\w-]+:[\w$#]+)|(?:^[@~][\w-]+$)/)&&!Object.keys(j).includes(t)||t.match(/\*\*/)||t.match(/:\[/)||t.match(/\$\{/)||t.match(/\{\{/)||t.match(/\(\{[^}]*\}/)||t.match(/<\w+>|<\/\w+>/);var H={output:{name:"master.css",dir:""},accept({name:t}){if(t.match(/[\\/]node_modules[\\/]/))return!1;if(t.match(/\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i))return!0},extract:b},T=H;import P,{configure as F,extend as q}from"@master/css";import{performance as E}from"perf_hooks";var d=class{constructor(e){this.options=e;this.options=q(T,e);let s;try{s=A(O.resolve(process.cwd(),e.config||"./master.css.js"))}catch{}this.css=new P(F(s))}css;extractions=new Set;extract({name:e,content:s}){if(!e||!s||!this.options.accept?.({content:s,name:e}))return[];let r=[];this.log("accepts",` \u2192 ${O.relative(process.cwd(),e)}`);for(let o of this.options.extract({content:s,name:e}))this.extractions.has(o)||(this.extractions.add(o),r.push(o));return r}insert(e){let s=E.now();for(let n of e)this.css.findAndInsert(n);let r=Math.round((E.now()-s)*1e3),o=this.css.rules.map(n=>n.className);console.log(`[Master CSS] process ${f.green(e.length)} extractions in ${f.green(r)} \xB5s [${f.green(this.css.rules.length)} rules in ${f.green(O.join(this.options.output.dir,this.options.output.name))}]`),this.log("extractions",` \u2192 ${f.green(e.length)} extractions: ${f.blue(e.join(" "))}`),this.log("validClasses",` \u2192 ${f.green(o.length)} total valid classes: ${f.blue(o.join(" "))}`)}log(e,s){(this.options.debug===!0||Array.isArray(this.options.debug)&&this.options.debug.includes(e))&&console.log(s)}};import N from"path";var g="MasterCSSWebpackPlugin",M=class extends d{apply(e){let{webpack:s}=e,{Template:r,RuntimeGlobals:o,RuntimeModule:n}=s,{RawSource:S}=s.sources,{Compilation:C}=s,{options:i}=this,l=N.join(i.output.dir||"",i.output.name),x=l.replace(/\\/g,"/");e.hooks.thisCompilation.tap(g,a=>{let u=new WeakSet,p=(m,c)=>{u.has(m)||(u.add(m),c.add(o.publicPath),a.addRuntimeModule(m,new y(c)))};a.hooks.runtimeRequirementInTree.for(o.ensureChunkHandlers).tap(g,p),a.hooks.runtimeRequirementInTree.for(o.hmrDownloadUpdateHandlers).tap(g,p);class y extends n{runtimeRequirements;constructor(c){super("master-css-loading",10),this.runtimeRequirements=c}generate(){let{runtimeRequirements:c}=this;return c.has(o.hmrDownloadUpdateHandlers)?r.asString([Date.now().toString(),`const link = document.querySelector('[href*=\\'${x}\\'][rel=stylesheet]')`,"if (link) {",r.indent(["link.href = link.href.replace(/ts=[0-9]+/, 'ts=' + Date.now())"]),"}"]):""}}}),e.hooks.compilation.tap(g,a=>{a.hooks.finishModules.tap(g,u=>{let{modifiedFiles:p,watching:y}=e,m=[];for(let c of u){let h=c.resource,w=c._source?.source();y&&p?.size&&!p.has(h)||m.push(...this.extract({name:h,content:w}))}if(m.length){let c=this.css.text;this.insert(m);let h=this.css.text;if(h!==c){let w=new S(h);a.getAsset(l)?a.updateAsset(l,w):a.emitAsset(l,w)}}}),a.hooks.processAssets.tap({name:g,stage:C.PROCESS_ASSETS_STAGE_ADDITIONS},()=>{a.chunks.forEach(u=>{u.files.add(l)})})})}};import I from"path";import v from"fs";import _ from"path";function k(t,e,s){let r=_.dirname(t);v.existsSync(r)||v.mkdirSync(r,{recursive:!0}),v.writeFileSync(t,e,s)}function W(t){let e=new d(t),s=I.join(e.options.output.dir||"",e.options.output.name),r,o,n,S=!1,C=(i,l)=>{let x=e.extract({name:i,content:l});if(x.length){let a=e.css.text;e.insert(x);let u=e.css.text;if(u!==a&&r){k(o,u);let p=()=>{r.ws.send({type:"update",updates:[{path:n,timestamp:Date.now()}]})};S?p():(setTimeout(p,500),S=!0)}}};return{name:"vite-plugin-master-css",enforce:"pre",configureServer(i){r=i},buildStart(){o=I.resolve(r?.config.cacheDir??process.cwd(),s),r&&(k(o,""),n=(r.config.cacheDir.slice(process.cwd().length)+"/"+s).replace(/\\/g,"/"))},resolveId(i){if(i.endsWith("master.css?direct"))return"\0"+i},transform(i,l){C(l,i)},transformIndexHtml(i){return i.replace(/(<head>)/,`$1<link rel="stylesheet" href="${n}">`)},async handleHotUpdate(i){C(i.file,await i.read())},generateBundle(){let i=this.emitFile({type:"asset",name:s,source:e.css.text});n="/"+this.getFileName(i)}}}export{d as MasterCSSCompiler,W as MasterCSSVitePlugin,M as MasterCSSWebpackPlugin};
|
|
2
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/compiler.ts", "../src/options/extract.ts", "../src/options/index.ts", "../src/webpack.ts", "../src/vite.ts", "../src/utils/write-file.ts"],
|
|
4
|
+
"sourcesContent": ["import path from 'path'\nimport chalk from 'chalk'\nimport defaultOptions, { MasterCSSCompilerOptions, MasterCSSCompilerSource } from './options'\nimport MasterCSS, { configure, extend } from '@master/css'\nimport { performance } from 'perf_hooks'\nimport type { MasterCSSConfig } from '@master/css'\n\nexport default class MasterCSSCompiler {\n\n constructor(\n public options?: MasterCSSCompilerOptions\n ) {\n this.options = extend(defaultOptions, options)\n let userConfig: MasterCSSConfig\n try {\n userConfig = require(path.resolve(process.cwd(), options.config || './master.css.js'))\n // eslint-disable-next-line no-empty\n } catch (err) { }\n this.css = new MasterCSS(configure(userConfig))\n }\n\n css: MasterCSS\n extractions = new Set<string>()\n\n extract({ name, content }: MasterCSSCompilerSource) {\n if (\n !name || !content\n || !this.options.accept?.({ content, name })\n ) {\n return []\n }\n const eachExtractions: string[] = []\n\n this.log('accepts', ` \u2192 ${path.relative(process.cwd(), name)}`)\n\n for (const eachNewExtraction of this.options.extract({ content, name })) {\n if (this.extractions.has(eachNewExtraction)) {\n continue\n } else {\n this.extractions.add(eachNewExtraction)\n eachExtractions.push(eachNewExtraction)\n }\n }\n return eachExtractions\n }\n\n insert(extractions) {\n const p1 = performance.now()\n\n /* \u6839\u64DA\u985E\u540D\u5C0B\u627E\u4E26\u63D2\u5165\u898F\u5247 ( MasterCSS \u672C\u8EAB\u5E36\u6709\u5FEB\u53D6\u6A5F\u5236\uFF0C\u91CD\u8907\u7684\u985E\u540D\u4E0D\u6703\u518D\u7DE8\u8B6F\u53CA\u7522\u751F ) */\n for (const eachExtraction of extractions) {\n this.css.findAndInsert(eachExtraction)\n }\n\n const spent = Math.round((performance.now() - p1) * 1000)\n const validClasses = this.css.rules.map((rule) => rule.className)\n\n /* \u5370\u51FA Master CSS \u7DE8\u8B6F\u6642\u9593 */\n console.log(`[Master CSS] process ${chalk.green(extractions.length)} extractions in ${chalk.green(spent)} \u00B5s [${chalk.green(this.css.rules.length)} rules in ${chalk.green(path.join(this.options.output.dir, this.options.output.name))}]`)\n\n this.log('extractions', ` \u2192 ${chalk.green(extractions.length)} extractions: ${chalk.blue(extractions.join(' '))}`)\n this.log('validClasses', ` \u2192 ${chalk.green(validClasses.length)} total valid classes: ${chalk.blue(validClasses.join(' '))}`)\n }\n\n log(name, content) {\n if (this.options.debug === true || Array.isArray(this.options.debug) && this.options.debug.includes(name)) {\n console.log(content)\n }\n }\n}", "import { defaultSemantics } from '@master/css'\nimport type { MasterCSSCompilerSource } from './index'\n\nexport default function extract({ content }: MasterCSSCompilerSource) {\n const blocks = content.match(/[^\\s]+/g) ?? []\n const strings = new Set<string>()\n for (const block of blocks) {\n const result = peelString(block)\n if (result.size) {\n for (const string of result) {\n strings.add(string)\n }\n } else {\n strings.add(trimString(block))\n }\n }\n return [...strings].filter(x => x && !checkToExclude(x))\n}\n\nconst trimString = (content) => {\n const originContent = content\n content = content.replace(/^([\\w={[(\\\\]*[\"'`])/, '')\n if (!content.match(/^content:((?<!\\\\)[\"'`])((?:\\\\\\1|(?:(?!\\1))[\\S\\s])*)((?<!\\\\)\\1)$/)) {\n content = content.replace(/(\\.*|[([{\\\\:#]*|[\"'`].*)$/, '')\n }\n if (originContent === content) {\n return content\n } else {\n return trimString(content)\n }\n}\n\nconst peelString = (content) => {\n const strings = new Set<string>()\n const stringRegx = /((?<!\\\\)[\"'`])((?:\\\\\\1|(?:(?!\\1))[\\S\\s])*)((?<!\\\\)\\1)/g\n let m\n while ((m = stringRegx.exec(content)) !== null) {\n if (m.index === stringRegx.lastIndex) {\n stringRegx.lastIndex++\n }\n const result = peelString(m[2])\n if (result.size) {\n for (const string of result) {\n strings.add(string)\n }\n } else {\n strings.add(trimString(m[2]))\n }\n }\n return strings\n}\n\nconst checkToExclude = (content) => {\n return !content\n || (!content.match(/(?:^[\\w-]+:[\\w$#]+)|(?:^[@~][\\w-]+$)/) && !Object.keys(defaultSemantics).includes(content))\n || content.match(/\\*\\*/)\n || content.match(/:\\[/)\n || content.match(/\\$\\{/)\n || content.match(/\\{\\{/)\n || content.match(/\\(\\{[^}]*\\}/)\n || content.match(/<\\w+>|<\\/\\w+>/)\n}", "import extract from './extract'\n\nconst defaultOptions: MasterCSSCompilerOptions = {\n output: {\n name: 'master.css',\n dir: ''\n },\n accept({ name }) {\n if (name.match(/[\\\\/]node_modules[\\\\/]/)) {\n return false\n }\n if (name.match(/\\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i)) {\n return true\n }\n },\n extract\n}\n\nexport declare type MasterCSSCompilerSource = {\n name: string\n content: string\n}\n\nexport interface MasterCSSCompilerOptions {\n output?: {\n name: string\n dir: string\n },\n accept?: (source: MasterCSSCompilerSource) => boolean\n extract?: (source: MasterCSSCompilerSource) => string[]\n config?: string\n debug?: string[] | boolean\n}\n\nexport default defaultOptions", "import path from 'path'\nimport MasterCSSCompiler from './compiler'\nimport type { Compiler } from 'webpack'\n\nconst NAME = 'MasterCSSWebpackPlugin'\n\nexport default class MasterCSSWebpackPlugin extends MasterCSSCompiler {\n\n apply(compiler: Compiler) {\n const { webpack } = compiler\n const { Template, RuntimeGlobals, RuntimeModule } = webpack\n const { RawSource } = webpack.sources\n const { Compilation } = webpack\n const { options } = this\n const outputPath = path.join(options.output.dir || '', options.output.name)\n const linkHref = outputPath.replace(/\\\\/g, '/')\n\n compiler.hooks.thisCompilation.tap(NAME, (compilation) => {\n\n const enabledChunks = new WeakSet()\n\n const handler = (chunk, set) => {\n if (enabledChunks.has(chunk))\n return\n\n enabledChunks.add(chunk)\n\n set.add(RuntimeGlobals.publicPath)\n\n compilation.addRuntimeModule(chunk, new CssLoadingRuntimeModule(set))\n }\n\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.ensureChunkHandlers)\n .tap(NAME, handler)\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.hmrDownloadUpdateHandlers)\n .tap(NAME, handler)\n\n class CssLoadingRuntimeModule extends RuntimeModule {\n\n runtimeRequirements: Set<string>\n\n constructor(runtimeRequirements: Set<string>) {\n super('master-css-loading', 10)\n\n this.runtimeRequirements = runtimeRequirements\n }\n\n generate() {\n const { runtimeRequirements } = this\n const withHmr = runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers)\n if (!withHmr)\n return ''\n\n return Template.asString([\n Date.now().toString(),\n `const link = document.querySelector('[href*=\\\\'${linkHref}\\\\'][rel=stylesheet]')`,\n 'if (link) {',\n Template.indent([\n 'link.href = link.href.replace(/ts=[0-9]+/, \\'ts=\\' + Date.now())'\n ]),\n '}'\n ])\n }\n }\n })\n\n compiler.hooks.compilation.tap(NAME, (compilation) => {\n // \u589E\u52A0\u984D\u5916\u7684 `master.css` assets\n compilation.hooks.finishModules.tap(NAME, (modules) => {\n const { modifiedFiles, watching } = compiler\n const eachExtractions: string[] = []\n\n for (const eachModule of modules) {\n const name = eachModule['resource']\n // \u5F9E\u8A18\u61B6\u9AD4\u6216\u5FEB\u53D6\u53D6\u5F97\u7576\u524D module \u7684\u539F\u59CB\u78BC\n const content = eachModule['_source']?.source()\n // \u5728 watch \u6A21\u5F0F\u4E0B\u50C5\u8655\u7406\u7576\u4E0B\u8B8A\u66F4\u7684\u6A94\u6848\n if (watching && modifiedFiles?.size && !modifiedFiles.has(name)) { continue }\n eachExtractions.push(...this.extract({ name, content }))\n }\n\n if (eachExtractions.length) {\n const originalCssText = this.css.text\n /* \u6BD4\u5C0D\u63D0\u53D6\u7269\u4E26\u63D2\u5165 CSS \u898F\u5247 */\n this.insert(eachExtractions)\n /* \u6839\u64DA cssText \u751F\u6210 `master.css` \u4E26\u52A0\u5165\u5230 Webpack \u7684 assets \u4E2D */\n const cssText = this.css.text\n if (cssText !== originalCssText) {\n const newSource = new RawSource(cssText)\n if (compilation.getAsset(outputPath)) {\n compilation.updateAsset(outputPath, newSource)\n } else {\n compilation.emitAsset(outputPath, newSource)\n }\n }\n }\n })\n\n compilation.hooks.processAssets.tap({\n name: NAME,\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n }, () => {\n compilation.chunks.forEach((chunk) => {\n chunk.files.add(outputPath)\n })\n })\n })\n }\n}\n", "import MasterCSSCompiler from './compiler'\nimport path from 'path'\nimport writeFile from './utils/write-file'\nimport type { MasterCSSCompilerOptions } from './options'\nimport type { PluginOption } from 'vite'\n\nexport default function (options?: MasterCSSCompilerOptions): PluginOption {\n const compiler = new MasterCSSCompiler(options)\n const outputPath = path.join(compiler.options.output.dir || '', compiler.options.output.name)\n\n let server\n let outputFilePath: string\n let linkHref: string\n let rendered = false\n\n const extract = (name, content) => {\n const eachExtractions = compiler.extract({ name, content })\n if (eachExtractions.length) {\n const originalCssText = compiler.css.text\n /* \u6BD4\u5C0D\u63D0\u53D6\u7269\u4E26\u63D2\u5165 CSS \u898F\u5247 */\n compiler.insert(eachExtractions)\n /* \u6839\u64DA cssText \u751F\u6210 `master.css` \u4E26\u52A0\u5165\u5230 Webpack \u7684 assets \u4E2D */\n const cssText = compiler.css.text\n if (cssText !== originalCssText) {\n if (server) {\n writeFile(outputFilePath, cssText)\n\n const notify = () => {\n server.ws.send({\n type: 'update',\n updates: [{\n path: linkHref,\n timestamp: Date.now()\n }]\n })\n }\n\n if (rendered) {\n notify()\n } else {\n setTimeout(notify, 500)\n\n rendered = true\n }\n }\n }\n }\n }\n\n return {\n name: 'vite-plugin-master-css',\n enforce: 'pre',\n configureServer(_server) {\n server = _server\n },\n buildStart() {\n outputFilePath = path.resolve(server?.config.cacheDir ?? process.cwd(), outputPath)\n if (server) {\n writeFile(outputFilePath, '')\n\n linkHref = (server.config.cacheDir.slice(process.cwd().length) + '/' + outputPath).replace(/\\\\/g, '/')\n }\n },\n resolveId(source) {\n if (source.endsWith('master.css?direct'))\n return '\\0' + source\n },\n transform(code, id) {\n extract(id, code)\n },\n transformIndexHtml(html) {\n return html.replace(\n /(<head>)/,\n `$1<link rel=\"stylesheet\" href=\"${linkHref}\">`\n )\n },\n async handleHotUpdate(hmrContext) {\n extract(hmrContext.file, await hmrContext.read())\n },\n generateBundle() {\n const referenceId = this.emitFile({\n type: 'asset',\n name: outputPath,\n source: compiler.css.text\n })\n linkHref = '/' + this.getFileName(referenceId)\n }\n } as PluginOption\n}", "import fs from 'fs'\nimport path from 'path'\n\nexport default function writeFile(filePath: string, data: string | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions) {\n const dirname = path.dirname(filePath)\n if (!fs.existsSync(dirname)) {\n fs.mkdirSync(dirname, { recursive: true })\n }\n fs.writeFileSync(filePath, data, options)\n\n}\n"],
|
|
5
|
+
"mappings": "6PAAA,OAAOA,MAAU,OACjB,OAAOC,MAAW,QCDlB,OAAS,oBAAAC,MAAwB,cAGlB,SAARC,EAAyB,CAAE,QAAAC,CAAQ,EAA4B,CAClE,IAAMC,EAASD,EAAQ,MAAM,SAAS,GAAK,CAAC,EACtCE,EAAU,IAAI,IACpB,QAAWC,KAASF,EAAQ,CACxB,IAAMG,EAASC,EAAWF,CAAK,EAC/B,GAAIC,EAAO,KACP,QAAWE,KAAUF,EACjBF,EAAQ,IAAII,CAAM,OAGtBJ,EAAQ,IAAIK,EAAWJ,CAAK,CAAC,CAErC,CACA,MAAO,CAAC,GAAGD,CAAO,EAAE,OAAOM,GAAKA,GAAK,CAACC,EAAeD,CAAC,CAAC,CAC3D,CAEA,IAAMD,EAAcP,GAAY,CAC5B,IAAMU,EAAgBV,EAKtB,OAJAA,EAAUA,EAAQ,QAAQ,sBAAuB,EAAE,EAC9CA,EAAQ,MAAM,iEAAiE,IAChFA,EAAUA,EAAQ,QAAQ,4BAA6B,EAAE,GAEzDU,IAAkBV,EACXA,EAEAO,EAAWP,CAAO,CAEjC,EAEMK,EAAcL,GAAY,CAC5B,IAAME,EAAU,IAAI,IACdS,EAAa,yDACfC,EACJ,MAAQA,EAAID,EAAW,KAAKX,CAAO,KAAO,MAAM,CACxCY,EAAE,QAAUD,EAAW,WACvBA,EAAW,YAEf,IAAMP,EAASC,EAAWO,EAAE,EAAE,EAC9B,GAAIR,EAAO,KACP,QAAWE,KAAUF,EACjBF,EAAQ,IAAII,CAAM,OAGtBJ,EAAQ,IAAIK,EAAWK,EAAE,EAAE,CAA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C,EAAkBZ,EAAS,IAAI,KAErCA,EAAS,OAAOW,CAAe,EAE/B,IAAME,EAAUb,EAAS,IAAI,KAC7B,GAAIa,IAAYD,GACRR,EAAQ,CACRU,EAAUT,EAAgBQ,CAAO,EAEjC,IAAME,EAAS,IAAM,CACjBX,EAAO,GAAG,KAAK,CACX,KAAM,SACN,QAAS,CAAC,CACN,KAAME,EACN,UAAW,KAAK,IAAI,CACxB,CAAC,CACL,CAAC,CACL,EAEIC,EACAQ,EAAO,GAEP,WAAWA,EAAQ,GAAG,EAEtBR,EAAW,GAEnB,CAER,CACJ,EAEA,MAAO,CACH,KAAM,yBACN,QAAS,MACT,gBAAgBS,EAAS,CACrBZ,EAASY,CACb,EACA,YAAa,CACTX,EAAiBF,EAAK,QAAQC,GAAQ,OAAO,UAAY,QAAQ,IAAI,EAAGF,CAAU,EAC9EE,IACAU,EAAUT,EAAgB,EAAE,EAE5BC,GAAYF,EAAO,OAAO,SAAS,MAAM,QAAQ,IAAI,EAAE,MAAM,EAAI,IAAMF,GAAY,QAAQ,MAAO,GAAG,EAE7G,EACA,UAAUe,EAAQ,CACd,GAAIA,EAAO,SAAS,mBAAmB,EACnC,MAAO,KAAOA,CACtB,EACA,UAAUC,EAAMC,EAAI,CAChBX,EAAQW,EAAID,CAAI,CACpB,EACA,mBAAmBE,EAAM,CACrB,OAAOA,EAAK,QACR,WACA,kCAAkCd,KACtC,CACJ,EACA,MAAM,gBAAgBe,EAAY,CAC9Bb,EAAQa,EAAW,KAAM,MAAMA,EAAW,KAAK,CAAC,CACpD,EACA,gBAAiB,CACb,IAAMC,EAAc,KAAK,SAAS,CAC9B,KAAM,QACN,KAAMpB,EACN,OAAQF,EAAS,IAAI,IACzB,CAAC,EACDM,EAAW,IAAM,KAAK,YAAYgB,CAAW,CACjD,CACJ,CACJ",
|
|
6
|
+
"names": ["path", "chalk", "defaultSemantics", "extract", "content", "blocks", "strings", "block", "result", "peelString", "string", "trimString", "x", "checkToExclude", "originContent", "stringRegx", "m", "defaultOptions", "name", "extract", "options_default", "MasterCSS", "configure", "extend", "performance", "MasterCSSCompiler", "options", "extend", "options_default", "userConfig", "__require", "path", "MasterCSS", "configure", "name", "content", "eachExtractions", "eachNewExtraction", "extractions", "p1", "performance", "eachExtraction", "spent", "validClasses", "rule", "chalk", "path", "NAME", "MasterCSSWebpackPlugin", "MasterCSSCompiler", "compiler", "webpack", "Template", "RuntimeGlobals", "RuntimeModule", "RawSource", "Compilation", "options", "outputPath", "path", "linkHref", "compilation", "enabledChunks", "handler", "chunk", "set", "CssLoadingRuntimeModule", "runtimeRequirements", "modules", "modifiedFiles", "watching", "eachExtractions", "eachModule", "name", "content", "originalCssText", "cssText", "newSource", "path", "fs", "path", "writeFile", "filePath", "data", "options", "dirname", "vite_default", "options", "compiler", "MasterCSSCompiler", "outputPath", "path", "server", "outputFilePath", "linkHref", "rendered", "extract", "name", "content", "eachExtractions", "originalCssText", "cssText", "writeFile", "notify", "_server", "source", "code", "id", "html", "hmrContext", "referenceId"]
|
|
7
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -23,23 +23,25 @@
|
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build:cjs": "esbuild src/index.ts --bundle --outfile=dist/index.cjs.js --format=cjs --platform=node --external:@master/css --external:chalk",
|
|
26
|
-
"build:esm": "
|
|
26
|
+
"build:esm": "esbuild src/index.ts --bundle --outfile=dist/index.esm.js --format=esm --platform=node --external:@master/css --external:chalk",
|
|
27
27
|
"dev:cjs": "npm run build:cjs -- --watch",
|
|
28
28
|
"dev:esm": "npm run build:esm -- --watch",
|
|
29
|
-
"prod": "rm -rf dist && npm run build:cjs -- --minify --sourcemap && npm run build:esm",
|
|
29
|
+
"prod": "rm -rf dist && npm run build:cjs -- --minify --sourcemap && npm run build:esm -- --minify --sourcemap && tsc --emitDeclarationOnly",
|
|
30
30
|
"test": "jest",
|
|
31
31
|
"lint": "eslint ./src"
|
|
32
32
|
},
|
|
33
|
+
"type": "module",
|
|
33
34
|
"main": "./dist/index.cjs.js",
|
|
35
|
+
"jsnext:main": "./dist/index.esm.js",
|
|
34
36
|
"browser": "./dist/index.browser.js",
|
|
35
|
-
"esnext": "./dist/
|
|
36
|
-
"module": "./dist/
|
|
37
|
-
"types": "./dist/
|
|
37
|
+
"esnext": "./dist/index.esm.js",
|
|
38
|
+
"module": "./dist/index.esm.js",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
38
40
|
"exports": {
|
|
39
41
|
".": {
|
|
40
42
|
"require": "./dist/index.cjs.js",
|
|
41
|
-
"import": "./dist/
|
|
42
|
-
"types": "./dist/
|
|
43
|
+
"import": "./dist/index.esm.js",
|
|
44
|
+
"types": "./dist/index.d.ts"
|
|
43
45
|
}
|
|
44
46
|
},
|
|
45
47
|
"jest": {
|
|
@@ -137,10 +139,10 @@
|
|
|
137
139
|
"vite": "^3.1.8"
|
|
138
140
|
},
|
|
139
141
|
"peerDependencies": {
|
|
140
|
-
"@master/css": "^2.0.0-beta"
|
|
142
|
+
"@master/css": "^2.0.0-beta.8"
|
|
141
143
|
},
|
|
142
144
|
"dependencies": {
|
|
143
145
|
"chalk": "^5.1.2"
|
|
144
146
|
},
|
|
145
|
-
"version": "2.0.0-beta.
|
|
147
|
+
"version": "2.0.0-beta.8"
|
|
146
148
|
}
|
package/dist/esm/compiler.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import defaultOptions from './options';
|
|
4
|
-
import MasterCSS, { configure, extend } from '@master/css';
|
|
5
|
-
import { performance } from 'perf_hooks';
|
|
6
|
-
export default class MasterCSSCompiler {
|
|
7
|
-
options;
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.options = options;
|
|
10
|
-
this.options = extend(defaultOptions, options);
|
|
11
|
-
let userConfig;
|
|
12
|
-
try {
|
|
13
|
-
userConfig = require(path.resolve(process.cwd(), options.config || './master.css.js'));
|
|
14
|
-
// eslint-disable-next-line no-empty
|
|
15
|
-
}
|
|
16
|
-
catch (err) { }
|
|
17
|
-
this.css = new MasterCSS(configure(userConfig));
|
|
18
|
-
}
|
|
19
|
-
css;
|
|
20
|
-
extractions = new Set();
|
|
21
|
-
extract({ name, content }) {
|
|
22
|
-
if (!name || !content
|
|
23
|
-
|| !this.options.accept?.({ content, name })) {
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
const eachExtractions = [];
|
|
27
|
-
this.log('accepts', ` → ${path.relative(process.cwd(), name)}`);
|
|
28
|
-
for (const eachNewExtraction of this.options.extract({ content, name })) {
|
|
29
|
-
if (this.extractions.has(eachNewExtraction)) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
this.extractions.add(eachNewExtraction);
|
|
34
|
-
eachExtractions.push(eachNewExtraction);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return eachExtractions;
|
|
38
|
-
}
|
|
39
|
-
insert(extractions) {
|
|
40
|
-
const p1 = performance.now();
|
|
41
|
-
/* 根據類名尋找並插入規則 ( MasterCSS 本身帶有快取機制,重複的類名不會再編譯及產生 ) */
|
|
42
|
-
for (const eachExtraction of extractions) {
|
|
43
|
-
this.css.findAndInsert(eachExtraction);
|
|
44
|
-
}
|
|
45
|
-
const spent = Math.round((performance.now() - p1) * 1000);
|
|
46
|
-
const validClasses = this.css.rules.map((rule) => rule.className);
|
|
47
|
-
/* 印出 Master CSS 編譯時間 */
|
|
48
|
-
console.log(`[Master CSS] process ${chalk.green(extractions.length)} extractions in ${chalk.green(spent)} µs [${chalk.green(this.css.rules.length)} rules in ${chalk.green(path.join(this.options.output.dir, this.options.output.name))}]`);
|
|
49
|
-
this.log('extractions', ` → ${chalk.green(extractions.length)} extractions: ${chalk.blue(extractions.join(' '))}`);
|
|
50
|
-
this.log('validClasses', ` → ${chalk.green(validClasses.length)} total valid classes: ${chalk.blue(validClasses.join(' '))}`);
|
|
51
|
-
}
|
|
52
|
-
log(name, content) {
|
|
53
|
-
if (this.options.debug === true || Array.isArray(this.options.debug) && this.options.debug.includes(name)) {
|
|
54
|
-
console.log(content);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=compiler.js.map
|
package/dist/esm/compiler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,cAAqE,MAAM,WAAW,CAAA;AAC7F,OAAO,SAAS,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAGxC,MAAM,CAAC,OAAO,OAAO,iBAAiB;IAGvB;IADX,YACW,OAA0C;QAA1C,YAAO,GAAP,OAAO,CAAmC;QAEjD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;QAC9C,IAAI,UAA2B,CAAA;QAC/B,IAAI;YACA,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,MAAM,IAAI,iBAAiB,CAAC,CAAC,CAAA;YACtF,oCAAoC;SACvC;QAAC,OAAO,GAAG,EAAE,GAAG;QACjB,IAAI,CAAC,GAAG,GAAG,IAAI,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAA;IACnD,CAAC;IAED,GAAG,CAAW;IACd,WAAW,GAAG,IAAI,GAAG,EAAU,CAAA;IAE/B,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAA2B;QAC9C,IACI,CAAC,IAAI,IAAI,CAAC,OAAO;eAC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AA;AAC7D,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,QAAQ,CAAA"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { defaultSemantics } from '@master/css';
|
|
2
|
-
export default function extract({ content }) {
|
|
3
|
-
const blocks = content.match(/[^\s]+/g) ?? [];
|
|
4
|
-
const strings = new Set();
|
|
5
|
-
for (const block of blocks) {
|
|
6
|
-
const result = peelString(block);
|
|
7
|
-
if (result.size) {
|
|
8
|
-
for (const string of result) {
|
|
9
|
-
strings.add(string);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
strings.add(trimString(block));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return [...strings].filter(x => x && !checkToExclude(x));
|
|
17
|
-
}
|
|
18
|
-
const trimString = (content) => {
|
|
19
|
-
const originContent = content;
|
|
20
|
-
content = content.replace(/^([\w={[(\\]*["'`])/, '');
|
|
21
|
-
if (!content.match(/^content:((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)$/)) {
|
|
22
|
-
content = content.replace(/(\.*|[([{\\:#]*|["'`].*)$/, '');
|
|
23
|
-
}
|
|
24
|
-
if (originContent === content) {
|
|
25
|
-
return content;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return trimString(content);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const peelString = (content) => {
|
|
32
|
-
const strings = new Set();
|
|
33
|
-
const stringRegx = /((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)/g;
|
|
34
|
-
let m;
|
|
35
|
-
while ((m = stringRegx.exec(content)) !== null) {
|
|
36
|
-
if (m.index === stringRegx.lastIndex) {
|
|
37
|
-
stringRegx.lastIndex++;
|
|
38
|
-
}
|
|
39
|
-
const result = peelString(m[2]);
|
|
40
|
-
if (result.size) {
|
|
41
|
-
for (const string of result) {
|
|
42
|
-
strings.add(string);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
strings.add(trimString(m[2]));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return strings;
|
|
50
|
-
};
|
|
51
|
-
const checkToExclude = (content) => {
|
|
52
|
-
return !content
|
|
53
|
-
|| (!content.match(/(?:^[\w-]+:[\w$#]+)|(?:^[@~][\w-]+$)/) && !Object.keys(defaultSemantics).includes(content))
|
|
54
|
-
|| content.match(/\*\*/)
|
|
55
|
-
|| content.match(/:\[/)
|
|
56
|
-
|| content.match(/\$\{/)
|
|
57
|
-
|| content.match(/\{\{/)
|
|
58
|
-
|| content.match(/\(\{[^}]*\}/)
|
|
59
|
-
|| content.match(/<\w+>|<\/\w+>/);
|
|
60
|
-
};
|
|
61
|
-
//# sourceMappingURL=extract.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../src/options/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAG9C,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,EAAE,OAAO,EAA2B;IAChE,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAA;IAC7C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IACjC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QACxB,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;QAChC,IAAI,MAAM,CAAC,IAAI,EAAE;YACb,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE;gBACzB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;aACtB;SACJ;aAAM;YACH,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;SACjC;KACJ;IACD,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EA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M,cAAc,GAAG,CAAC,OAAO,EAAE,EAAE;IAC/B,OAAO,CAAC,OAAO;WACR,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;WAC5G,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;WACrB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;WACpB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;WACrB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;WACrB,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC;WAC5B,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;AACzC,CAAC,CAAA"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import extract from './extract';
|
|
2
|
-
const defaultOptions = {
|
|
3
|
-
output: {
|
|
4
|
-
name: 'master.css',
|
|
5
|
-
dir: ''
|
|
6
|
-
},
|
|
7
|
-
accept({ name }) {
|
|
8
|
-
if (name.match(/[\\/]node_modules[\\/]/)) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
if (name.match(/\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i)) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
extract
|
|
16
|
-
};
|
|
17
|
-
export default defaultOptions;
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/options/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,MAAM,cAAc,GAA6B;IAC7C,MAAM,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,EAAE;KACV;IACD,MAAM,CAAC,EAAE,IAAI,EAAE;QACX,IAAI,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,EAAE;YACtC,OAAO,KAAK,CAAA;SACf;QACD,IAAI,IAAI,CAAC,KAAK,CAAC,2CAA2C,CAAC,EAAE;YACzD,OAAO,IAAI,CAAA;SACd;IACL,CAAC;IACD,OAAO;CACV,CAAA;AAkBD,eAAe,cAAc,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
export default function writeFile(filePath, data, options) {
|
|
4
|
-
const dirname = path.dirname(filePath);
|
|
5
|
-
if (!fs.existsSync(dirname)) {
|
|
6
|
-
fs.mkdirSync(dirname, { recursive: true });
|
|
7
|
-
}
|
|
8
|
-
fs.writeFileSync(filePath, data, options);
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=write-file.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"write-file.js","sourceRoot":"","sources":["../../../src/utils/write-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,QAAgB,EAAE,IAAqC,EAAE,OAA6B;IACpH,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACtC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QACzB,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;KAC7C;IACD,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;AAE7C,CAAC"}
|
package/dist/esm/vite.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import MasterCSSCompiler from './compiler';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import writeFile from './utils/write-file';
|
|
4
|
-
export default function (options) {
|
|
5
|
-
const compiler = new MasterCSSCompiler(options);
|
|
6
|
-
const outputPath = path.join(compiler.options.output.dir || '', compiler.options.output.name);
|
|
7
|
-
let server;
|
|
8
|
-
let outputFilePath;
|
|
9
|
-
let linkHref;
|
|
10
|
-
let rendered = false;
|
|
11
|
-
const extract = (name, content) => {
|
|
12
|
-
const eachExtractions = compiler.extract({ name, content });
|
|
13
|
-
if (eachExtractions.length) {
|
|
14
|
-
const originalCssText = compiler.css.text;
|
|
15
|
-
/* 比對提取物並插入 CSS 規則 */
|
|
16
|
-
compiler.insert(eachExtractions);
|
|
17
|
-
/* 根據 cssText 生成 `master.css` 並加入到 Webpack 的 assets 中 */
|
|
18
|
-
const cssText = compiler.css.text;
|
|
19
|
-
if (cssText !== originalCssText) {
|
|
20
|
-
if (server) {
|
|
21
|
-
writeFile(outputFilePath, cssText);
|
|
22
|
-
const notify = () => {
|
|
23
|
-
server.ws.send({
|
|
24
|
-
type: 'update',
|
|
25
|
-
updates: [{
|
|
26
|
-
path: linkHref,
|
|
27
|
-
timestamp: Date.now()
|
|
28
|
-
}]
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
if (rendered) {
|
|
32
|
-
notify();
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
setTimeout(notify, 500);
|
|
36
|
-
rendered = true;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
return {
|
|
43
|
-
name: 'vite-plugin-master-css',
|
|
44
|
-
enforce: 'pre',
|
|
45
|
-
configureServer(_server) {
|
|
46
|
-
server = _server;
|
|
47
|
-
},
|
|
48
|
-
buildStart() {
|
|
49
|
-
outputFilePath = path.resolve(server?.config.cacheDir ?? process.cwd(), outputPath);
|
|
50
|
-
if (server) {
|
|
51
|
-
writeFile(outputFilePath, '');
|
|
52
|
-
linkHref = (server.config.cacheDir.slice(process.cwd().length) + '/' + outputPath).replace(/\\/g, '/');
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
resolveId(source) {
|
|
56
|
-
if (source.endsWith('master.css?direct'))
|
|
57
|
-
return '\0' + source;
|
|
58
|
-
},
|
|
59
|
-
transform(code, id) {
|
|
60
|
-
extract(id, code);
|
|
61
|
-
},
|
|
62
|
-
transformIndexHtml(html) {
|
|
63
|
-
return html.replace(/(<head>)/, `$1<link rel="stylesheet" href="${linkHref}">`);
|
|
64
|
-
},
|
|
65
|
-
async handleHotUpdate(hmrContext) {
|
|
66
|
-
extract(hmrContext.file, await hmrContext.read());
|
|
67
|
-
},
|
|
68
|
-
generateBundle() {
|
|
69
|
-
const referenceId = this.emitFile({
|
|
70
|
-
type: 'asset',
|
|
71
|
-
name: outputPath,
|
|
72
|
-
source: compiler.css.text
|
|
73
|
-
});
|
|
74
|
-
linkHref = '/' + this.getFileName(referenceId);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=vite.js.map
|
package/dist/esm/vite.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,YAAY,CAAA;AAC1C,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,SAAS,MAAM,oBAAoB,CAAA;AAI1C,MAAM,CAAC,OAAO,WAAW,OAAkC;IACvD,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAA;IAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAE7F,IAAI,MAAM,CAAA;IACV,IAAI,cAAsB,CAAA;IAC1B,IAAI,QAAgB,CAAA;IACpB,IAAI,QAAQ,GAAG,KAAK,CAAA;IAEpB,MAAM,OAAO,GAAG,C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E,CAAC,CAAA;gBAE7B,QAAQ,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,UAAU,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;aACzG;QACL,CAAC;QACD,SAAS,CAAC,MAAM;YACZ,IAAI,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC;gBACpC,OAAO,IAAI,GAAG,MAAM,CAAA;QAC5B,CAAC;QACD,SAAS,CAAC,IAAI,EAAE,EAAE;YACd,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;QACrB,CAAC;QACD,kBAAkB,CAAC,IAAI;YACnB,OAAO,IAAI,CAAC,OAAO,CACf,UAAU,EACV,kCAAkC,QAAQ,IAAI,CACjD,CAAA;QACL,CAAC;QACD,KAAK,CAAC,eAAe,CAAC,UAAU;YAC5B,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC,CAAA;QACrD,CAAC;QACD,cAAc;YACV,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC;gBAC9B,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI;aAC5B,CAAC,CAAA;YACF,QAAQ,GAAG,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;QAClD,CAAC;KACJ,CAAA;AACL,CAAC"}
|
package/dist/esm/webpack.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import MasterCSSCompiler from './compiler';
|
|
3
|
-
const NAME = 'MasterCSSWebpackPlugin';
|
|
4
|
-
export default class MasterCSSWebpackPlugin extends MasterCSSCompiler {
|
|
5
|
-
apply(compiler) {
|
|
6
|
-
const { webpack } = compiler;
|
|
7
|
-
const { Template, RuntimeGlobals, RuntimeModule } = webpack;
|
|
8
|
-
const { RawSource } = webpack.sources;
|
|
9
|
-
const { Compilation } = webpack;
|
|
10
|
-
const { options } = this;
|
|
11
|
-
const outputPath = path.join(options.output.dir || '', options.output.name);
|
|
12
|
-
const linkHref = outputPath.replace(/\\/g, '/');
|
|
13
|
-
compiler.hooks.thisCompilation.tap(NAME, (compilation) => {
|
|
14
|
-
const enabledChunks = new WeakSet();
|
|
15
|
-
const handler = (chunk, set) => {
|
|
16
|
-
if (enabledChunks.has(chunk))
|
|
17
|
-
return;
|
|
18
|
-
enabledChunks.add(chunk);
|
|
19
|
-
set.add(RuntimeGlobals.publicPath);
|
|
20
|
-
compilation.addRuntimeModule(chunk, new CssLoadingRuntimeModule(set));
|
|
21
|
-
};
|
|
22
|
-
compilation.hooks.runtimeRequirementInTree
|
|
23
|
-
.for(RuntimeGlobals.ensureChunkHandlers)
|
|
24
|
-
.tap(NAME, handler);
|
|
25
|
-
compilation.hooks.runtimeRequirementInTree
|
|
26
|
-
.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
|
27
|
-
.tap(NAME, handler);
|
|
28
|
-
class CssLoadingRuntimeModule extends RuntimeModule {
|
|
29
|
-
runtimeRequirements;
|
|
30
|
-
constructor(runtimeRequirements) {
|
|
31
|
-
super('master-css-loading', 10);
|
|
32
|
-
this.runtimeRequirements = runtimeRequirements;
|
|
33
|
-
}
|
|
34
|
-
generate() {
|
|
35
|
-
const { runtimeRequirements } = this;
|
|
36
|
-
const withHmr = runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers);
|
|
37
|
-
if (!withHmr)
|
|
38
|
-
return '';
|
|
39
|
-
return Template.asString([
|
|
40
|
-
Date.now().toString(),
|
|
41
|
-
`const link = document.querySelector('[href*=\\'${linkHref}\\'][rel=stylesheet]')`,
|
|
42
|
-
'if (link) {',
|
|
43
|
-
Template.indent([
|
|
44
|
-
'link.href = link.href.replace(/ts=[0-9]+/, \'ts=\' + Date.now())'
|
|
45
|
-
]),
|
|
46
|
-
'}'
|
|
47
|
-
]);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
compiler.hooks.compilation.tap(NAME, (compilation) => {
|
|
52
|
-
// 增加額外的 `master.css` assets
|
|
53
|
-
compilation.hooks.finishModules.tap(NAME, (modules) => {
|
|
54
|
-
const { modifiedFiles, watching } = compiler;
|
|
55
|
-
const eachExtractions = [];
|
|
56
|
-
for (const eachModule of modules) {
|
|
57
|
-
const name = eachModule['resource'];
|
|
58
|
-
// 從記憶體或快取取得當前 module 的原始碼
|
|
59
|
-
const content = eachModule['_source']?.source();
|
|
60
|
-
// 在 watch 模式下僅處理當下變更的檔案
|
|
61
|
-
if (watching && modifiedFiles?.size && !modifiedFiles.has(name)) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
eachExtractions.push(...this.extract({ name, content }));
|
|
65
|
-
}
|
|
66
|
-
if (eachExtractions.length) {
|
|
67
|
-
const originalCssText = this.css.text;
|
|
68
|
-
/* 比對提取物並插入 CSS 規則 */
|
|
69
|
-
this.insert(eachExtractions);
|
|
70
|
-
/* 根據 cssText 生成 `master.css` 並加入到 Webpack 的 assets 中 */
|
|
71
|
-
const cssText = this.css.text;
|
|
72
|
-
if (cssText !== originalCssText) {
|
|
73
|
-
const newSource = new RawSource(cssText);
|
|
74
|
-
if (compilation.getAsset(outputPath)) {
|
|
75
|
-
compilation.updateAsset(outputPath, newSource);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
compilation.emitAsset(outputPath, newSource);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
compilation.hooks.processAssets.tap({
|
|
84
|
-
name: NAME,
|
|
85
|
-
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
86
|
-
}, () => {
|
|
87
|
-
compilation.chunks.forEach((chunk) => {
|
|
88
|
-
chunk.files.add(outputPath);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=webpack.js.map
|
package/dist/esm/webpack.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../src/webpack.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,iBAAiB,MAAM,YAAY,CAAA;AAG1C,MAAM,IAAI,GAAG,wBAAwB,CAAA;AAErC,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,iBAAiB;IAEjE,KAAK,CAAC,QAAkB;QACpB,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAA;QAC5B,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,OAAO,CAAA;QAC3D,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,OAAO,CAAA;QACrC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;QAC/B,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;QACxB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3E,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAE/C,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE;YAErD,MAAM,aAAa,GAAG,IAAI,OAAO,EAAE,CAAA;YAEnC,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBAC3B,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC;oBACxB,OAAM;gBAEV,aAAa,CAAC,GAAG,CAAC,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