@plumeria/webpack-plugin 6.3.0 → 6.3.1

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/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { LoaderContext } from 'webpack';
2
- export default function loader(this: LoaderContext<unknown>, source: string): void;
2
+ export default function loader(this: LoaderContext<unknown>, source: string): Promise<void>;
package/dist/index.js CHANGED
@@ -5,15 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = loader;
7
7
  const core_1 = require("@swc/core");
8
- const fs_1 = __importDefault(require("fs"));
8
+ const fs_1 = require("fs");
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const zss_engine_1 = require("zss-engine");
11
11
  const utils_1 = require("@plumeria/utils");
12
12
  const VIRTUAL_FILE_PATH = path_1.default.resolve(__dirname, '..', 'zero-virtual.css');
13
13
  if (process.env.NODE_ENV === 'production') {
14
- fs_1.default.writeFileSync(VIRTUAL_FILE_PATH, '/** Placeholder file */', 'utf-8');
14
+ (0, fs_1.writeFileSync)(VIRTUAL_FILE_PATH, '/** Placeholder file */\n', 'utf-8');
15
15
  }
16
- function loader(source) {
16
+ async function loader(source) {
17
17
  const callback = this.async();
18
18
  const isProduction = process.env.NODE_ENV === 'production';
19
19
  if (this.resourcePath.includes('node_modules') ||
@@ -222,7 +222,7 @@ function loader(source) {
222
222
  if (obj) {
223
223
  const hashMap = {};
224
224
  Object.entries(obj).forEach(([key, style]) => {
225
- const records = (0, utils_1.getStyleRecords)(key, style, 2);
225
+ const records = (0, utils_1.getStyleRecords)(key, style);
226
226
  if (!isProduction) {
227
227
  (0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
228
228
  records.forEach((r) => {
@@ -372,6 +372,9 @@ function loader(source) {
372
372
  const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
373
373
  const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
374
374
  scannedTables.keyframesObjectTable[hash] = obj;
375
+ if (!isProduction) {
376
+ (0, utils_1.extractOndemandStyles)({ kf: `kf-${hash}` }, extractedSheets, scannedTables);
377
+ }
375
378
  replacements.push({
376
379
  start: node.span.start - ast.span.start,
377
380
  end: node.span.end - ast.span.start,
@@ -419,7 +422,7 @@ function loader(source) {
419
422
  scannedTables.createObjectTable[hash] = obj;
420
423
  Object.entries(obj).forEach(([key, style]) => {
421
424
  if (typeof style === 'object' && style !== null) {
422
- const records = (0, utils_1.getStyleRecords)(key, style, 2);
425
+ const records = (0, utils_1.getStyleRecords)(key, style);
423
426
  if (!isProduction) {
424
427
  (0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
425
428
  records.forEach((r) => addSheet(r.sheet));
@@ -770,7 +773,7 @@ function loader(source) {
770
773
  (0, utils_1.extractOndemandStyles)(baseStyle, extractedSheets, scannedTables);
771
774
  }
772
775
  const hash = (0, zss_engine_1.genBase36Hash)(baseStyle, 1, 8);
773
- const records = (0, utils_1.getStyleRecords)(hash, baseStyle, 2);
776
+ const records = (0, utils_1.getStyleRecords)(hash, baseStyle);
774
777
  if (!isProduction) {
775
778
  records.forEach((r) => addSheet(r.sheet));
776
779
  }
@@ -811,7 +814,7 @@ function loader(source) {
811
814
  (0, utils_1.extractOndemandStyles)(currentStyle, extractedSheets, scannedTables);
812
815
  }
813
816
  const hash = (0, zss_engine_1.genBase36Hash)(currentStyle, 1, 8);
814
- const records = (0, utils_1.getStyleRecords)(hash, currentStyle, 2);
817
+ const records = (0, utils_1.getStyleRecords)(hash, currentStyle);
815
818
  if (process.env.NODE_ENV !== 'production') {
816
819
  records.forEach((r) => extractedSheets.push(r.sheet));
817
820
  }
@@ -849,7 +852,7 @@ function loader(source) {
849
852
  },
850
853
  });
851
854
  Object.values(localCreateStyles).forEach((info) => {
852
- if (info.type === 'constant' || info.type === 'variant') {
855
+ if (info.type === 'constant') {
853
856
  return;
854
857
  }
855
858
  if (info.isExported) {
@@ -867,6 +870,7 @@ function loader(source) {
867
870
  });
868
871
  }
869
872
  });
873
+ const optInCSS = await (0, utils_1.optimizer)(extractedSheets.join(''));
870
874
  const buffer = Buffer.from(source);
871
875
  let offset = 0;
872
876
  const parts = [];
@@ -892,7 +896,7 @@ function loader(source) {
892
896
  }
893
897
  const virtualCssRequest = stringifyRequest(this, `${VIRTUAL_CSS_PATH}`);
894
898
  const postfix = `\nimport ${virtualCssRequest};`;
895
- const css = fs_1.default.readFileSync(VIRTUAL_FILE_PATH, 'utf-8');
899
+ const css = (0, fs_1.readFileSync)(VIRTUAL_FILE_PATH, 'utf-8');
896
900
  function generateOrderedCSS(styles) {
897
901
  const sections = [];
898
902
  if (styles.keyframeStyles?.trim()) {
@@ -912,7 +916,7 @@ function loader(source) {
912
916
  }
913
917
  return sections.join('\n');
914
918
  }
915
- const orderedCSS = generateOrderedCSS(fileStyles);
919
+ const orderedCSS = await (0, utils_1.optimizer)(generateOrderedCSS(fileStyles));
916
920
  const relativeId = path_1.default.relative(process.cwd(), this.resourcePath);
917
921
  const hmrCode = `
918
922
  if (module.hot) {
@@ -946,7 +950,7 @@ function loader(source) {
946
950
  }
947
951
  `;
948
952
  if (extractedSheets.length > 0 && process.env.NODE_ENV === 'development') {
949
- fs_1.default.appendFileSync(VIRTUAL_FILE_PATH, extractedSheets.join(''), 'utf-8');
953
+ (0, fs_1.appendFileSync)(VIRTUAL_FILE_PATH, optInCSS, 'utf-8');
950
954
  }
951
955
  const useClientDirective = /^\s*['"]use client['"]/;
952
956
  if (process.env.NODE_ENV === 'production')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/webpack-plugin",
3
- "version": "6.3.0",
3
+ "version": "6.3.1",
4
4
  "description": "Plumeria Webpack plugin",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  "zero-virtual.css"
23
23
  ],
24
24
  "dependencies": {
25
- "@plumeria/utils": "^6.3.0"
25
+ "@plumeria/utils": "^6.3.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.8",