swico 0.1.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.
Files changed (56) hide show
  1. package/package.json +90 -0
  2. package/src/bin.d.ts +2 -0
  3. package/src/bin.js +46 -0
  4. package/src/command/build.d.ts +1 -0
  5. package/src/command/build.js +91 -0
  6. package/src/command/start.d.ts +1 -0
  7. package/src/command/start.js +166 -0
  8. package/src/config/webpack.base.react.d.ts +82 -0
  9. package/src/config/webpack.base.react.js +286 -0
  10. package/src/config/webpack.base.vue.d.ts +106 -0
  11. package/src/config/webpack.base.vue.js +303 -0
  12. package/src/config/webpack.dev.d.ts +2 -0
  13. package/src/config/webpack.dev.js +140 -0
  14. package/src/config/webpack.prod.d.ts +2 -0
  15. package/src/config/webpack.prod.js +183 -0
  16. package/src/index.d.ts +15 -0
  17. package/src/index.js +10 -0
  18. package/src/index.react.d.ts +19 -0
  19. package/src/index.react.js +19 -0
  20. package/src/index.vue.d.ts +34 -0
  21. package/src/index.vue.js +29 -0
  22. package/src/task.d.ts +1 -0
  23. package/src/task.js +61 -0
  24. package/src/template/global.d.ts +3 -0
  25. package/src/template/global.js +3 -0
  26. package/src/template/hooks/react.d.ts +12 -0
  27. package/src/template/hooks/react.js +45 -0
  28. package/src/template/hooks/vue.d.ts +2 -0
  29. package/src/template/hooks/vue.js +34 -0
  30. package/src/template/layout/Layout.d.ts +2 -0
  31. package/src/template/layout/Layout.js +6 -0
  32. package/src/template/layout/index.d.ts +4 -0
  33. package/src/template/layout/index.js +6 -0
  34. package/src/template/react/config.d.ts +3 -0
  35. package/src/template/react/config.js +5 -0
  36. package/src/template/react/history.d.ts +11 -0
  37. package/src/template/react/history.js +109 -0
  38. package/src/template/react/index.d.ts +11 -0
  39. package/src/template/react/index.js +63 -0
  40. package/src/template/react/loading.d.ts +2 -0
  41. package/src/template/react/loading.js +3 -0
  42. package/src/template/react/routes.d.ts +3 -0
  43. package/src/template/react/routes.js +3 -0
  44. package/src/template/vue/Container.d.ts +2 -0
  45. package/src/template/vue/Container.js +4 -0
  46. package/src/template/vue/Container.vue +7 -0
  47. package/src/template/vue/config.d.ts +3 -0
  48. package/src/template/vue/config.js +5 -0
  49. package/src/template/vue/index.d.ts +1 -0
  50. package/src/template/vue/index.js +46 -0
  51. package/src/template/vue/routes.d.ts +6 -0
  52. package/src/template/vue/routes.js +3 -0
  53. package/src/utils/config.d.ts +47 -0
  54. package/src/utils/config.js +394 -0
  55. package/src/utils/tools.d.ts +7 -0
  56. package/src/utils/tools.js +141 -0
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
58
+ var __importDefault = (this && this.__importDefault) || function (mod) {
59
+ return (mod && mod.__esModule) ? mod : { "default": mod };
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ var path_1 = __importDefault(require("path"));
63
+ var mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
64
+ var config_1 = require("../utils/config");
65
+ var webpackbar_1 = __importDefault(require("webpackbar"));
66
+ var html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
67
+ var fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
68
+ var webpack_1 = __importDefault(require("webpack"));
69
+ function default_1(_a) {
70
+ var _b, _c, _d;
71
+ var projectPath = _a.projectPath, entryPath = _a.entryPath, env = _a.env, customConfig = _a.customConfig;
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ var customBaseConfig, getCustomAliasConfig, publicPath, routerBase, basicPlugins, defineConfigData, formatObj;
74
+ return __generator(this, function (_e) {
75
+ switch (_e.label) {
76
+ case 0:
77
+ customBaseConfig = customConfig.base;
78
+ getCustomAliasConfig = function () {
79
+ var alias = (customBaseConfig || {}).alias;
80
+ var custAliasConfig = {};
81
+ if (alias) {
82
+ Object.keys(alias).forEach(function (key) {
83
+ custAliasConfig[key] = path_1.default.join(projectPath, "/".concat(alias[key]));
84
+ });
85
+ }
86
+ return custAliasConfig;
87
+ };
88
+ publicPath = (customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.publicPath) || config_1.initConfig.publicPath;
89
+ routerBase = ((_b = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.router) === null || _b === void 0 ? void 0 : _b.base) || config_1.initConfig.router.base;
90
+ basicPlugins = [];
91
+ defineConfigData = (_d = (_c = customConfig === null || customConfig === void 0 ? void 0 : customConfig.base) === null || _c === void 0 ? void 0 : _c.define) !== null && _d !== void 0 ? _d : {};
92
+ return [4, (0, config_1.getFormatDefineVars)(defineConfigData)];
93
+ case 1:
94
+ formatObj = _e.sent();
95
+ if (Object.keys(formatObj).length !== 0) {
96
+ basicPlugins.push(new webpack_1.default.DefinePlugin(formatObj));
97
+ }
98
+ return [2, {
99
+ entry: entryPath,
100
+ output: {
101
+ path: path_1.default.join(projectPath, '/dist'),
102
+ filename: 'js/[name].[chunkhash].js',
103
+ assetModuleFilename: 'assets/[name]_[chunkhash][ext]',
104
+ publicPath: publicPath,
105
+ clean: true
106
+ },
107
+ target: ['web', 'es5'],
108
+ cache: {
109
+ type: 'filesystem'
110
+ },
111
+ module: {
112
+ rules: [
113
+ {
114
+ test: /\.(tsx|ts|jsx)$/,
115
+ exclude: /node_modules/,
116
+ use: [
117
+ {
118
+ loader: 'swc-loader',
119
+ options: {
120
+ jsc: {
121
+ parser: {
122
+ syntax: 'typescript',
123
+ tsx: true,
124
+ decorators: true,
125
+ dynamicImport: true
126
+ },
127
+ transform: {
128
+ react: {
129
+ runtime: 'automatic',
130
+ useBuiltins: true,
131
+ importSource: 'react'
132
+ }
133
+ },
134
+ target: 'es2015'
135
+ }
136
+ }
137
+ }
138
+ ]
139
+ },
140
+ {
141
+ oneOf: [
142
+ {
143
+ test: /\.module\.css$/,
144
+ use: [
145
+ env === 'dev' ? 'style-loader' : mini_css_extract_plugin_1.default.loader,
146
+ {
147
+ loader: 'css-loader',
148
+ options: {
149
+ modules: {
150
+ localIdentName: 'moduleStyle_[local]_[contenthash:8]'
151
+ }
152
+ }
153
+ },
154
+ {
155
+ loader: 'postcss-loader',
156
+ options: {
157
+ postcssOptions: {
158
+ plugins: [['autoprefixer']]
159
+ }
160
+ }
161
+ }
162
+ ]
163
+ },
164
+ {
165
+ test: /\.css$/,
166
+ use: [
167
+ env === 'dev' ? 'style-loader' : mini_css_extract_plugin_1.default.loader,
168
+ 'css-loader',
169
+ {
170
+ loader: 'postcss-loader',
171
+ options: {
172
+ postcssOptions: {
173
+ plugins: [['autoprefixer']]
174
+ }
175
+ }
176
+ }
177
+ ]
178
+ },
179
+ {
180
+ test: /\.module\.less$/,
181
+ use: [
182
+ env === 'dev' ? 'style-loader' : mini_css_extract_plugin_1.default.loader,
183
+ {
184
+ loader: 'css-loader',
185
+ options: {
186
+ modules: {
187
+ localIdentName: 'moduleStyle_[local]_[contenthash:8]'
188
+ }
189
+ }
190
+ },
191
+ {
192
+ loader: 'postcss-loader',
193
+ options: {
194
+ postcssOptions: {
195
+ plugins: [['postcss-preset-env', 'autoprefixer']]
196
+ }
197
+ }
198
+ },
199
+ 'less-loader'
200
+ ]
201
+ },
202
+ {
203
+ test: /\.less$/,
204
+ use: [
205
+ env === 'dev' ? 'style-loader' : mini_css_extract_plugin_1.default.loader,
206
+ 'css-loader',
207
+ {
208
+ loader: 'postcss-loader',
209
+ options: {
210
+ postcssOptions: {
211
+ plugins: [['autoprefixer']]
212
+ }
213
+ }
214
+ },
215
+ 'less-loader'
216
+ ]
217
+ },
218
+ {
219
+ test: /\.(jpg|png|gif|webp|bmp|jpeg|svg)$/,
220
+ type: 'asset',
221
+ generator: {
222
+ filename: 'images/[name]_[hash][ext]'
223
+ }
224
+ },
225
+ {
226
+ test: /\.(otf|eot|woff2?|ttf)$/i,
227
+ type: 'asset',
228
+ generator: {
229
+ filename: 'fonts/[name]_[hash][ext]'
230
+ }
231
+ },
232
+ {
233
+ test: /\.(txt|xml)$/i,
234
+ type: 'asset/source'
235
+ },
236
+ {
237
+ test: /\.html$/,
238
+ loader: 'html-loader'
239
+ }
240
+ ]
241
+ }
242
+ ]
243
+ },
244
+ resolve: {
245
+ extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
246
+ alias: __assign({ '@': path_1.default.join(projectPath, '/src') }, getCustomAliasConfig())
247
+ },
248
+ externals: customConfig.base.externals,
249
+ plugins: __spreadArray(__spreadArray(__spreadArray([], basicPlugins, true), [
250
+ new html_webpack_plugin_1.default({
251
+ template: path_1.default.join(projectPath, '/src/index.ejs'),
252
+ filename: 'index.html',
253
+ minify: {
254
+ collapseWhitespace: true,
255
+ removeAttributeQuotes: true
256
+ },
257
+ templateParameters: {
258
+ publicPath: publicPath,
259
+ routerBase: routerBase
260
+ },
261
+ hash: true
262
+ }),
263
+ new fork_ts_checker_webpack_plugin_1.default({
264
+ typescript: {
265
+ diagnosticOptions: {
266
+ semantic: true,
267
+ syntactic: true
268
+ }
269
+ }
270
+ }),
271
+ new mini_css_extract_plugin_1.default({
272
+ filename: env === 'dev' ? 'css/[name].css' : 'css/[name].[contenthash].css',
273
+ ignoreOrder: true
274
+ }),
275
+ new webpackbar_1.default({
276
+ name: 'Secywo',
277
+ color: '#5f72f5',
278
+ profile: false
279
+ })
280
+ ], false), ((customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.plugins) || config_1.initConfig.plugins), true)
281
+ }];
282
+ }
283
+ });
284
+ });
285
+ }
286
+ exports.default = default_1;
@@ -0,0 +1,106 @@
1
+ import { GlobalData } from '../utils/config';
2
+ export default function ({ projectPath, entryPath, env, customConfig }: GlobalData): Promise<{
3
+ entry: string;
4
+ output: {
5
+ path: string;
6
+ filename: string;
7
+ assetModuleFilename: string;
8
+ publicPath: string;
9
+ clean: boolean;
10
+ };
11
+ target: string[];
12
+ cache: {
13
+ type: string;
14
+ };
15
+ module: {
16
+ rules: ({
17
+ test: RegExp;
18
+ loader: string;
19
+ exclude: RegExp;
20
+ use?: undefined;
21
+ oneOf?: undefined;
22
+ } | {
23
+ test: RegExp;
24
+ exclude: RegExp;
25
+ use: {
26
+ loader: string;
27
+ options: {
28
+ jsc: {
29
+ parser: {
30
+ syntax: string;
31
+ tsx: boolean;
32
+ decorators: boolean;
33
+ dynamicImport: boolean;
34
+ };
35
+ target: string;
36
+ };
37
+ };
38
+ }[];
39
+ loader?: undefined;
40
+ oneOf?: undefined;
41
+ } | {
42
+ oneOf: ({
43
+ test: RegExp;
44
+ oneOf: ({
45
+ resourceQuery: RegExp;
46
+ use: (string | {
47
+ loader: string;
48
+ options: {
49
+ modules: {
50
+ localIdentName: string;
51
+ };
52
+ postcssOptions?: undefined;
53
+ };
54
+ } | {
55
+ loader: string;
56
+ options: {
57
+ postcssOptions: {
58
+ plugins: string[][];
59
+ };
60
+ modules?: undefined;
61
+ };
62
+ })[];
63
+ } | {
64
+ use: any[];
65
+ resourceQuery?: undefined;
66
+ })[];
67
+ type?: undefined;
68
+ generator?: undefined;
69
+ loader?: undefined;
70
+ } | {
71
+ test: RegExp;
72
+ type: string;
73
+ generator: {
74
+ filename: string;
75
+ };
76
+ oneOf?: undefined;
77
+ loader?: undefined;
78
+ } | {
79
+ test: RegExp;
80
+ type: string;
81
+ oneOf?: undefined;
82
+ generator?: undefined;
83
+ loader?: undefined;
84
+ } | {
85
+ test: RegExp;
86
+ loader: string;
87
+ oneOf?: undefined;
88
+ type?: undefined;
89
+ generator?: undefined;
90
+ })[];
91
+ test?: undefined;
92
+ loader?: undefined;
93
+ exclude?: undefined;
94
+ use?: undefined;
95
+ })[];
96
+ };
97
+ resolve: {
98
+ extensions: string[];
99
+ alias: {
100
+ '@': string;
101
+ vue: string;
102
+ };
103
+ };
104
+ externals: any;
105
+ plugins: any[];
106
+ }>;