@into-mini/sfc-split-plugin 0.5.6 → 0.5.9

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.mts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Options } from './plugin/sfc-split.mts';
2
1
  import type { Compiler, WebpackPluginInstance } from 'webpack';
2
+ import type { Options } from '@into-mini/sfc-transformer/src/transformer.mts';
3
3
  export declare const COMPONENT_ROOT = "as-components";
4
4
  export declare class SfcSplitPlugin implements WebpackPluginInstance {
5
5
  #private;
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { fileURLToPath } from 'node:url';
2
2
  import { AddWxsPlugin } from "./plugin/add-wxs.mjs";
3
- // import { ExposeEntryNamePlugin } from './plugin/expose-entry.mts';
3
+ import { ExposeEntryNamePlugin } from "./plugin/expose-entry.mjs";
4
4
  import { EntryRenamePlugin } from "./plugin/entry-rename.mjs";
5
+ import { MinaRuntimeWebpackPlugin } from "./plugin/mina-runtime.mjs";
5
6
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
6
7
  export const COMPONENT_ROOT = 'as-components';
7
8
  function reach(path) {
@@ -18,19 +19,10 @@ export class SfcSplitPlugin {
18
19
  };
19
20
  }
20
21
  #applyLoader(compiler) {
21
- compiler.options.module.rules.push(
22
- // {
23
- // test: /\.vue$/,
24
- // use: [
25
- // {
26
- // loader: reach('./loader/fake-vue-loader.mts'),
27
- // options: {
28
- // componentRoot: COMPONENT_ROOT,
29
- // },
30
- // },
31
- // ],
32
- // },
33
- {
22
+ compiler.options.module.rules.push({
23
+ test: /\.vue$/,
24
+ use: [],
25
+ }, {
34
26
  test: /\.vue$/,
35
27
  issuer: /\.vue$/,
36
28
  resourceQuery: /type=script/,
@@ -42,7 +34,7 @@ export class SfcSplitPlugin {
42
34
  resourceQuery: /type=template/,
43
35
  type: 'asset/resource',
44
36
  generator: {
45
- filename: '[path][name].[hash:8].wxml',
37
+ filename: '[entry].wxml',
46
38
  },
47
39
  use: [
48
40
  {
@@ -67,9 +59,19 @@ export class SfcSplitPlugin {
67
59
  resourceQuery: [/type=config&lang=json/],
68
60
  type: 'asset/resource',
69
61
  generator: {
70
- filename: '[path][hash:8].json',
62
+ filename: '[entry].json',
71
63
  },
72
- loader: theLoader,
64
+ use: [
65
+ {
66
+ loader: reach('@into-mini/sfc-split-plugin/dist/loader/entry-loader.mjs'),
67
+ options: {
68
+ componentRoot: COMPONENT_ROOT,
69
+ },
70
+ },
71
+ {
72
+ loader: theLoader,
73
+ },
74
+ ],
73
75
  }, {
74
76
  test: /\.vue$/,
75
77
  resourceQuery: { not: /type=/ },
@@ -87,9 +89,8 @@ export class SfcSplitPlugin {
87
89
  const { type } = this.options;
88
90
  if (type) {
89
91
  new AddWxsPlugin().apply(compiler);
90
- // new MinaRuntimeWebpackPlugin().apply(compiler);
91
- // new SfcSplitPluginBase({ tagMatcher, preserveTap }).apply(compiler);
92
- // new ExposeEntryNamePlugin().apply(compiler);
92
+ new MinaRuntimeWebpackPlugin().apply(compiler);
93
+ new ExposeEntryNamePlugin().apply(compiler);
93
94
  new EntryRenamePlugin({
94
95
  issuer: /\.vue$/,
95
96
  test: /\.wxml|json/,
@@ -1,2 +1,2 @@
1
1
  import type { LoaderContext } from 'webpack';
2
- export default function loader(this: LoaderContext<Record<string, any>>, source: string, map: any, meta: any): void;
2
+ export default function loader(this: LoaderContext<Record<string, any>>, source: string): void;
@@ -1,9 +1,8 @@
1
1
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
2
  // @ts-nocheck
3
3
  import { createHash } from 'node:crypto';
4
- import { join, relative, resolve } from 'node:path';
4
+ import { relative, resolve } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
- import { toJSONString } from '@into-mini/sfc-transformer/src/utils.mts';
7
6
  import slash from 'slash';
8
7
  function createShortHash(input) {
9
8
  return createHash('sha256').update(input).digest('hex').slice(0, 8);
@@ -52,22 +51,13 @@ function handleImport({ toThis, addSmartEntry, componentRoot, context, rootConte
52
51
  }
53
52
  }
54
53
  }
55
- export default function loader(source, map, meta) {
54
+ export default function loader(source) {
56
55
  this.cacheable();
57
56
  const callback = this.async();
58
57
  const { componentRoot } = this.getOptions();
59
58
  const { entryName: thisEntryName } = this;
60
- const resourcePath = slash(this.resourcePath);
61
- const { paths, config, script } = this.processSfcFile({
62
- source,
63
- resourcePath,
64
- });
59
+ const config = JSON.parse(source);
65
60
  const { rootContext, context } = this;
66
- for (const path of paths) {
67
- const filePath = join(rootContext, path);
68
- this.addDependency(filePath);
69
- this.addMissingDependency(filePath);
70
- }
71
61
  function toThis(entryName) {
72
62
  return slash(relative(`/${thisEntryName}/..`, `/${entryName}`));
73
63
  }
@@ -107,12 +97,5 @@ export default function loader(source, map, meta) {
107
97
  },
108
98
  });
109
99
  }
110
- const file = [
111
- ...paths
112
- .map((path) => relative(`${resourcePath}/..`, path))
113
- .map((path) => `import "./${path}";`),
114
- script,
115
- ].join('\n');
116
- this.emitFile(`${thisEntryName}.json`, toJSONString(config));
117
- callback(null, file, map, meta);
100
+ callback(null, JSON.stringify(config));
118
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@into-mini/sfc-split-plugin",
3
- "version": "0.5.6",
3
+ "version": "0.5.9",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "loader",
@@ -33,9 +33,9 @@
33
33
  "webpack-virtual-modules": "^0.6.2",
34
34
  "yaml": "^2.8.2",
35
35
  "@into-mini/clsx": "^0.1.0",
36
- "@into-mini/sfc-split-loader": "^0.2.5",
36
+ "@into-mini/sfc-transformer": "^0.6.1",
37
37
  "@into-mini/wxml-loader": "^0.0.0",
38
- "@into-mini/sfc-transformer": "^0.6.1"
38
+ "@into-mini/sfc-split-loader": "^0.2.6"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "webpack": "^5.104.0"
@@ -1,18 +0,0 @@
1
- import VirtualModulesPlugin from 'webpack-virtual-modules';
2
- import type { Compiler, WebpackPluginInstance } from 'webpack';
3
- export type Options = {
4
- type?: boolean;
5
- tagMatcher?: (tag: string) => {
6
- tag: string;
7
- path: string;
8
- };
9
- preserveTap?: (tag: string) => boolean;
10
- };
11
- export declare class SfcSplitPluginBase extends VirtualModulesPlugin implements WebpackPluginInstance {
12
- #private;
13
- PLUGIN_NAME: string;
14
- tagMatcher: Options['tagMatcher'];
15
- preserveTap: Options['preserveTap'];
16
- constructor({ tagMatcher, preserveTap }: Options);
17
- apply(compiler: Compiler): void;
18
- }
@@ -1,74 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
- import path from 'node:path';
4
- import { parse } from '@into-mini/sfc-transformer/src/index.mjs';
5
- import slash from 'slash';
6
- import VirtualModulesPlugin from 'webpack-virtual-modules';
7
- export class SfcSplitPluginBase extends VirtualModulesPlugin {
8
- PLUGIN_NAME = 'SfcSplitPluginBase';
9
- tagMatcher;
10
- preserveTap;
11
- constructor({ tagMatcher, preserveTap }) {
12
- super();
13
- this.tagMatcher = tagMatcher;
14
- this.preserveTap = preserveTap;
15
- }
16
- apply(compiler) {
17
- this.#expose(compiler);
18
- super.apply(compiler);
19
- }
20
- #expose(compiler) {
21
- const { PLUGIN_NAME } = this;
22
- const { NormalModule: { getCompilationHooks }, } = compiler.webpack;
23
- compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
24
- getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (loaderContext) => {
25
- Object.defineProperty(loaderContext, 'processSfcFile', {
26
- enumerable: true,
27
- configurable: false,
28
- value: (options) => {
29
- return this.#processSfcFile(options);
30
- },
31
- });
32
- });
33
- });
34
- }
35
- #inject(resourcePath, ext, content) {
36
- const src = path.resolve(resourcePath.replace(/\.vue$/, ext));
37
- super.writeModule(src, content);
38
- return src;
39
- }
40
- #injectStyle(resourcePath, id, style) {
41
- return this.#inject(resourcePath, `-${id}.${style.lang ?? 'css'}`, style.content);
42
- }
43
- #injectStyles(resourcePath, styles) {
44
- const io = [];
45
- const css = styles?.length > 0 ? styles : [];
46
- css.forEach((style, idx) => {
47
- if (style?.content) {
48
- const src = this.#injectStyle(resourcePath, idx, style);
49
- io.push(src);
50
- }
51
- });
52
- return io;
53
- }
54
- #injectTemplate(resourcePath, tpl) {
55
- return this.#inject(resourcePath, '.wxml', tpl);
56
- }
57
- #processSfcFile({ source, resourcePath }) {
58
- const { tagMatcher, preserveTap } = this;
59
- const { tpl, styles, code, config } = parse(source, {
60
- tagMatcher,
61
- preserveTap,
62
- });
63
- const paths = [];
64
- const wxml = this.#injectTemplate(resourcePath, tpl);
65
- paths.push(wxml);
66
- const css = this.#injectStyles(resourcePath, styles);
67
- paths.push(...css);
68
- return {
69
- config,
70
- paths: paths.map((src) => slash(src)),
71
- script: code,
72
- };
73
- }
74
- }