@best-shot/preset-mini 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Eric Chen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @best-shot/preset-mini <img src="https://cdn.jsdelivr.net/gh/best-shot/best-shot/packages/core/logo.svg" alt="logo" height="80" align="right">
2
+
3
+ A `best-shot` preset for mini program project.
4
+
5
+ [![npm][npm-badge]][npm-url]
6
+ [![github][github-badge]][github-url]
7
+ ![node][node-badge]
8
+
9
+ [npm-url]: https://www.npmjs.com/package/@best-shot/preset-mini
10
+ [npm-badge]: https://img.shields.io/npm/v/@best-shot/preset-mini.svg?style=flat-square&logo=npm
11
+ [github-url]: https://github.com/best-shot/best-shot/tree/master/packages/preset-mini
12
+ [github-badge]: https://img.shields.io/npm/l/@best-shot/preset-mini.svg?style=flat-square&colorB=blue&logo=github
13
+ [node-badge]: https://img.shields.io/node/v/@best-shot/preset-mini.svg?style=flat-square&colorB=green&logo=node.js
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @best-shot/preset-mini --save-dev
19
+ ```
package/helper.mjs ADDED
@@ -0,0 +1,27 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+
4
+ import { parse } from 'yaml';
5
+
6
+ export function readYAML(path, base = process.cwd()) {
7
+ const file = readFileSync(resolve(base, path), 'utf8');
8
+
9
+ return parse(file);
10
+ }
11
+
12
+ function unique(...arr) {
13
+ return [...new Set(arr)];
14
+ }
15
+
16
+ export function getAllPages(config) {
17
+ const { pages = [], subPackages = [], tabBar: { list = [] } = {} } = config;
18
+
19
+ return unique(
20
+ ...pages,
21
+ ...list.map(({ pagePath }) => pagePath),
22
+ ...subPackages.flatMap(
23
+ (subPackage) =>
24
+ subPackage.pages.map((page) => `${subPackage.root}/${page}`) || [],
25
+ ),
26
+ );
27
+ }
package/index.mjs ADDED
@@ -0,0 +1,69 @@
1
+ import { fileURLToPath } from 'node:url';
2
+
3
+ import { getAllPages, readYAML } from './helper.mjs';
4
+
5
+ export function apply() {
6
+ return (chain) => {
7
+ chain.module
8
+ .rule('vue')
9
+ .test(/\.vue$/)
10
+ .use('loader')
11
+ .loader(
12
+ fileURLToPath(import.meta.resolve('@best-shot/sfc-split-loader')),
13
+ );
14
+
15
+ const context = chain.get('context');
16
+
17
+ const io = readYAML('app.yaml', context);
18
+ const allPages = getAllPages(io);
19
+
20
+ chain
21
+ .entry('app')
22
+ .add('./app.js')
23
+ .add('./app.css')
24
+ .add('./app.yaml?to-url');
25
+
26
+ for (const page of allPages) {
27
+ chain.entry(page).add(`./${page}.vue`);
28
+ }
29
+ };
30
+ }
31
+
32
+ export const name = 'preset-mini';
33
+
34
+ export const schema = {
35
+ target: {
36
+ default: 'es2024',
37
+ },
38
+ context: {
39
+ default: 'src',
40
+ },
41
+ output: {
42
+ type: 'object',
43
+ properties: {
44
+ publicPath: {
45
+ default: '/',
46
+ },
47
+ module: {
48
+ default: true,
49
+ },
50
+ chunkFormat: {
51
+ default: 'commonjs',
52
+ },
53
+ chunkLoading: {
54
+ default: 'require',
55
+ },
56
+ },
57
+ },
58
+ dataURI: {
59
+ default: true,
60
+ },
61
+ optimization: {
62
+ type: 'object',
63
+ properties: {
64
+ splitChunks: {
65
+ default: true,
66
+ },
67
+ },
68
+ },
69
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@best-shot/preset-mini",
3
+ "version": "0.0.0",
4
+ "description": "A `best-shot` preset for mini program project",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "Eric Chen",
8
+ "email": "airkro@qq.com"
9
+ },
10
+ "keywords": [
11
+ "best-shot",
12
+ "miniprogram",
13
+ "mp",
14
+ "weapp",
15
+ "webpack",
16
+ "wechat",
17
+ "weixin"
18
+ ],
19
+ "homepage": "https://github.com/best-shot/best-shot/tree/master/packages/preset-mini",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/best-shot/best-shot.git",
23
+ "directory": "packages/preset-mini"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/best-shot/best-shot/issues"
27
+ },
28
+ "main": "index.mjs",
29
+ "type": "module",
30
+ "dependencies": {
31
+ "yaml": "^2.4.5",
32
+ "@best-shot/sfc-split-loader": "~0.2.0"
33
+ },
34
+ "peerDependencies": {
35
+ "@best-shot/core": "~0.9.17",
36
+ "@best-shot/preset-babel": "~0.14.8",
37
+ "@best-shot/preset-style": "~0.12.14"
38
+ },
39
+ "engines": {
40
+ "node": ">=20.6.0 || ^18.19.0"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "registry": "https://registry.npmjs.org/"
45
+ },
46
+ "x-readme": {
47
+ "logo": "https://cdn.jsdelivr.net/gh/best-shot/best-shot/packages/core/logo.svg"
48
+ }
49
+ }