@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,130 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _a;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
/* eslint-disable no-nested-ternary */
|
|
19
|
+
var path_1 = __importDefault(require("path"));
|
|
20
|
+
var webpack_1 = __importDefault(require("webpack"));
|
|
21
|
+
var webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
22
|
+
var processEnv_1 = require("../../processEnv");
|
|
23
|
+
var loader_1 = require("../../processEnv/loader");
|
|
24
|
+
var command = process.argv[2] || 'dev';
|
|
25
|
+
var argCmd = JSON.parse(((_a = process.argv) === null || _a === void 0 ? void 0 : _a[3]) || '{}');
|
|
26
|
+
// 根据命令设置环境变量
|
|
27
|
+
if (command === 'build') {
|
|
28
|
+
process.env.BABEL_ENV = 'production';
|
|
29
|
+
process.env.NODE_ENV = 'production';
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
process.env.BABEL_ENV = 'development';
|
|
33
|
+
process.env.NODE_ENV = 'development';
|
|
34
|
+
}
|
|
35
|
+
// 初始化环境变量
|
|
36
|
+
try {
|
|
37
|
+
processEnv_1.processEnv.initialize(process.env.NODE_ENV, path_1.default.resolve(process.cwd()), process.env.PUBLIC_URL || '');
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error('Failed to initialize environment variables:', error);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
var webpackProdConfig = require('./webpack.prod').default;
|
|
44
|
+
var webpackAnalyConfig = require('./webpack.analy').default;
|
|
45
|
+
var webpackDevConfig = require('./webpack.dev').default;
|
|
46
|
+
function dev() {
|
|
47
|
+
var _a, _b, _c, _d, _e;
|
|
48
|
+
var compiler = (0, webpack_1.default)(webpackDevConfig);
|
|
49
|
+
var devServerOptions = JSON.parse(JSON.stringify(webpackDevConfig.devServer || {}));
|
|
50
|
+
// 获取 qtcli.config.js 配置
|
|
51
|
+
var envLoader = loader_1.ProcessEnvLoader.getInstance();
|
|
52
|
+
var qtConfig = envLoader.getQtConfig();
|
|
53
|
+
// 先合并 qtcli.config.js 的配置
|
|
54
|
+
if ((_a = qtConfig === null || qtConfig === void 0 ? void 0 : qtConfig.webpackConfig) === null || _a === void 0 ? void 0 : _a.devServer) {
|
|
55
|
+
Object.assign(devServerOptions, qtConfig.webpackConfig.devServer);
|
|
56
|
+
}
|
|
57
|
+
// 再应用命令行参数,确保命令行参数优先级最高
|
|
58
|
+
Object.assign(devServerOptions, {
|
|
59
|
+
open: (_c = (_b = argCmd === null || argCmd === void 0 ? void 0 : argCmd.open) !== null && _b !== void 0 ? _b : devServerOptions.open) !== null && _c !== void 0 ? _c : false,
|
|
60
|
+
port: (argCmd === null || argCmd === void 0 ? void 0 : argCmd.port) || process.env.PORT || devServerOptions.port || 'auto',
|
|
61
|
+
server: (argCmd === null || argCmd === void 0 ? void 0 : argCmd.http) ? 'https' : devServerOptions.server || 'http',
|
|
62
|
+
host: (argCmd === null || argCmd === void 0 ? void 0 : argCmd.domain) || devServerOptions.host || 'localhost',
|
|
63
|
+
});
|
|
64
|
+
// 合并代理配置
|
|
65
|
+
if ((_e = (_d = qtConfig === null || qtConfig === void 0 ? void 0 : qtConfig.webpackConfig) === null || _d === void 0 ? void 0 : _d.devServer) === null || _e === void 0 ? void 0 : _e.proxy) {
|
|
66
|
+
devServerOptions.proxy = __assign(__assign({ '/api': {
|
|
67
|
+
target: 'http://localhost:3000',
|
|
68
|
+
changeOrigin: true,
|
|
69
|
+
pathRewrite: { '^/api': '' },
|
|
70
|
+
} }, (devServerOptions.proxy || {})), qtConfig.webpackConfig.devServer.proxy);
|
|
71
|
+
}
|
|
72
|
+
var server = new webpack_dev_server_1.default(devServerOptions, compiler);
|
|
73
|
+
server.startCallback(function () {
|
|
74
|
+
process && process.send && process.send({ type: 'log', data: 111 });
|
|
75
|
+
});
|
|
76
|
+
var ptime = new Date().getTime();
|
|
77
|
+
compiler.hooks.done.tap('DonePlugin', function (stats) {
|
|
78
|
+
var port = server.server.address().port;
|
|
79
|
+
var info = stats.toJson();
|
|
80
|
+
if (process && process.send) {
|
|
81
|
+
process.send({
|
|
82
|
+
type: 'DonePlugin',
|
|
83
|
+
data: {
|
|
84
|
+
time: new Date().getTime() - ptime,
|
|
85
|
+
port: port,
|
|
86
|
+
errors: info.errors,
|
|
87
|
+
warings: info.warnings,
|
|
88
|
+
devServerOptions: devServerOptions,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
compiler.hooks.compile.tap('compile', function () {
|
|
94
|
+
ptime = new Date().getTime();
|
|
95
|
+
if (process && process.send) {
|
|
96
|
+
process.send({ type: 'compile', data: { time: new Date().getTime() } });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function build() {
|
|
101
|
+
var compiler = (0, webpack_1.default)((argCmd === null || argCmd === void 0 ? void 0 : argCmd.analy) ? webpackAnalyConfig : webpackProdConfig);
|
|
102
|
+
compiler.run(function (err, stats) {
|
|
103
|
+
if (err) {
|
|
104
|
+
if (process && process.send) {
|
|
105
|
+
process.send({ type: 'buildError', data: err.message });
|
|
106
|
+
}
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
var info = stats.toJson();
|
|
111
|
+
if (process && process.send) {
|
|
112
|
+
process.send({
|
|
113
|
+
type: 'buildSuccess',
|
|
114
|
+
data: {
|
|
115
|
+
time: stats.endTime - stats.startTime,
|
|
116
|
+
errors: info.errors,
|
|
117
|
+
warings: info.warings,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
compiler.hooks.done.tap('DonePlugin', function () {
|
|
124
|
+
if (process && process.send) {
|
|
125
|
+
process.send({ type: 'DonePlugin', data: 111 });
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
command === 'dev' && dev();
|
|
130
|
+
command === 'build' && build();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var prodConfig = require('./webpack.prod');
|
|
4
|
+
var SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
|
|
5
|
+
var smp = new SpeedMeasurePlugin();
|
|
6
|
+
var merge = require('webpack-merge').merge;
|
|
7
|
+
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
8
|
+
exports.default = smp.wrap(merge(prodConfig, {
|
|
9
|
+
plugins: [new BundleAnalyzerPlugin()],
|
|
10
|
+
}));
|
|
@@ -0,0 +1,419 @@
|
|
|
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
var loader_1 = require("../../processEnv/loader");
|
|
28
|
+
var manager_1 = require("../../processEnv/manager");
|
|
29
|
+
var DonePlugin_1 = __importDefault(require("../plugins/DonePlugin"));
|
|
30
|
+
var FileListPlugin_1 = __importDefault(require("../plugins/FileListPlugin"));
|
|
31
|
+
var InjectScriptPlugin_1 = __importDefault(require("../plugins/InjectScriptPlugin"));
|
|
32
|
+
var path = require('path');
|
|
33
|
+
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
34
|
+
var HtmlWebpackTagsPlugin = require('html-webpack-tags-plugin');
|
|
35
|
+
var webpack = require('webpack');
|
|
36
|
+
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
37
|
+
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
|
38
|
+
// 获取环境变量管理器
|
|
39
|
+
var envManager = manager_1.ProcessEnvManager.getInstance();
|
|
40
|
+
// 获取环境变量配置
|
|
41
|
+
var envConfig = envManager.getOptions();
|
|
42
|
+
// 判断是否为开发环境
|
|
43
|
+
var isDev = function () { return process.env.NODE_ENV === 'development'; };
|
|
44
|
+
// 获取 qtcli.config.js 配置
|
|
45
|
+
var envLoader = loader_1.ProcessEnvLoader.getInstance();
|
|
46
|
+
var qtConfig = envLoader.getQtConfig() || {
|
|
47
|
+
config: {
|
|
48
|
+
htmlInject: {
|
|
49
|
+
head: [],
|
|
50
|
+
body: [],
|
|
51
|
+
},
|
|
52
|
+
env: {},
|
|
53
|
+
},
|
|
54
|
+
webpackConfig: {
|
|
55
|
+
resolve: {
|
|
56
|
+
alias: {},
|
|
57
|
+
},
|
|
58
|
+
module: {
|
|
59
|
+
rules: [],
|
|
60
|
+
},
|
|
61
|
+
plugins: [],
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
// 定义基础配置
|
|
65
|
+
var config = {
|
|
66
|
+
entry: {
|
|
67
|
+
index: path.resolve(process.cwd(), './src/index.tsx'),
|
|
68
|
+
},
|
|
69
|
+
output: {
|
|
70
|
+
filename: 'static/js/[name].[chunkhash].js',
|
|
71
|
+
path: path.resolve(process.cwd(), './dist'),
|
|
72
|
+
clean: true,
|
|
73
|
+
publicPath: '/',
|
|
74
|
+
},
|
|
75
|
+
module: {
|
|
76
|
+
rules: [
|
|
77
|
+
{
|
|
78
|
+
test: /\.(ts|tsx)$/,
|
|
79
|
+
include: [path.resolve(process.cwd(), './src')],
|
|
80
|
+
use: [
|
|
81
|
+
{
|
|
82
|
+
loader: require.resolve('babel-loader'),
|
|
83
|
+
options: {
|
|
84
|
+
presets: [
|
|
85
|
+
[
|
|
86
|
+
require.resolve('@babel/preset-env'),
|
|
87
|
+
{
|
|
88
|
+
targets: {
|
|
89
|
+
chrome: 36,
|
|
90
|
+
ie: 9,
|
|
91
|
+
},
|
|
92
|
+
useBuiltIns: 'usage',
|
|
93
|
+
corejs: 3,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
[
|
|
97
|
+
require.resolve('@babel/preset-react'),
|
|
98
|
+
{
|
|
99
|
+
runtime: 'automatic',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
require.resolve('@babel/preset-typescript'),
|
|
103
|
+
],
|
|
104
|
+
plugins: [
|
|
105
|
+
[
|
|
106
|
+
require.resolve('@babel/plugin-transform-runtime'),
|
|
107
|
+
{
|
|
108
|
+
useESModules: true,
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
test: /\.(js|jsx)$/,
|
|
118
|
+
include: [path.resolve(process.cwd(), './src')],
|
|
119
|
+
use: [
|
|
120
|
+
{
|
|
121
|
+
loader: require.resolve('babel-loader'),
|
|
122
|
+
options: {
|
|
123
|
+
presets: [
|
|
124
|
+
[
|
|
125
|
+
require.resolve('@babel/preset-env'),
|
|
126
|
+
{
|
|
127
|
+
targets: {
|
|
128
|
+
chrome: 36,
|
|
129
|
+
ie: 9,
|
|
130
|
+
},
|
|
131
|
+
useBuiltIns: 'usage',
|
|
132
|
+
corejs: 3,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
require.resolve('@babel/preset-react'),
|
|
137
|
+
{
|
|
138
|
+
runtime: 'automatic',
|
|
139
|
+
development: isDev(),
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
],
|
|
143
|
+
plugins: [
|
|
144
|
+
[
|
|
145
|
+
require.resolve('@babel/plugin-transform-runtime'),
|
|
146
|
+
{
|
|
147
|
+
useESModules: true,
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
test: /\.css$/,
|
|
157
|
+
exclude: [/\.module\.(css|less)/, /\.global\.less$/],
|
|
158
|
+
use: [
|
|
159
|
+
isDev() ? require.resolve('style-loader') : MiniCssExtractPlugin.loader,
|
|
160
|
+
{
|
|
161
|
+
loader: require.resolve('css-loader'),
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
loader: require.resolve('postcss-loader'),
|
|
165
|
+
options: {
|
|
166
|
+
postcssOptions: {
|
|
167
|
+
plugins: ['autoprefixer'],
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
test: /\.less$/,
|
|
175
|
+
exclude: [/\.module\.(css|less)/, /\.global\.less$/],
|
|
176
|
+
use: [
|
|
177
|
+
isDev() ? require.resolve('style-loader') : MiniCssExtractPlugin.loader,
|
|
178
|
+
{
|
|
179
|
+
loader: require.resolve('css-loader'),
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
loader: require.resolve('postcss-loader'),
|
|
183
|
+
options: {
|
|
184
|
+
postcssOptions: {
|
|
185
|
+
plugins: ['autoprefixer'],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
loader: require.resolve('less-loader'),
|
|
191
|
+
options: {
|
|
192
|
+
lessOptions: {
|
|
193
|
+
javascriptEnabled: true,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
test: /\.module\.less/,
|
|
201
|
+
use: [
|
|
202
|
+
isDev() ? require.resolve('style-loader') : MiniCssExtractPlugin.loader,
|
|
203
|
+
{
|
|
204
|
+
loader: require.resolve('css-loader'),
|
|
205
|
+
options: {
|
|
206
|
+
modules: {
|
|
207
|
+
localIdentName: '[path][name]__[local]--[contenthash:base64]',
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
loader: require.resolve('postcss-loader'),
|
|
213
|
+
options: {
|
|
214
|
+
postcssOptions: {
|
|
215
|
+
plugins: ['autoprefixer'],
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
loader: require.resolve('less-loader'),
|
|
221
|
+
options: {
|
|
222
|
+
lessOptions: {
|
|
223
|
+
javascriptEnabled: true,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
test: /\.(png|jpg|jpeg|gif|svg)$/,
|
|
231
|
+
type: 'asset/resource',
|
|
232
|
+
parser: {
|
|
233
|
+
detaUrlCondition: {
|
|
234
|
+
maxSize: 10 * 1024,
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
generator: {
|
|
238
|
+
filename: 'static/images/[contenthash][ext][query]',
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
test: /\.(woff2?|eot|ttf|otf)$/,
|
|
243
|
+
type: 'asset',
|
|
244
|
+
parser: {
|
|
245
|
+
detaUrlCondition: {
|
|
246
|
+
maxSize: 10 * 1024,
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
generator: {
|
|
250
|
+
filename: 'static/fonts/[name][contenthash][ext]',
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)$/,
|
|
255
|
+
type: 'asset',
|
|
256
|
+
parser: {
|
|
257
|
+
detaUrlCondition: {
|
|
258
|
+
maxSize: 10 * 1024,
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
generator: {
|
|
262
|
+
filename: 'static/media/[contenthash][ext]',
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
test: /\.scss$/,
|
|
267
|
+
exclude: [/\.module\.scss$/],
|
|
268
|
+
use: [
|
|
269
|
+
isDev() ? require.resolve('style-loader') : MiniCssExtractPlugin.loader,
|
|
270
|
+
{
|
|
271
|
+
loader: require.resolve('css-loader'),
|
|
272
|
+
options: {
|
|
273
|
+
sourceMap: true,
|
|
274
|
+
importLoaders: 2,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
loader: require.resolve('postcss-loader'),
|
|
279
|
+
options: {
|
|
280
|
+
postcssOptions: {
|
|
281
|
+
plugins: ['autoprefixer'],
|
|
282
|
+
},
|
|
283
|
+
sourceMap: true,
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
loader: require.resolve('sass-loader'),
|
|
288
|
+
options: {
|
|
289
|
+
sourceMap: true,
|
|
290
|
+
implementation: require.resolve('sass'),
|
|
291
|
+
sassOptions: {
|
|
292
|
+
includePaths: [path.resolve(process.cwd(), './src/styles')],
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
test: /\.module\.scss$/,
|
|
300
|
+
use: [
|
|
301
|
+
isDev() ? require.resolve('style-loader') : MiniCssExtractPlugin.loader,
|
|
302
|
+
{
|
|
303
|
+
loader: require.resolve('css-loader'),
|
|
304
|
+
options: {
|
|
305
|
+
sourceMap: true,
|
|
306
|
+
importLoaders: 2,
|
|
307
|
+
modules: {
|
|
308
|
+
localIdentName: '[path][name]__[local]--[contenthash:base64]',
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
loader: require.resolve('postcss-loader'),
|
|
314
|
+
options: {
|
|
315
|
+
postcssOptions: {
|
|
316
|
+
plugins: ['autoprefixer'],
|
|
317
|
+
},
|
|
318
|
+
sourceMap: true,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
loader: require.resolve('sass-loader'),
|
|
323
|
+
options: {
|
|
324
|
+
sourceMap: true,
|
|
325
|
+
implementation: require('sass'),
|
|
326
|
+
sassOptions: {
|
|
327
|
+
includePaths: [path.resolve(process.cwd(), './src/styles')],
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
},
|
|
335
|
+
plugins: __spreadArray(__spreadArray(__spreadArray([
|
|
336
|
+
new HtmlWebpackPlugin({
|
|
337
|
+
template: path.resolve(process.cwd(), './public/index.html'),
|
|
338
|
+
filename: '[name].html',
|
|
339
|
+
inject: true,
|
|
340
|
+
favicon: path.resolve(process.cwd(), './public/favicon.ico'),
|
|
341
|
+
publicPath: envConfig.PUBLIC_URL || '/',
|
|
342
|
+
meta: Array.isArray((_b = (_a = qtConfig === null || qtConfig === void 0 ? void 0 : qtConfig.config) === null || _a === void 0 ? void 0 : _a.htmlInject) === null || _b === void 0 ? void 0 : _b.head)
|
|
343
|
+
? qtConfig.config.htmlInject.head
|
|
344
|
+
.filter(function (item) { return item.tag === 'meta'; })
|
|
345
|
+
.map(function (item) { return item.attrs; })
|
|
346
|
+
: [],
|
|
347
|
+
}),
|
|
348
|
+
new InterpolateHtmlPlugin(HtmlWebpackPlugin, {
|
|
349
|
+
PUBLIC_URL: envConfig.PUBLIC_URL || '',
|
|
350
|
+
})
|
|
351
|
+
], (Array.isArray((_d = (_c = qtConfig === null || qtConfig === void 0 ? void 0 : qtConfig.config) === null || _c === void 0 ? void 0 : _c.htmlInject) === null || _d === void 0 ? void 0 : _d.head)
|
|
352
|
+
? [
|
|
353
|
+
new HtmlWebpackTagsPlugin({
|
|
354
|
+
tags: __spreadArray(__spreadArray([], (qtConfig.config.htmlInject.head
|
|
355
|
+
.filter(function (item) { return item.tag === 'link'; })
|
|
356
|
+
.map(function (item) { return ({
|
|
357
|
+
path: item.attrs.href,
|
|
358
|
+
append: false,
|
|
359
|
+
type: 'css',
|
|
360
|
+
}); }) || []), true), (qtConfig.config.htmlInject.head
|
|
361
|
+
.filter(function (item) { return item.tag === 'script'; })
|
|
362
|
+
.map(function (item) { return ({
|
|
363
|
+
path: item.attrs.src,
|
|
364
|
+
append: false,
|
|
365
|
+
type: 'js',
|
|
366
|
+
}); }) || []), true),
|
|
367
|
+
append: false,
|
|
368
|
+
usePublicPath: true,
|
|
369
|
+
}),
|
|
370
|
+
]
|
|
371
|
+
: []), true), (Array.isArray((_f = (_e = qtConfig === null || qtConfig === void 0 ? void 0 : qtConfig.config) === null || _e === void 0 ? void 0 : _e.htmlInject) === null || _f === void 0 ? void 0 : _f.body)
|
|
372
|
+
? [
|
|
373
|
+
new HtmlWebpackTagsPlugin({
|
|
374
|
+
tags: qtConfig.config.htmlInject.body
|
|
375
|
+
.filter(function (item) { return item.tag === 'script'; })
|
|
376
|
+
.map(function (item) { return ({
|
|
377
|
+
path: item.attrs.src,
|
|
378
|
+
append: true,
|
|
379
|
+
type: 'js',
|
|
380
|
+
}); }),
|
|
381
|
+
append: true,
|
|
382
|
+
usePublicPath: true,
|
|
383
|
+
}),
|
|
384
|
+
]
|
|
385
|
+
: []), true), [
|
|
386
|
+
new webpack.ProgressPlugin({
|
|
387
|
+
handler: function (percentage) {
|
|
388
|
+
process && process.send && process.send({ type: 'progress', data: percentage || 0 });
|
|
389
|
+
},
|
|
390
|
+
}),
|
|
391
|
+
new DonePlugin_1.default(),
|
|
392
|
+
new FileListPlugin_1.default({
|
|
393
|
+
filename: 'list.md',
|
|
394
|
+
}),
|
|
395
|
+
new webpack.DefinePlugin(__assign(__assign(__assign({}, envConfig), (_h = (_g = qtConfig === null || qtConfig === void 0 ? void 0 : qtConfig.config) === null || _g === void 0 ? void 0 : _g.env) === null || _h === void 0 ? void 0 : _h[process.env.NODE_ENV || 'development']), { 'process.env': JSON.stringify(process.env) })),
|
|
396
|
+
new InjectScriptPlugin_1.default({
|
|
397
|
+
headScripts: ((_k = (_j = qtConfig === null || qtConfig === void 0 ? void 0 : qtConfig.config) === null || _j === void 0 ? void 0 : _j.jsInject) === null || _k === void 0 ? void 0 : _k.head) || [],
|
|
398
|
+
bodyScripts: ((_m = (_l = qtConfig === null || qtConfig === void 0 ? void 0 : qtConfig.config) === null || _l === void 0 ? void 0 : _l.jsInject) === null || _m === void 0 ? void 0 : _m.body) || [],
|
|
399
|
+
}),
|
|
400
|
+
!isDev() &&
|
|
401
|
+
new MiniCssExtractPlugin({
|
|
402
|
+
filename: 'static/css/[name].[contenthash].css',
|
|
403
|
+
chunkFilename: 'static/css/[name].[contenthash].chunk.css',
|
|
404
|
+
}),
|
|
405
|
+
], false).filter(Boolean),
|
|
406
|
+
resolve: {
|
|
407
|
+
modules: ['node_modules', path.resolve(__dirname, '../../../node_modules')],
|
|
408
|
+
extensions: ['.jsx', '.js', '.tsx', '.ts', '.less', '.scss'],
|
|
409
|
+
alias: __assign({ '@': path.resolve(process.cwd(), './src'), react: path.resolve(process.cwd(), './node_modules/react') }, (_p = (_o = qtConfig === null || qtConfig === void 0 ? void 0 : qtConfig.webpackConfig) === null || _o === void 0 ? void 0 : _o.resolve) === null || _p === void 0 ? void 0 : _p.alias),
|
|
410
|
+
},
|
|
411
|
+
resolveLoader: {
|
|
412
|
+
modules: [path.resolve(__filename, '../../../node_modules')],
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
// 合并 webpack 配置
|
|
416
|
+
var finalConfig = __assign(__assign(__assign({}, config), (qtConfig.webpackConfig || {})), {
|
|
417
|
+
// 确保某些配置不被覆盖
|
|
418
|
+
entry: config.entry, output: __assign(__assign({}, config.output), (((_q = qtConfig.webpackConfig) === null || _q === void 0 ? void 0 : _q.output) || {})), module: __assign(__assign({}, config.module), { rules: __spreadArray(__spreadArray([], (((_r = config.module) === null || _r === void 0 ? void 0 : _r.rules) || []), true), (((_t = (_s = qtConfig.webpackConfig) === null || _s === void 0 ? void 0 : _s.module) === null || _t === void 0 ? void 0 : _t.rules) || []), true) }), plugins: __spreadArray(__spreadArray([], (config.plugins || []), true), (((_u = qtConfig.webpackConfig) === null || _u === void 0 ? void 0 : _u.plugins) || []), true) });
|
|
419
|
+
exports.default = finalConfig;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 path_1 = __importDefault(require("path"));
|
|
7
|
+
var webpack_merge_1 = require("webpack-merge");
|
|
8
|
+
var webpack_base_1 = __importDefault(require("./webpack.base"));
|
|
9
|
+
var devConfig = (0, webpack_merge_1.merge)(webpack_base_1.default, {
|
|
10
|
+
mode: 'development',
|
|
11
|
+
devtool: 'source-map',
|
|
12
|
+
devServer: {
|
|
13
|
+
port: process.env.PORT || 8000,
|
|
14
|
+
compress: false,
|
|
15
|
+
hot: true,
|
|
16
|
+
historyApiFallback: true,
|
|
17
|
+
server: 'https',
|
|
18
|
+
allowedHosts: 'all',
|
|
19
|
+
liveReload: false,
|
|
20
|
+
client: {
|
|
21
|
+
progress: true,
|
|
22
|
+
logging: 'info',
|
|
23
|
+
overlay: false,
|
|
24
|
+
},
|
|
25
|
+
static: {
|
|
26
|
+
directory: path_1.default.join(process.cwd(), './public'),
|
|
27
|
+
},
|
|
28
|
+
onListening: function (devServer) {
|
|
29
|
+
if (!devServer) {
|
|
30
|
+
throw new Error('webpack-dev-server is not defined');
|
|
31
|
+
}
|
|
32
|
+
var port = devServer.server.address().port;
|
|
33
|
+
console.log('开发服务器运行在端口:', port);
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
plugins: [],
|
|
37
|
+
});
|
|
38
|
+
exports.default = devConfig;
|
|
@@ -0,0 +1,82 @@
|
|
|
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 globAll = require('glob-all');
|
|
9
|
+
var CompressionPlugin = require('compression-webpack-plugin');
|
|
10
|
+
var merge = require('webpack-merge').merge;
|
|
11
|
+
var baseConfig = require('./webpack.base').default;
|
|
12
|
+
var CopyPlugin = require('copy-webpack-plugin');
|
|
13
|
+
var CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
14
|
+
var TerserPlugin = require('terser-webpack-plugin');
|
|
15
|
+
var PurgeCSSPlugin = require('purgecss-webpack-plugin');
|
|
16
|
+
exports.default = merge(baseConfig, {
|
|
17
|
+
mode: 'production',
|
|
18
|
+
plugins: [
|
|
19
|
+
new CopyPlugin({
|
|
20
|
+
patterns: [
|
|
21
|
+
{
|
|
22
|
+
from: path.resolve(process.cwd(), './public'),
|
|
23
|
+
to: baseConfig.output.path,
|
|
24
|
+
filter: function (source) {
|
|
25
|
+
return !source.includes('index.html');
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
}),
|
|
30
|
+
new mini_css_extract_plugin_1.default({
|
|
31
|
+
filename: 'static/css/[name].[contenthash].css',
|
|
32
|
+
}),
|
|
33
|
+
new PurgeCSSPlugin({
|
|
34
|
+
paths: globAll.sync([
|
|
35
|
+
"".concat(path.join(process.cwd(), './src'), "/**/*.tsx"),
|
|
36
|
+
"".concat(path.join(process.cwd(), './src'), "/**/*.jsx"),
|
|
37
|
+
path.join(process.cwd(), './public/index.html'),
|
|
38
|
+
]),
|
|
39
|
+
safelist: {
|
|
40
|
+
standard: [/^ant-/],
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
new CompressionPlugin({
|
|
44
|
+
test: /.(js|css)$/,
|
|
45
|
+
filename: '[path][base].gz',
|
|
46
|
+
algorithm: 'gzip',
|
|
47
|
+
threshold: 1024,
|
|
48
|
+
minRatio: 0.8,
|
|
49
|
+
}),
|
|
50
|
+
],
|
|
51
|
+
optimization: {
|
|
52
|
+
splitChunks: {
|
|
53
|
+
cacheGroups: {
|
|
54
|
+
vendors: {
|
|
55
|
+
test: /node_modules/,
|
|
56
|
+
name: 'vendors',
|
|
57
|
+
minChunks: 1,
|
|
58
|
+
chunks: 'initial',
|
|
59
|
+
minSize: 100,
|
|
60
|
+
priority: 1,
|
|
61
|
+
},
|
|
62
|
+
commons: {
|
|
63
|
+
name: 'commons',
|
|
64
|
+
minChunks: 2,
|
|
65
|
+
chunks: 'initial',
|
|
66
|
+
minSize: 100,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
minimizer: [
|
|
71
|
+
new CssMinimizerPlugin(),
|
|
72
|
+
new TerserPlugin({
|
|
73
|
+
parallel: true,
|
|
74
|
+
terserOptions: {
|
|
75
|
+
compress: {
|
|
76
|
+
pure_funcs: ['console.log'],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
});
|