swico 2.9.0 → 3.0.0-beta.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.
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.default = default_1;
46
+ const main_config_1 = require("../main-config");
47
+ const core_1 = require("@rsbuild/core");
48
+ function default_1(options) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ var _a, _b, _c, _d, _e, _f, _g, _h;
51
+ const { projectPath, customConfig, templateType } = options;
52
+ const getBaseConfig = (yield Promise.resolve(`${templateType === 'vue' ? './config.base.vue' : './config.base.react'}`).then(s => __importStar(require(s)))).default;
53
+ const baseConfig = yield getBaseConfig(Object.assign(Object.assign({}, options), { env: 'prod' }));
54
+ const consoleAvailable = (_b = (_a = customConfig.prod) === null || _a === void 0 ? void 0 : _a.console) !== null && _b !== void 0 ? _b : main_config_1.initConfig.console;
55
+ const copyConfig = (_d = (_c = customConfig.prod) === null || _c === void 0 ? void 0 : _c.copy) !== null && _d !== void 0 ? _d : main_config_1.initConfig.copy;
56
+ return (0, core_1.mergeRsbuildConfig)(baseConfig, {
57
+ output: {
58
+ copy: copyConfig.length > 0 ? [...(copyConfig || [])] : [],
59
+ sourceMap: {
60
+ js: (_f = (_e = customConfig.prod.devtool) !== null && _e !== void 0 ? _e : customConfig.base.devtool) !== null && _f !== void 0 ? _f : false,
61
+ css: false,
62
+ extract: false
63
+ }
64
+ },
65
+ performance: {
66
+ removeConsole: !consoleAvailable
67
+ },
68
+ mode: 'production',
69
+ plugins: [...((_h = (_g = customConfig.prod) === null || _g === void 0 ? void 0 : _g.plugins) !== null && _h !== void 0 ? _h : [])]
70
+ });
71
+ });
72
+ }
package/src/utils.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export declare const copyDirFiles: (src: any, dest: any, filter?: (fileName: any) => boolean) => Promise<void>;
2
- export declare const getPort: () => Promise<number>;
3
2
  export declare const colorConfig: {
4
3
  theme: string;
5
4
  warning: string;
package/src/utils.js CHANGED
@@ -19,8 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  return (mod && mod.__esModule) ? mod : { "default": mod };
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.toast = exports.colorConfig = exports.getPort = exports.copyDirFiles = void 0;
23
- const portfinder_1 = __importDefault(require("portfinder"));
22
+ exports.toast = exports.colorConfig = exports.copyDirFiles = void 0;
24
23
  const fs_extra_1 = __importDefault(require("fs-extra"));
25
24
  const path_1 = __importDefault(require("path"));
26
25
  const chalk_1 = __importDefault(require("chalk"));
@@ -63,13 +62,6 @@ const copyDirFiles = (src, dest, filter) => __awaiter(void 0, void 0, void 0, fu
63
62
  yield _copy(src, dest);
64
63
  });
65
64
  exports.copyDirFiles = copyDirFiles;
66
- const getPort = () => {
67
- return portfinder_1.default.getPortPromise({
68
- port: 3000,
69
- stopPort: 3333
70
- });
71
- };
72
- exports.getPort = getPort;
73
65
  exports.colorConfig = {
74
66
  theme: '#7888FCFF',
75
67
  warning: '#fb8918',
@@ -1,2 +0,0 @@
1
- import { GlobalDataType } from '../main-config';
2
- export default function (options: GlobalDataType): Promise<any>;
@@ -1,100 +0,0 @@
1
- import { GlobalDataType } from '../main-config';
2
- export default function ({ projectPath, entryPath, env, customConfig }: GlobalDataType): Promise<{
3
- entry: string;
4
- output: {
5
- path: string;
6
- filename: string;
7
- chunkFilename: string;
8
- cssFilename: string;
9
- cssChunkFilename: string;
10
- assetModuleFilename: string;
11
- publicPath: string;
12
- clean: boolean;
13
- };
14
- experiments: {
15
- css: boolean;
16
- };
17
- target: string[];
18
- module: {
19
- parser: {
20
- 'css/auto': {
21
- namedExports: boolean;
22
- };
23
- };
24
- rules: ({
25
- test: RegExp;
26
- exclude: RegExp;
27
- use: {
28
- loader: string;
29
- options: {
30
- jsc: {
31
- parser: {
32
- syntax: string;
33
- tsx: boolean;
34
- decorators: boolean;
35
- dynamicImport: boolean;
36
- };
37
- transform: {
38
- react: {
39
- runtime: string;
40
- useBuiltins: boolean;
41
- importSource: string;
42
- };
43
- };
44
- target: string;
45
- };
46
- };
47
- }[];
48
- oneOf?: undefined;
49
- } | {
50
- oneOf: ({
51
- test: RegExp;
52
- type: string;
53
- use: (string | {
54
- loader: string;
55
- options: {
56
- api: string;
57
- implementation: string;
58
- };
59
- })[];
60
- generator?: undefined;
61
- loader?: undefined;
62
- } | {
63
- test: RegExp;
64
- type: string;
65
- generator: {
66
- filename: string;
67
- };
68
- use?: undefined;
69
- loader?: undefined;
70
- } | {
71
- test: RegExp;
72
- type: string;
73
- use?: undefined;
74
- generator?: undefined;
75
- loader?: undefined;
76
- } | {
77
- test: RegExp;
78
- loader: string;
79
- type?: undefined;
80
- use?: undefined;
81
- generator?: undefined;
82
- })[];
83
- test?: undefined;
84
- exclude?: undefined;
85
- use?: undefined;
86
- })[];
87
- };
88
- resolve: {
89
- extensions: string[];
90
- alias: {
91
- '@': string;
92
- 'react-router': string;
93
- 'swico/react': string;
94
- swico: string;
95
- qs: string;
96
- };
97
- };
98
- externals: any;
99
- plugins: any[];
100
- }>;
@@ -1,166 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.default = default_1;
16
- const path_1 = __importDefault(require("path"));
17
- const main_config_1 = require("../main-config");
18
- const core_1 = require("@rspack/core");
19
- const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
20
- const lessLoader = require.resolve('less-loader');
21
- const sassLoader = require.resolve('sass-loader');
22
- const postcssLoader = require.resolve('postcss-loader');
23
- function default_1(_a) {
24
- return __awaiter(this, arguments, void 0, function* ({ projectPath, entryPath, env, customConfig }) {
25
- var _b, _c, _d, _e, _f;
26
- const customBaseConfig = customConfig.base;
27
- const getCustomAliasConfig = () => {
28
- const { alias } = customBaseConfig || {};
29
- const custAliasConfig = {};
30
- if (alias) {
31
- Object.keys(alias).forEach((key) => {
32
- custAliasConfig[key] = path_1.default.join(projectPath, `/${alias[key]}`);
33
- });
34
- }
35
- return custAliasConfig;
36
- };
37
- const publicPath = (_b = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.publicPath) !== null && _b !== void 0 ? _b : main_config_1.initConfig.publicPath;
38
- const routerBase = (_d = (_c = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.router) === null || _c === void 0 ? void 0 : _c.base) !== null && _d !== void 0 ? _d : main_config_1.initConfig.router.base;
39
- const initialDefineVarsConfig = {
40
- SWICO_ENV: JSON.stringify(env),
41
- SWICO_ROUTER_BASE: JSON.stringify(routerBase),
42
- SWICO_PUBLIC_PATH: JSON.stringify(publicPath),
43
- SWICO_STATIC_PUBLIC_PATH: JSON.stringify(env === 'prod' ? publicPath : '/')
44
- };
45
- const customDefineVarsConfig = yield (0, main_config_1.getFormatDefineVars)((_e = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.define) !== null && _e !== void 0 ? _e : {});
46
- return {
47
- entry: entryPath,
48
- output: {
49
- path: path_1.default.join(projectPath, '/dist'),
50
- filename: 'js/[name].[chunkhash].js',
51
- chunkFilename: 'js/[name].[chunkhash].js',
52
- cssFilename: 'css/[id].css',
53
- cssChunkFilename: 'css/[id].css',
54
- assetModuleFilename: 'assets/[name]_[chunkhash][ext]',
55
- publicPath,
56
- clean: true
57
- },
58
- experiments: {
59
- css: true
60
- },
61
- target: ['web', 'es2015'],
62
- module: {
63
- parser: {
64
- 'css/auto': {
65
- namedExports: false
66
- }
67
- },
68
- rules: [
69
- {
70
- test: /\.(tsx|ts|jsx)$/,
71
- exclude: /node_modules/,
72
- use: [
73
- {
74
- loader: 'builtin:swc-loader',
75
- options: {
76
- jsc: {
77
- parser: {
78
- syntax: 'typescript',
79
- tsx: true,
80
- decorators: true,
81
- dynamicImport: true
82
- },
83
- transform: {
84
- react: {
85
- runtime: 'automatic',
86
- useBuiltins: true,
87
- importSource: 'react'
88
- }
89
- },
90
- target: 'es2015'
91
- }
92
- }
93
- }
94
- ]
95
- },
96
- {
97
- oneOf: [
98
- {
99
- test: /\.css$/,
100
- type: 'css/auto',
101
- use: [postcssLoader]
102
- },
103
- {
104
- test: /\.less$/,
105
- type: 'css/auto',
106
- use: [postcssLoader, lessLoader]
107
- },
108
- {
109
- test: /\.scss$/,
110
- type: 'css/auto',
111
- use: [
112
- postcssLoader,
113
- {
114
- loader: sassLoader,
115
- options: {
116
- api: 'modern-compiler',
117
- implementation: require.resolve('sass-embedded')
118
- }
119
- }
120
- ]
121
- },
122
- {
123
- test: /\.(jpg|png|gif|webp|bmp|jpeg|svg)$/,
124
- type: 'asset',
125
- generator: {
126
- filename: 'images/[name]_[contenthash][ext]'
127
- }
128
- },
129
- {
130
- test: /\.(otf|eot|woff2?|ttf)$/i,
131
- type: 'asset',
132
- generator: {
133
- filename: 'fonts/[name]_[contenthash][ext]'
134
- }
135
- },
136
- {
137
- test: /\.(txt|xml)$/i,
138
- type: 'asset/source'
139
- },
140
- {
141
- test: /\.html$/,
142
- loader: require.resolve('html-loader')
143
- }
144
- ]
145
- }
146
- ]
147
- },
148
- resolve: {
149
- extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
150
- alias: Object.assign({ '@': path_1.default.join(projectPath, '/src'), 'react-router': path_1.default.dirname(require.resolve('react-router')), 'swico/react': path_1.default.join(projectPath, '/.swico/index'), swico: path_1.default.join(projectPath, '/.swico/index'), qs: path_1.default.dirname(require.resolve('qs')) }, getCustomAliasConfig())
151
- },
152
- externals: customConfig.base.externals,
153
- plugins: [
154
- new html_webpack_plugin_1.default({
155
- template: path_1.default.join(projectPath, '/src/index.ejs'),
156
- filename: 'index.html',
157
- minify: true,
158
- templateParameters: initialDefineVarsConfig,
159
- hash: true
160
- }),
161
- new core_1.rspack.DefinePlugin(Object.assign(Object.assign({}, initialDefineVarsConfig), customDefineVarsConfig)),
162
- ...((_f = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.plugins) !== null && _f !== void 0 ? _f : main_config_1.initConfig.plugins)
163
- ]
164
- };
165
- });
166
- }
@@ -1,135 +0,0 @@
1
- import { GlobalDataType } from '../main-config';
2
- export default function ({ projectPath, entryPath, env, customConfig }: GlobalDataType): Promise<{
3
- entry: string;
4
- output: {
5
- path: string;
6
- filename: string;
7
- chunkFilename: string;
8
- cssFilename: string;
9
- cssChunkFilename: string;
10
- assetModuleFilename: string;
11
- publicPath: string;
12
- clean: boolean;
13
- };
14
- target: string[];
15
- module: {
16
- rules: ({
17
- test: RegExp;
18
- loader: string;
19
- exclude: RegExp;
20
- options: {
21
- experimentalInlineMatchResource: boolean;
22
- };
23
- use?: undefined;
24
- oneOf?: undefined;
25
- type?: undefined;
26
- generator?: undefined;
27
- } | {
28
- test: RegExp;
29
- exclude: RegExp;
30
- use: {
31
- loader: string;
32
- options: {
33
- jsc: {
34
- parser: {
35
- syntax: string;
36
- tsx: boolean;
37
- decorators: boolean;
38
- dynamicImport: boolean;
39
- };
40
- target: string;
41
- };
42
- };
43
- }[];
44
- loader?: undefined;
45
- options?: undefined;
46
- oneOf?: undefined;
47
- type?: undefined;
48
- generator?: undefined;
49
- } | {
50
- oneOf: {
51
- test: RegExp;
52
- oneOf: ({
53
- resourceQuery: RegExp;
54
- use: (string | {
55
- loader: string;
56
- options: {
57
- modules: {
58
- localIdentName: string;
59
- namedExport: boolean;
60
- };
61
- postcssOptions?: undefined;
62
- };
63
- } | {
64
- loader: string;
65
- options: {
66
- postcssOptions: {
67
- plugins: string[][];
68
- };
69
- modules?: undefined;
70
- };
71
- })[];
72
- } | {
73
- use: (string | {
74
- loader: string;
75
- options: {
76
- postcssOptions: {
77
- plugins: string[][];
78
- };
79
- };
80
- })[];
81
- resourceQuery?: undefined;
82
- })[];
83
- }[];
84
- test?: undefined;
85
- loader?: undefined;
86
- exclude?: undefined;
87
- options?: undefined;
88
- use?: undefined;
89
- type?: undefined;
90
- generator?: undefined;
91
- } | {
92
- test: RegExp;
93
- type: string;
94
- generator: {
95
- filename: string;
96
- };
97
- loader?: undefined;
98
- exclude?: undefined;
99
- options?: undefined;
100
- use?: undefined;
101
- oneOf?: undefined;
102
- } | {
103
- test: RegExp;
104
- type: string;
105
- loader?: undefined;
106
- exclude?: undefined;
107
- options?: undefined;
108
- use?: undefined;
109
- oneOf?: undefined;
110
- generator?: undefined;
111
- } | {
112
- test: RegExp;
113
- loader: string;
114
- exclude?: undefined;
115
- options?: undefined;
116
- use?: undefined;
117
- oneOf?: undefined;
118
- type?: undefined;
119
- generator?: undefined;
120
- })[];
121
- };
122
- resolve: {
123
- extensions: string[];
124
- alias: {
125
- '@': string;
126
- vue: string;
127
- 'vue-router': string;
128
- 'swico/vue': string;
129
- swico: string;
130
- qs: string;
131
- };
132
- };
133
- externals: any;
134
- plugins: any[];
135
- }>;