1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | exports.setup = exports.generateVersion = void 0;
|
14 | const path_1 = require("path");
|
15 | const entries_1 = require("./entries");
|
16 | const environment_1 = require("./environment");
|
17 | const icons_1 = require("./icons");
|
18 | const plugins_1 = require("./plugins");
|
19 | const rules_1 = require("./rules");
|
20 | const server_1 = require("./server");
|
21 | __exportStar(require("./entries"), exports);
|
22 | __exportStar(require("./environment"), exports);
|
23 | __exportStar(require("./icons"), exports);
|
24 | __exportStar(require("./plugins"), exports);
|
25 | __exportStar(require("./rules"), exports);
|
26 | __exportStar(require("./server"), exports);
|
27 | __exportStar(require("./types"), exports);
|
28 | function generateVersion() {
|
29 | return new Date()
|
30 | .toISOString()
|
31 | .replace(/([-:])|(\.\d+Z$)/g, '')
|
32 | .replace('T', '.');
|
33 | }
|
34 | exports.generateVersion = generateVersion;
|
35 | async function setup(options = {}) {
|
36 | var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
37 | if (!options.environment || typeof options.environment !== 'string') {
|
38 | options.environment = 'development';
|
39 | }
|
40 | if (!options.version) {
|
41 | options.version = generateVersion();
|
42 | }
|
43 | options.srcFolder = path_1.resolve(process.cwd(), (_a = options.srcFolder) !== null && _a !== void 0 ? _a : 'src');
|
44 | options.destFolder = path_1.resolve(process.cwd(), (_b = options.destFolder) !== null && _b !== void 0 ? _b : 'dist');
|
45 | options.env = environment_1.setupEnvironment(options);
|
46 | options.icons = await icons_1.loadIcons(options);
|
47 | const server = await server_1.setupServer(options);
|
48 | const stats = ((_c = options.stats) !== null && _c !== void 0 ? _c : options.environment === 'production') ? 'normal' : 'errors-only';
|
49 | server.stats = stats;
|
50 | const mainExtension = ((_d = options.useESModules) !== null && _d !== void 0 ? _d : true) ? 'mjs' : 'js';
|
51 | const config = {
|
52 | mode: options.environment === 'production' ? 'production' : 'development',
|
53 | entry: (_e = options.entries) !== null && _e !== void 0 ? _e : (await entries_1.autoDetectEntries(options)),
|
54 | output: {
|
55 | filename: `[name]-[hash].${mainExtension}`,
|
56 | chunkFilename: `[name]-[hash].${mainExtension}`,
|
57 | path: options.destFolder,
|
58 | publicPath: (_f = options.publicPath) !== null && _f !== void 0 ? _f : '/',
|
59 | libraryTarget: options.libraryTarget
|
60 | },
|
61 | target: options.target,
|
62 | module: {
|
63 | rules: await rules_1.setupRules(options)
|
64 | },
|
65 | resolve: { extensions: ['.json', '.js', '.jsx', '.ts', '.tsx'] },
|
66 | plugins: await plugins_1.setupPlugins(options),
|
67 | externals: options.externals,
|
68 | devtool: options.environment === 'development' ? (_g = options.sourceMaps) !== null && _g !== void 0 ? _g : 'source-map' : false,
|
69 | cache: true,
|
70 | devServer: server,
|
71 | performance: (_h = options.performance) !== null && _h !== void 0 ? _h : { hints: false },
|
72 | stats,
|
73 | optimization: {
|
74 | splitChunks: (_k = (_j = options.plugins) === null || _j === void 0 ? void 0 : _j.splitChunks) !== null && _k !== void 0 ? _k : false,
|
75 | concatenateModules: (_m = (_l = options.plugins) === null || _l === void 0 ? void 0 : _l.concatenate) !== null && _m !== void 0 ? _m : true
|
76 | }
|
77 | };
|
78 | return environment_1.runHook(config, options.afterHook);
|
79 | }
|
80 | exports.setup = setup;
|