@into-mini/sfc-split-plugin 0.6.3 → 0.6.5

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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AddWxsPlugin } from "./plugin/add-wxs.mjs";
2
2
  import { ExposeEntryNamePlugin } from "./plugin/expose-entry.mjs";
3
- import { EntryRenamePlugin } from "./plugin/entry-rename.mjs";
3
+ // import { EntryRenamePlugin } from './plugin/entry-rename.mts';
4
4
  import { MinaRuntimeWebpackPlugin } from "./plugin/mina-runtime.mjs";
5
5
  export class SfcSplitPlugin {
6
6
  options;
@@ -17,10 +17,10 @@ export class SfcSplitPlugin {
17
17
  new AddWxsPlugin().apply(compiler);
18
18
  new MinaRuntimeWebpackPlugin().apply(compiler);
19
19
  new ExposeEntryNamePlugin().apply(compiler);
20
- new EntryRenamePlugin({
21
- issuer: /\.vue$/,
22
- test: /\.wxml|json/,
23
- }).apply(compiler);
20
+ // new EntryRenamePlugin({
21
+ // issuer: /\.vue$/,
22
+ // test: /\.wxml|json/,
23
+ // }).apply(compiler);
24
24
  }
25
25
  }
26
26
  }
@@ -3,6 +3,7 @@
3
3
  import { createHash } from 'node:crypto';
4
4
  import { relative, resolve } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
+ import sortKeys from 'sort-keys';
6
7
  import slash from 'slash';
7
8
  function createShortHash(input) {
8
9
  return createHash('sha256').update(input).digest('hex').slice(0, 8);
@@ -11,7 +12,7 @@ function reach(path) {
11
12
  return fileURLToPath(import.meta.resolve(path));
12
13
  }
13
14
  const componentRoot = 'as-components';
14
- function handleImport({ toThis, addSmartEntry, context, rootContext, maps, callback, }) {
15
+ function handleImport({ addSmartEntry, context, rootContext, maps, callback }) {
15
16
  if (Object.keys(maps).length > 0) {
16
17
  for (const [name, path] of Object.entries(maps)) {
17
18
  if (path.endsWith('.vue') && !path.startsWith('plugin://')) {
@@ -30,7 +31,7 @@ function handleImport({ toThis, addSmartEntry, context, rootContext, maps, callb
30
31
  createShortHash(slash(relativePath)),
31
32
  ].join('/')
32
33
  : relativePath.replace(/\.vue$/, '');
33
- const placer = toThis(entryName);
34
+ const placer = `/${entryName}`;
34
35
  callback({
35
36
  name,
36
37
  placer,
@@ -55,19 +56,14 @@ function handleImport({ toThis, addSmartEntry, context, rootContext, maps, callb
55
56
  export default function loader(source) {
56
57
  this.cacheable();
57
58
  const callback = this.async();
58
- const { entryName: thisEntryName } = this;
59
59
  const config = JSON.parse(source.trim() || '{}');
60
60
  const { rootContext, context } = this;
61
- function toThis(entryName) {
62
- return slash(relative(`/${thisEntryName}/..`, `/${entryName}`));
63
- }
64
61
  // eslint-disable-next-line unicorn/consistent-function-scoping
65
62
  const addSmartEntry = (io) => {
66
63
  this.addSmartEntry(io);
67
64
  };
68
65
  if (config?.usingComponents) {
69
66
  handleImport.bind(this)({
70
- toThis,
71
67
  addSmartEntry,
72
68
  componentRoot,
73
69
  context,
@@ -84,7 +80,6 @@ export default function loader(source) {
84
80
  }
85
81
  if (config?.componentGenerics) {
86
82
  handleImport.bind(this)({
87
- toThis,
88
83
  addSmartEntry,
89
84
  context,
90
85
  rootContext,
@@ -96,6 +91,8 @@ export default function loader(source) {
96
91
  },
97
92
  });
98
93
  }
94
+ config.componentGenerics &&= sortKeys(config.componentGenerics);
95
+ config.usingComponents &&= sortKeys(config.usingComponents);
99
96
  const shouldFormat = this._compiler?.options?.optimization?.minimize !== true;
100
97
  const spaces = shouldFormat ? 2 : 0;
101
98
  callback(null, JSON.stringify(config, null, spaces));
@@ -1,7 +1,6 @@
1
- import type { Compiler, Compilation, PathData, Module, Chunk, WebpackPluginInstance } from 'webpack';
1
+ import type { Compiler, PathData, Chunk, WebpackPluginInstance } from 'webpack';
2
2
  export declare class ExposeEntryNamePlugin implements WebpackPluginInstance {
3
3
  getEntryNameFromChunk(chunk: Chunk): string | null | undefined;
4
- getEntryNameFromEntries(compilation: Compilation, module: Module): string;
5
4
  getEntryNameFromPathData(pathData: PathData): string;
6
5
  apply(compiler: Compiler): void;
7
6
  }
@@ -1,4 +1,3 @@
1
- import slash from 'slash';
2
1
  const PLUGIN_NAME = 'ExposeEntryNamePlugin';
3
2
  export class ExposeEntryNamePlugin {
4
3
  getEntryNameFromChunk(chunk) {
@@ -12,29 +11,6 @@ export class ExposeEntryNamePlugin {
12
11
  }
13
12
  return '';
14
13
  }
15
- getEntryNameFromEntries(compilation, module) {
16
- const { moduleGraph, entries } = compilation;
17
- for (const [name, io] of entries) {
18
- for (const dep of io.dependencies) {
19
- const entryModule = moduleGraph.getModule(dep);
20
- if (entryModule) {
21
- if (
22
- // @ts-expect-error ------------
23
- entryModule.request && // @ts-expect-error ------------
24
- slash(entryModule.request) === slash(module.request)) {
25
- return name;
26
- }
27
- if (
28
- // @ts-expect-error ------------
29
- entryModule?.resource && // @ts-expect-error ------------
30
- slash(entryModule?.resource) === slash(module.resource)) {
31
- return name;
32
- }
33
- }
34
- }
35
- }
36
- return '';
37
- }
38
14
  getEntryNameFromPathData(pathData) {
39
15
  if (pathData?.chunk) {
40
16
  const entryName = this.getEntryNameFromChunk(pathData.chunk);
@@ -54,7 +30,6 @@ export class ExposeEntryNamePlugin {
54
30
  return '';
55
31
  }
56
32
  apply(compiler) {
57
- const { NormalModule: { getCompilationHooks }, } = compiler.webpack;
58
33
  compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
59
34
  compilation.hooks.assetPath.tap(PLUGIN_NAME, (path, pathData) => {
60
35
  if (path.includes('[entry]')) {
@@ -65,15 +40,6 @@ export class ExposeEntryNamePlugin {
65
40
  }
66
41
  return path;
67
42
  });
68
- getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (loaderContext, module) => {
69
- Object.defineProperty(loaderContext, 'entryName', {
70
- enumerable: true,
71
- configurable: false,
72
- get: () => {
73
- return this.getEntryNameFromEntries(compilation, module);
74
- },
75
- });
76
- });
77
43
  });
78
44
  }
79
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@into-mini/sfc-split-plugin",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "loader",
@@ -29,12 +29,13 @@
29
29
  "type": "module",
30
30
  "dependencies": {
31
31
  "slash": "^5.1.0",
32
+ "sort-keys": "^6.0.0",
32
33
  "yaml": "^2.8.2",
33
34
  "@into-mini/clsx": "^0.1.1",
34
35
  "@into-mini/sfc-transformer": "^0.6.5"
35
36
  },
36
37
  "peerDependencies": {
37
- "webpack": "^5.104.0"
38
+ "webpack": "^5.104.1"
38
39
  },
39
40
  "engines": {
40
41
  "node": ">=22.18.0"
@@ -1,6 +0,0 @@
1
- import type { Compiler, Compilation, PathData, Module, WebpackPluginInstance } from 'webpack';
2
- export declare class ExposeEntryNamePlugin implements WebpackPluginInstance {
3
- getEntryNameFromEntries(compilation: Compilation, module: Module): string;
4
- getEntryNameFromPathData(compilation: Compilation, pathData: PathData): string;
5
- apply(compiler: Compiler): void;
6
- }
@@ -1,63 +0,0 @@
1
- import slash from 'slash';
2
- const PLUGIN_NAME = 'ExposeEntryNamePlugin';
3
- export class ExposeEntryNamePlugin {
4
- getEntryNameFromEntries(compilation, module) {
5
- const { moduleGraph, entries } = compilation;
6
- for (const [name, io] of entries) {
7
- for (const dep of io.dependencies) {
8
- const entryModule = moduleGraph.getModule(dep);
9
- if (entryModule) {
10
- if (
11
- // @ts-expect-error ------------
12
- entryModule.request && // @ts-expect-error ------------
13
- slash(entryModule.request) === slash(module.request)) {
14
- return name;
15
- }
16
- if (
17
- // @ts-expect-error ------------
18
- entryModule?.resource && // @ts-expect-error ------------
19
- slash(entryModule?.resource) === slash(module.resource)) {
20
- return name;
21
- }
22
- }
23
- }
24
- }
25
- return '';
26
- }
27
- getEntryNameFromPathData(compilation, pathData) {
28
- const mod = pathData.module;
29
- const graph = pathData.chunkGraph;
30
- if (mod && graph) {
31
- const [entryModule] = graph
32
- .getModuleChunks(mod)
33
- .map((chunk) => [...graph.getChunkEntryModulesIterable(chunk)][0]);
34
- if (entryModule) {
35
- return this.getEntryNameFromEntries(compilation, entryModule);
36
- }
37
- }
38
- return '';
39
- }
40
- apply(compiler) {
41
- const { NormalModule: { getCompilationHooks }, } = compiler.webpack;
42
- compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
43
- compilation.hooks.assetPath.tap(PLUGIN_NAME, (path, pathData) => {
44
- if (path.includes('[entry]')) {
45
- const entryName = this.getEntryNameFromPathData(compilation, pathData);
46
- return entryName
47
- ? path.replaceAll('[entry]', entryName)
48
- : path.replaceAll('[entry]', '[hash:8]');
49
- }
50
- return path;
51
- });
52
- getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (loaderContext, module) => {
53
- Object.defineProperty(loaderContext, 'entryName', {
54
- enumerable: true,
55
- configurable: false,
56
- get: () => {
57
- return this.getEntryNameFromEntries(compilation, module);
58
- },
59
- });
60
- });
61
- });
62
- }
63
- }