@qingtian/qtcli 1.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/README.md +193 -0
- package/dist/bin/cli.js +11 -0
- package/dist/package.json +209 -0
- package/dist/qt.conf.js +101 -0
- package/dist/src/App.js +10 -0
- package/dist/src/commands/build.js +74 -0
- package/dist/src/commands/dev.js +68 -0
- package/dist/src/commands/index.js +83 -0
- package/dist/src/commands/init.js +128 -0
- package/dist/src/cores/context.js +123 -0
- package/dist/src/index.js +29 -0
- package/dist/src/processEnv/index.js +23 -0
- package/dist/src/processEnv/injector.js +39 -0
- package/dist/src/processEnv/loader.js +201 -0
- package/dist/src/processEnv/manager.js +122 -0
- package/dist/src/processEnv/types.js +2 -0
- package/dist/src/proxys/build/index.js +225 -0
- package/dist/src/proxys/dev/index.js +284 -0
- package/dist/src/proxys/init/index.js +90 -0
- package/dist/src/servers/server.js +46 -0
- package/dist/src/types/baseInterface.js +46 -0
- package/dist/src/types/contextModel.js +21 -0
- package/dist/src/utils/childProcess.js +134 -0
- package/dist/src/utils/env.js +56 -0
- package/dist/src/utils/fileUtils.js +121 -0
- package/dist/src/utils/format.js +23 -0
- package/dist/src/utils/formatOutput.js +242 -0
- package/dist/src/utils/logger.js +70 -0
- package/dist/src/utils/printer.js +148 -0
- package/dist/src/utils/sleep.js +11 -0
- package/dist/src/utils/url.js +42 -0
- package/dist/src/webpack/npm/es.js +127 -0
- package/dist/src/webpack/npm/index.js +100 -0
- package/dist/src/webpack/npm/lib.js +128 -0
- package/dist/src/webpack/npm/webpack.base.js +221 -0
- package/dist/src/webpack/npm/webpack.prod.js +76 -0
- package/dist/src/webpack/plugins/DonePlugin.js +14 -0
- package/dist/src/webpack/plugins/FileListPlugin.js +28 -0
- package/dist/src/webpack/plugins/InjectScriptPlugin.js +33 -0
- package/dist/src/webpack/web/index.js +130 -0
- package/dist/src/webpack/web/webpack.analy.js +10 -0
- package/dist/src/webpack/web/webpack.base.js +419 -0
- package/dist/src/webpack/web/webpack.dev.js +38 -0
- package/dist/src/webpack/web/webpack.prod.js +82 -0
- package/package.json +209 -0
|
@@ -0,0 +1,100 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var webpack_1 = __importDefault(require("webpack"));
|
|
43
|
+
var printer_1 = require("../../utils/printer");
|
|
44
|
+
var es_1 = __importDefault(require("./es"));
|
|
45
|
+
var lib_1 = __importDefault(require("./lib"));
|
|
46
|
+
var _process = global.process;
|
|
47
|
+
var webpackProdConfig = require('./webpack.prod').default;
|
|
48
|
+
var command = process.argv[2] || 'dev';
|
|
49
|
+
function build() {
|
|
50
|
+
var _this = this;
|
|
51
|
+
var compiler = (0, webpack_1.default)(webpackProdConfig);
|
|
52
|
+
compiler.run(function (err, stats) { return __awaiter(_this, void 0, void 0, function () {
|
|
53
|
+
var info, ptime, time;
|
|
54
|
+
return __generator(this, function (_a) {
|
|
55
|
+
switch (_a.label) {
|
|
56
|
+
case 0:
|
|
57
|
+
if (!err) return [3 /*break*/, 1];
|
|
58
|
+
printer_1.printer.log('--构建出错--', err);
|
|
59
|
+
if (process && process.send) {
|
|
60
|
+
process.send({ type: 'buildError', data: err.message });
|
|
61
|
+
}
|
|
62
|
+
throw err;
|
|
63
|
+
case 1:
|
|
64
|
+
info = stats.toJson();
|
|
65
|
+
if (process && process.send) {
|
|
66
|
+
process.send({
|
|
67
|
+
type: 'buildSuccess',
|
|
68
|
+
data: {
|
|
69
|
+
time: stats.endTime - stats.startTime,
|
|
70
|
+
errors: info.errors,
|
|
71
|
+
warings: info.warings,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
ptime = new Date().getTime();
|
|
76
|
+
_process.send({ type: 'beforeLibBuild', data: {} });
|
|
77
|
+
return [4 /*yield*/, (0, lib_1.default)()];
|
|
78
|
+
case 2:
|
|
79
|
+
_a.sent();
|
|
80
|
+
time = new Date().getTime() - ptime;
|
|
81
|
+
_process.send({ type: 'afterLibBuild', data: { time: time } });
|
|
82
|
+
ptime = new Date().getTime();
|
|
83
|
+
_process.send({ type: 'beforeEsBuild', data: {} });
|
|
84
|
+
return [4 /*yield*/, (0, es_1.default)()];
|
|
85
|
+
case 3:
|
|
86
|
+
_a.sent();
|
|
87
|
+
time = new Date().getTime() - ptime;
|
|
88
|
+
_process.send({ type: 'afterEsBuild', data: { time: time } });
|
|
89
|
+
_a.label = 4;
|
|
90
|
+
case 4: return [2 /*return*/];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}); });
|
|
94
|
+
compiler.hooks.done.tap('DonePlugin', function () {
|
|
95
|
+
if (process && process.send) {
|
|
96
|
+
process.send({ type: 'DonePlugin', data: 111 });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
command === 'build' && build();
|
|
@@ -0,0 +1,128 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
/* eslint-disable no-async-promise-executor */
|
|
40
|
+
// import babelDir from '@babel/cli/lib/babel/dir';
|
|
41
|
+
var babelDir = require('@babel/cli/lib/babel/dir');
|
|
42
|
+
var _a = require('../../utils/childProcess'), execPromise = _a.execPromise, forkPromise = _a.forkPromise;
|
|
43
|
+
var path = require('path');
|
|
44
|
+
var rimraf = require('rimraf').rimraf;
|
|
45
|
+
exports.default = (function () {
|
|
46
|
+
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
+
var rm, err_1;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
_a.trys.push([0, 2, , 3]);
|
|
52
|
+
return [4 /*yield*/, rimraf.rimraf('lib', {})];
|
|
53
|
+
case 1:
|
|
54
|
+
rm = _a.sent();
|
|
55
|
+
if (rm) {
|
|
56
|
+
console.log('删除lib/成功');
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.log('删除lib/失败');
|
|
60
|
+
}
|
|
61
|
+
babelDir({
|
|
62
|
+
cliOptions: {
|
|
63
|
+
filenames: ['src/'],
|
|
64
|
+
outDir: 'lib/',
|
|
65
|
+
extensions: ['.ts', '.tsx', '.js', '.jsx'],
|
|
66
|
+
copyFiles: true,
|
|
67
|
+
},
|
|
68
|
+
babelOptions: {
|
|
69
|
+
ignore: ['**/.d.ts'],
|
|
70
|
+
sourceMaps: true,
|
|
71
|
+
presets: [
|
|
72
|
+
[
|
|
73
|
+
require.resolve('@babel/preset-env'),
|
|
74
|
+
{
|
|
75
|
+
modules: 'cjs',
|
|
76
|
+
targets: {
|
|
77
|
+
node: 'current',
|
|
78
|
+
},
|
|
79
|
+
corejs: 3,
|
|
80
|
+
useBuiltIns: 'entry',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
require.resolve('@babel/preset-react'),
|
|
85
|
+
{
|
|
86
|
+
runtime: 'automatic',
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
require.resolve('@babel/preset-flow'),
|
|
90
|
+
require.resolve('@babel/preset-typescript'),
|
|
91
|
+
],
|
|
92
|
+
plugins: [
|
|
93
|
+
[
|
|
94
|
+
require.resolve('@babel/plugin-transform-runtime'),
|
|
95
|
+
{
|
|
96
|
+
useEsModules: false,
|
|
97
|
+
absoluteRuntime: false,
|
|
98
|
+
corejs: false,
|
|
99
|
+
helpers: true,
|
|
100
|
+
regenerator: true,
|
|
101
|
+
version: '7.0.0-beta.0',
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
require.resolve('@babel/plugin-syntax-flow'),
|
|
105
|
+
require.resolve('@babel/plugin-transform-typescript'),
|
|
106
|
+
require.resolve('@babel/plugin-transform-flow-strip-types'),
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
forkPromise('node_modules/.bin/tsc', ['--outDir', 'lib', '--declaration', '--emitDeclarationOnly', '--listEmittedFiles'], {
|
|
111
|
+
cwd: path.resolve(process.cwd(), './'),
|
|
112
|
+
}).then(function () {
|
|
113
|
+
console.log('生成.d.ts完成');
|
|
114
|
+
execPromise('cp src/global.d.ts lib/');
|
|
115
|
+
resolve(true);
|
|
116
|
+
}, function (err) {
|
|
117
|
+
reject(err);
|
|
118
|
+
});
|
|
119
|
+
return [3 /*break*/, 3];
|
|
120
|
+
case 2:
|
|
121
|
+
err_1 = _a.sent();
|
|
122
|
+
reject(err_1);
|
|
123
|
+
return [3 /*break*/, 3];
|
|
124
|
+
case 3: return [2 /*return*/];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}); });
|
|
128
|
+
});
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var DonePlugin_1 = __importDefault(require("../plugins/DonePlugin"));
|
|
7
|
+
var FileListPlugin_1 = __importDefault(require("../plugins/FileListPlugin"));
|
|
8
|
+
var path = require('path');
|
|
9
|
+
var webpack = require('webpack');
|
|
10
|
+
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
11
|
+
var config = {
|
|
12
|
+
entry: {
|
|
13
|
+
QTComponents: path.resolve(process.cwd(), './src/index.tsx'),
|
|
14
|
+
},
|
|
15
|
+
output: {
|
|
16
|
+
filename: '[name].js',
|
|
17
|
+
path: path.resolve(process.cwd(), './dist'),
|
|
18
|
+
clean: true,
|
|
19
|
+
publicPath: '/',
|
|
20
|
+
library: {
|
|
21
|
+
name: '[name]',
|
|
22
|
+
type: 'umd',
|
|
23
|
+
},
|
|
24
|
+
umdNamedDefine: true,
|
|
25
|
+
},
|
|
26
|
+
externals: {
|
|
27
|
+
react: 'React',
|
|
28
|
+
'react-dom': 'ReactDOM',
|
|
29
|
+
dayjs: 'dayjs',
|
|
30
|
+
lodash: '_',
|
|
31
|
+
antd: 'antd',
|
|
32
|
+
},
|
|
33
|
+
cache: {
|
|
34
|
+
type: 'filesystem',
|
|
35
|
+
},
|
|
36
|
+
module: {
|
|
37
|
+
rules: [
|
|
38
|
+
{
|
|
39
|
+
test: /.(ts|tsx|js|jsx)$/,
|
|
40
|
+
include: [path.resolve(process.cwd(), './src')],
|
|
41
|
+
use: {
|
|
42
|
+
loader: require.resolve('babel-loader'),
|
|
43
|
+
options: {
|
|
44
|
+
presets: [
|
|
45
|
+
[
|
|
46
|
+
require.resolve('@babel/preset-env'),
|
|
47
|
+
{
|
|
48
|
+
modules: false,
|
|
49
|
+
targets: {
|
|
50
|
+
chrome: 35,
|
|
51
|
+
ie: 9,
|
|
52
|
+
},
|
|
53
|
+
useBuiltIns: 'usage',
|
|
54
|
+
corejs: 3,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
require.resolve('@babel/preset-react'),
|
|
58
|
+
require.resolve('@babel/preset-typescript'),
|
|
59
|
+
],
|
|
60
|
+
plugins: [
|
|
61
|
+
[
|
|
62
|
+
require.resolve('@babel/plugin-transform-runtime'),
|
|
63
|
+
{
|
|
64
|
+
useESModules: true,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
test: /.css$/,
|
|
73
|
+
// include: [path.resolve(process.cwd(), './src')],
|
|
74
|
+
exclude: [/\.module\.(css|less)/, /\.global\.less$/],
|
|
75
|
+
use: [
|
|
76
|
+
true ? require.resolve('style-loader') : MiniCssExtractPlugin.loader,
|
|
77
|
+
{
|
|
78
|
+
loader: require.resolve('css-loader'),
|
|
79
|
+
// options: {
|
|
80
|
+
// modules: true,
|
|
81
|
+
// }
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
loader: require.resolve('postcss-loader'),
|
|
85
|
+
options: {
|
|
86
|
+
postcssOptions: {
|
|
87
|
+
plugins: ['autoprefixer'],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
test: /.less$/,
|
|
95
|
+
// include: [path.resolve(process.cwd(), './src')],
|
|
96
|
+
exclude: [/\.module\.(css|less)/, /\.global\.less$/],
|
|
97
|
+
use: [
|
|
98
|
+
true ? require.resolve('style-loader') : MiniCssExtractPlugin.loader,
|
|
99
|
+
{
|
|
100
|
+
loader: require.resolve('css-loader'),
|
|
101
|
+
// options: {
|
|
102
|
+
// modules: true,
|
|
103
|
+
// }
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
loader: require.resolve('postcss-loader'),
|
|
107
|
+
options: {
|
|
108
|
+
postcssOptions: {
|
|
109
|
+
plugins: ['autoprefixer'],
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
loader: require.resolve('less-loader'),
|
|
115
|
+
options: {
|
|
116
|
+
lessOptions: {
|
|
117
|
+
javascriptEnabled: true,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
test: /\.module\.less/,
|
|
125
|
+
// include: [path.resolve(process.cwd(), './src')],
|
|
126
|
+
exclude: [/\.module\.(css|less)/, /\.global\.less$/],
|
|
127
|
+
use: [
|
|
128
|
+
true ? require.resolve('style-loader') : MiniCssExtractPlugin.loader,
|
|
129
|
+
{
|
|
130
|
+
loader: require.resolve('css-loader'),
|
|
131
|
+
options: {
|
|
132
|
+
modules: {
|
|
133
|
+
localIdentName: '[path][name]__[local]--[contenthash:base64]',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
loader: require.resolve('postcss-loader'),
|
|
139
|
+
options: {
|
|
140
|
+
postcssOptions: {
|
|
141
|
+
plugins: ['autoprefixer'],
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
loader: require.resolve('less-loader'),
|
|
147
|
+
options: {
|
|
148
|
+
lessOptions: {
|
|
149
|
+
javascriptEnabled: true,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
test: /.(png|jpg|jpeg|git|svg)$/,
|
|
157
|
+
type: 'asset/resource',
|
|
158
|
+
parser: {
|
|
159
|
+
detaUrlCondition: {
|
|
160
|
+
maxSize: 10 * 1024,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
generator: {
|
|
164
|
+
filename: 'static/images/[contenthash][ext][query]',
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
test: /.(woff2?|eot|ttf|otf)$/,
|
|
169
|
+
type: 'asset',
|
|
170
|
+
parser: {
|
|
171
|
+
detaUrlCondition: {
|
|
172
|
+
maxSize: 10 * 1024,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
generator: {
|
|
176
|
+
filename: 'static/fonts/[name][contenthash][ext]',
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
test: /.(mp4|webm|ogg|mp3|wav|flac|aac)$/,
|
|
181
|
+
type: 'asset',
|
|
182
|
+
parser: {
|
|
183
|
+
detaUrlCondition: {
|
|
184
|
+
maxSize: 10 * 1024,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
generator: {
|
|
188
|
+
filename: 'static/media/[contenthash][ext]',
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
plugins: [
|
|
194
|
+
new webpack.DefinePlugin({
|
|
195
|
+
'process.env.BASE_ENV': JSON.stringify(process.env.BASE_ENV),
|
|
196
|
+
}),
|
|
197
|
+
new webpack.ProgressPlugin({
|
|
198
|
+
handler: function (percentage) {
|
|
199
|
+
process && process.send && process.send({ type: 'progress', data: percentage || 0 });
|
|
200
|
+
},
|
|
201
|
+
}),
|
|
202
|
+
new DonePlugin_1.default(),
|
|
203
|
+
new FileListPlugin_1.default({
|
|
204
|
+
filename: 'list.md',
|
|
205
|
+
}),
|
|
206
|
+
].filter(function (v) {
|
|
207
|
+
return v;
|
|
208
|
+
}),
|
|
209
|
+
resolve: {
|
|
210
|
+
modules: ['node_modules', path.resolve(__dirname, '../../../node_modules')],
|
|
211
|
+
extensions: ['.js', '.jsx', '.tsx', '.ts', '.less'],
|
|
212
|
+
alias: {
|
|
213
|
+
'@': path.resolve(process.cwd(), './src'),
|
|
214
|
+
react: path.resolve(process.cwd(), './node_modules/react'),
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
resolveLoader: {
|
|
218
|
+
modules: [path.resolve(__filename, '../../../node_modules')],
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
exports.default = config;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var merge = require('webpack-merge').merge;
|
|
9
|
+
var baseConfig = require('./webpack.base').default;
|
|
10
|
+
var CopyPlugin = require('copy-webpack-plugin');
|
|
11
|
+
exports.default = merge(baseConfig, {
|
|
12
|
+
mode: 'production',
|
|
13
|
+
plugins: [
|
|
14
|
+
new CopyPlugin({
|
|
15
|
+
patterns: [
|
|
16
|
+
{
|
|
17
|
+
from: path.resolve(process.cwd(), './public'),
|
|
18
|
+
to: path.resolve(process.cwd(), './dist'),
|
|
19
|
+
filter: function (source) {
|
|
20
|
+
return !source.includes('index.html');
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
}),
|
|
25
|
+
new mini_css_extract_plugin_1.default({
|
|
26
|
+
filename: 'static/css/[name].[contenthash].css',
|
|
27
|
+
}),
|
|
28
|
+
// new PurgeCSSPlugin({
|
|
29
|
+
// paths: globAll.sync([
|
|
30
|
+
// `${path.join(process.cwd(), './src')}/**/*.tsx`,
|
|
31
|
+
// path.join(process.cwd(), './public/index.html')
|
|
32
|
+
// ]),
|
|
33
|
+
// safelist: {
|
|
34
|
+
// standard: [/^ant-/],
|
|
35
|
+
// }
|
|
36
|
+
// }),
|
|
37
|
+
// new CompressionPlugin({
|
|
38
|
+
// test: /.(js|css)$/,
|
|
39
|
+
// filename: '[path][base].gz',
|
|
40
|
+
// algorithm: 'gzip',
|
|
41
|
+
// threshold: 1024,
|
|
42
|
+
// minRatio: 0.8,
|
|
43
|
+
// })
|
|
44
|
+
],
|
|
45
|
+
// optimization: {
|
|
46
|
+
// splitChunks: {
|
|
47
|
+
// cacheGroups: {
|
|
48
|
+
// vendors: {
|
|
49
|
+
// test: /node_modules/,
|
|
50
|
+
// name: 'vendors',
|
|
51
|
+
// minChunks: 1,
|
|
52
|
+
// chunks: 'initial',
|
|
53
|
+
// minSize: 100,
|
|
54
|
+
// priority: 1,
|
|
55
|
+
// },
|
|
56
|
+
// commons: {
|
|
57
|
+
// name: 'commons',
|
|
58
|
+
// minChunks: 2,
|
|
59
|
+
// chunks: 'initial',
|
|
60
|
+
// minSize: 100,
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
63
|
+
// },
|
|
64
|
+
// minimizer: [
|
|
65
|
+
// new CssMinimizerPlugin(),
|
|
66
|
+
// new TerserPlugin({
|
|
67
|
+
// parallel: true,
|
|
68
|
+
// terserOptions: {
|
|
69
|
+
// compress: {
|
|
70
|
+
// pure_funcs: ["console.log"]
|
|
71
|
+
// }
|
|
72
|
+
// }
|
|
73
|
+
// })
|
|
74
|
+
// ]
|
|
75
|
+
// }
|
|
76
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-useless-constructor */
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
var DonePlugin = /** @class */ (function () {
|
|
6
|
+
function DonePlugin() {
|
|
7
|
+
}
|
|
8
|
+
DonePlugin.prototype.apply = function (compiler) {
|
|
9
|
+
compiler.hooks.done.tap('DonePlugin', function () { });
|
|
10
|
+
compiler.hooks.compile.tap('compile', function () { });
|
|
11
|
+
};
|
|
12
|
+
return DonePlugin;
|
|
13
|
+
}());
|
|
14
|
+
exports.default = DonePlugin;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var FileListPlugin = /** @class */ (function () {
|
|
4
|
+
function FileListPlugin(_a) {
|
|
5
|
+
var filename = _a.filename;
|
|
6
|
+
this.filename = filename;
|
|
7
|
+
}
|
|
8
|
+
FileListPlugin.prototype.apply = function (compiler) {
|
|
9
|
+
compiler.hooks.emit.tap('FileListPlugin', function (compilation) {
|
|
10
|
+
var list = [];
|
|
11
|
+
var assets = compilation.assets;
|
|
12
|
+
Object.entries(assets).forEach(function (_a) {
|
|
13
|
+
var filename = _a[0], stateObj = _a[1];
|
|
14
|
+
if (!/(\.js\.map)|(\.gz)/.test(filename)) {
|
|
15
|
+
list.push({
|
|
16
|
+
filename: filename,
|
|
17
|
+
size: "".concat((stateObj.size() / 1024).toFixed(2), " kb"),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (process && process.send) {
|
|
22
|
+
process.send({ type: 'listEnd', data: list });
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return FileListPlugin;
|
|
27
|
+
}());
|
|
28
|
+
exports.default = FileListPlugin;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
4
|
+
var InjectScriptPlugin = /** @class */ (function () {
|
|
5
|
+
function InjectScriptPlugin(options) {
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
InjectScriptPlugin.prototype.apply = function (compiler) {
|
|
9
|
+
var _this = this;
|
|
10
|
+
compiler.hooks.compilation.tap('InjectScriptPlugin', function (compilation) {
|
|
11
|
+
HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tap('InjectScriptPlugin', function (htmlPluginData) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
// 注入 head 中的代码片段
|
|
14
|
+
if ((_a = _this.options.headScripts) === null || _a === void 0 ? void 0 : _a.length) {
|
|
15
|
+
var headScripts = _this.options.headScripts
|
|
16
|
+
.map(function (script) { return "<script>".concat(script.code, "</script>"); })
|
|
17
|
+
.join('\n');
|
|
18
|
+
htmlPluginData.html = htmlPluginData.html.replace('</head>', "".concat(headScripts, "\n</head>"));
|
|
19
|
+
}
|
|
20
|
+
// 注入 body 中的代码片段
|
|
21
|
+
if ((_b = _this.options.bodyScripts) === null || _b === void 0 ? void 0 : _b.length) {
|
|
22
|
+
var bodyScripts = _this.options.bodyScripts
|
|
23
|
+
.map(function (script) { return "<script>".concat(script.code, "</script>"); })
|
|
24
|
+
.join('\n');
|
|
25
|
+
htmlPluginData.html = htmlPluginData.html.replace('</body>', "".concat(bodyScripts, "\n</body>"));
|
|
26
|
+
}
|
|
27
|
+
return htmlPluginData;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
return InjectScriptPlugin;
|
|
32
|
+
}());
|
|
33
|
+
exports.default = InjectScriptPlugin;
|