@doracli/webpack 0.0.3 → 0.0.5

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.
@@ -1,17 +1,15 @@
1
1
  import * as webpack from 'webpack';
2
2
  import webpack__default, { Configuration, Stats, Compiler as Compiler$1 } from 'webpack';
3
+ export { Compilation, ExternalModule, Module, Compiler as WebpackCompiler, WebpackPluginInstance, default as webpack } from 'webpack';
3
4
  import * as http from 'http';
4
5
  import WebpackDevServer, { Configuration as Configuration$1 } from 'webpack-dev-server';
5
6
  import { TPlainObject, TAny } from '@cclr/lang';
6
- import { CompilerBase, ConfigCtx } from '@doracli/helper';
7
+ import { CompilerBase, ConfigCtx, HtmlAssetManager } from '@doracli/helper';
7
8
  import * as _doracli_type from '@doracli/type';
8
9
  import { TModule as TModule$1 } from '@doracli/type';
9
10
  import HtmlWebpackPlugin from 'html-webpack-plugin';
10
-
11
- declare const build: (options: Configuration) => Promise<{
12
- err?: Error | null;
13
- stats?: Stats;
14
- }>;
11
+ import { TOnionFun } from '@cclr/utils';
12
+ import { TDoraConfigMultiple } from '@doracli/type/src/dora-config-multiple';
15
13
 
16
14
  type TAction = 'build' | 'server' | 'lib';
17
15
  type TEnvParams = {
@@ -19,6 +17,10 @@ type TEnvParams = {
19
17
  workRootDir: string;
20
18
  format?: TModule$1;
21
19
  };
20
+ type TModuleInfo = {
21
+ name: string;
22
+ input: string;
23
+ };
22
24
 
23
25
  type TMode = Configuration['mode'];
24
26
  type TEntry = Configuration['entry'];
@@ -33,8 +35,8 @@ type TPlugins = Configuration['plugins'];
33
35
  type TOptimization = Configuration['optimization'];
34
36
 
35
37
  type TBuildResult = {
36
- Error: Error;
37
- Stats: Stats;
38
+ err: Error;
39
+ stats: Stats;
38
40
  };
39
41
  declare class Compiler extends CompilerBase<Configuration, {
40
42
  build: Promise<TBuildResult>;
@@ -42,16 +44,18 @@ declare class Compiler extends CompilerBase<Configuration, {
42
44
  server: Promise<WebpackDevServer>;
43
45
  }> {
44
46
  context: (webpackConfig: Configuration) => Promise<{
47
+ compiler: webpack__default.Compiler;
45
48
  rebuild: () => Promise<TBuildResult>;
46
49
  cancel: () => Promise<void>;
50
+ server: (serverOptions: Configuration$1, webpackConfig?: Configuration) => Promise<WebpackDevServer<any, http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>>>;
47
51
  }>;
48
52
  inOutMap: (inputOutputMap: Record<string, string>) => Promise<TBuildResult>;
49
53
  input: (input: string) => Promise<{
50
54
  output: (output: TOutput) => Promise<TBuildResult>;
51
55
  }>;
52
56
  build: (webpackConfig: Configuration) => Promise<TBuildResult>;
53
- watch: (watchOptions: Configuration["watchOptions"], webpackConfig: Configuration, cb?: (err: Error | null, stats?: Stats) => void) => webpack.Watching;
54
- server: (serverOptions: Configuration$1, webpackConfig?: Configuration) => Promise<WebpackDevServer<any, http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>>>;
57
+ watch: (watchOptions: Configuration["watchOptions"], webpackConfig: Configuration, cb?: (err: Error | null, stats?: Stats) => void) => webpack__default.Watching;
58
+ server: (serverOptions: Configuration$1, webpackConfig?: Configuration, userCompiler?: webpack__default.Compiler) => Promise<WebpackDevServer<any, http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>>>;
55
59
  }
56
60
 
57
61
  declare const getDevServer: (serviceConfig: Configuration$1) => Configuration$1;
@@ -98,11 +102,11 @@ declare class TsconfigPlugin {
98
102
 
99
103
  declare const getTsconfigPlugin: (envParams: TEnvParams) => TsconfigPlugin;
100
104
 
101
- declare const getReactPluginsPreset: (envParams: TEnvParams, options: {
102
- minimize?: boolean;
105
+ interface IReactPluginsPresetOptions {
103
106
  WebpackBundleAnalyzerOptions?: TAny;
104
- HtmlWebpackPluginOptions?: HtmlWebpackPlugin.Options;
105
- }) => TPlugins;
107
+ cssFilename?: string;
108
+ }
109
+ declare const getReactPluginsPreset: (envParams: TEnvParams, options: IReactPluginsPresetOptions) => TPlugins;
106
110
 
107
111
  /**
108
112
  * 获取webpack的resolve配置
@@ -113,8 +117,9 @@ declare const getResolve: (resolveConfig: TResolve) => TResolve;
113
117
 
114
118
  declare const getResolveLoader: () => TResolveLoader;
115
119
 
116
- declare const createCompiler: (config: Configuration) => webpack__default.Compiler | null;
117
-
120
+ /**
121
+ * 单任务上下文
122
+ */
118
123
  declare class Ctx {
119
124
  configCtx: ConfigCtx;
120
125
  webpackConfig: Configuration;
@@ -126,8 +131,128 @@ declare class Ctx {
126
131
  updateDevServerConfig(config: Configuration$1): void;
127
132
  getDoraConfig(): _doracli_type.TDoraConfig;
128
133
  geTDoraConfigWebpack(): _doracli_type.TDoraConfigWebpack;
134
+ getDoraConfigServiceConfig(): Partial<_doracli_type.TDoraConfigService>;
129
135
  }
130
136
 
137
+ /**
138
+ * webpack dev server 配置 中间件
139
+ * @returns
140
+ */
141
+ declare const webpackDevServerMw: () => TOnionFun<Ctx>;
142
+
143
+ /**
144
+ * webpack dev server 配置 中间件
145
+ * @returns
146
+ */
147
+ declare const webpackDevtoolMw: () => TOnionFun<Ctx>;
148
+
149
+ declare const envParamsMw: (envParams: TEnvParams) => TOnionFun<Ctx>;
150
+
151
+ /**
152
+ * webpack dev server 配置 中间件
153
+ * @returns
154
+ */
155
+ declare const webpackExternalsMw: () => TOnionFun<Ctx>;
156
+
157
+ /**
158
+ * webpack dev server 配置 中间件
159
+ * @returns
160
+ */
161
+ declare const webpackEntryWholeMw: () => TOnionFun<Ctx>;
162
+
163
+ /**
164
+ * 处理 multiple
165
+ * - 1. multiple 变成多入口,多出口 的 entry格式
166
+ * - 2. 上下文一定要拆分过
167
+ */
168
+ declare const multipleToInOutMw: (outputOptions?: {
169
+ /** default: [name]/[chunkhash].js */
170
+ filename: string;
171
+ }) => TOnionFun<Ctx>;
172
+
173
+ /**
174
+ * webpack dev server 配置 中间件
175
+ * @returns
176
+ */
177
+ declare const webpackOutputMw: () => TOnionFun<Ctx>;
178
+
179
+ type TLogLevel = 'none' | 'verbose' | 'error' | 'warn' | 'info' | 'log';
180
+ /**
181
+ * webpack dev server 配置 中间件
182
+ * @returns
183
+ */
184
+ declare const webpackLogLevelMw: (logLevel?: TLogLevel) => TOnionFun<Ctx>;
185
+
186
+ /**
187
+ * webpack dev server 配置 中间件
188
+ * @returns
189
+ */
190
+ declare const webpackReactModuleMw: () => TOnionFun<Ctx>;
191
+
192
+ /**
193
+ * webpack dev server 配置 中间件
194
+ * @returns
195
+ */
196
+ declare const webpackPlainMw: () => TOnionFun<Ctx>;
197
+
198
+ /**
199
+ * 替换 React 相关的插件配置
200
+ * @returns
201
+ */
202
+ declare const webpackReactPluginMw: (options?: IReactPluginsPresetOptions) => TOnionFun<Ctx>;
203
+ /**
204
+ * 替换 React 相关的插件配置
205
+ * @returns
206
+ */
207
+ declare const webpackMultipleReactPluginMw: (options?: {
208
+ /** default: [name]/[chunkhash].css */
209
+ cssFilename?: string;
210
+ }) => TOnionFun<Ctx>;
211
+ /**
212
+ * 添加 HtmlWebpackPlugin 插件配置
213
+ * @returns
214
+ */
215
+ declare const webpackHtmlPluginMw: () => TOnionFun<Ctx>;
216
+
217
+ /**
218
+ * webpack dev server 配置 中间件
219
+ * @returns
220
+ */
221
+ declare const webpackResolveMw: () => TOnionFun<Ctx>;
222
+
223
+ /**
224
+ * webpack dev server 配置 中间件
225
+ * @returns
226
+ */
227
+ declare const webpackResolveLoaderMw: () => TOnionFun<Ctx>;
228
+
229
+ type TBundleAsset = {
230
+ name: string;
231
+ scripts: string[];
232
+ styles: string[];
233
+ runtimeChunks: string[];
234
+ };
235
+ declare function collectAssetUrls(compiler: webpack__default.Compiler, onChange?: (params: Record<string, TBundleAsset>) => void, options?: {
236
+ hostname?: string;
237
+ port?: number | string;
238
+ }): () => Record<string, TBundleAsset>;
239
+
240
+ declare const htmlRouteGeneratorMw: (htmlAssetManager: HtmlAssetManager, configCtx: ConfigCtx) => Promise<(req: any, res: any, next: any) => Promise<void>>;
241
+
242
+ /**
243
+ * 把配置拆分成多个标准的配置上下文,使用于webpack
244
+ * - 主要是拆分成不同的入口输出分组
245
+ * @param configCtx
246
+ */
247
+ declare const splitDoraConfig: (configCtx: ConfigCtx) => ConfigCtx[];
248
+
249
+ /**
250
+ * 根据配置分组
251
+ * @param multiple
252
+ * @returns
253
+ */
254
+ declare const splitDoraConfigMultiple: (multiple: TDoraConfigMultiple[]) => TDoraConfigMultiple[][];
255
+
131
256
  declare const mergeWebpackConfig: <T extends Partial<Configuration>>(first: T | undefined, second: T | undefined) => Partial<Configuration>;
132
257
  /**
133
258
  * 合并多个 devServer 配置
@@ -136,12 +261,5 @@ declare const mergeWebpackConfig: <T extends Partial<Configuration>>(first: T |
136
261
  */
137
262
  declare const mergeServerConfig: <T extends Partial<Configuration$1>>(...configs: (T | undefined)[]) => Configuration$1;
138
263
 
139
- /**
140
- * 启动服务
141
- * @param options
142
- * @param compiler
143
- */
144
- declare const service: (options: Configuration$1, compiler: Compiler$1) => Promise<void>;
145
-
146
- export { Compiler, Ctx, babelLoader, build, createCompiler, cssLoader, getBabelConfig, getCssBaseLoader, getDevServer, getDevtool, getEntry, getExternals, getHtmlWebpackPlugin, getMode, getOptimization, getOutput, getReactModulePreset, getReactPluginsPreset, getResolve, getResolveLoader, getTsconfigPlugin, lessLoader, mergeServerConfig, mergeWebpackConfig, postcssLoader, postcssPresetEnv, sassLoader, service, styleLoader };
147
- export type { TAction, TBuildResult, TDevtool, TEntry, TEnvParams, TExperiments, TExternals, TMode, TModule, TOptimization, TOutput, TPlugins, TResolve, TResolveLoader };
264
+ export { Compiler, Ctx, babelLoader, collectAssetUrls, cssLoader, envParamsMw, getBabelConfig, getCssBaseLoader, getDevServer, getDevtool, getEntry, getExternals, getHtmlWebpackPlugin, getMode, getOptimization, getOutput, getReactModulePreset, getReactPluginsPreset, getResolve, getResolveLoader, getTsconfigPlugin, htmlRouteGeneratorMw, lessLoader, mergeServerConfig, mergeWebpackConfig, multipleToInOutMw, postcssLoader, postcssPresetEnv, sassLoader, splitDoraConfig, splitDoraConfigMultiple, styleLoader, webpackDevServerMw, webpackDevtoolMw, webpackEntryWholeMw, webpackExternalsMw, webpackHtmlPluginMw, webpackLogLevelMw, webpackMultipleReactPluginMw, webpackOutputMw, webpackPlainMw, webpackReactModuleMw, webpackReactPluginMw, webpackResolveLoaderMw, webpackResolveMw };
265
+ export type { IReactPluginsPresetOptions, TAction, TBuildResult, TBundleAsset, TDevtool, TEntry, TEnvParams, TExperiments, TExternals, TLogLevel, TMode, TModule, TModuleInfo, TOptimization, TOutput, TPlugins, TResolve, TResolveLoader };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doracli/webpack",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "use webpack",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -25,39 +25,39 @@
25
25
  "scripts": {
26
26
  "test": "vitest",
27
27
  "g:test": "vitest run",
28
- "build": "ccf build"
28
+ "build": "drr build"
29
29
  },
30
30
  "dependencies": {
31
- "@dorabag/open-browser": "^1.0.10"
31
+ "@dorabag/open-browser": "^1.0.16"
32
32
  },
33
33
  "devDependencies": {
34
- "@cclr/lang": "^0.1.28",
35
- "@cclr/utils": "^0.1.28",
36
- "@dorabag/config-loader": "^1.0.11",
34
+ "@cclr/lang": "^0.1.49",
35
+ "@cclr/utils": "^0.1.49",
36
+ "@dorabag/config-loader": "^1.0.16",
37
37
  "@dorabag/file-pro": "^1.0.10",
38
38
  "@dorabag/open-browser": "^1.0.7",
39
- "@dorabag/srv-tool": "^1.0.10",
40
- "@doracli/helper": "^0.0.3",
41
- "@doracli/preset-babel": "^0.0.3",
42
- "@doracli/type": "^0.0.3",
39
+ "@dorabag/srv-tool": "^1.0.16",
40
+ "@doracli/helper": "^0.0.5",
41
+ "@doracli/preset-babel": "^0.0.5",
42
+ "@doracli/type": "^0.0.5",
43
43
  "babel-loader": "^10.0.0",
44
44
  "css-loader": "^7.1.2",
45
- "html-webpack-plugin": "^5.6.4",
46
- "less": "^4.4.2",
45
+ "html-webpack-plugin": "^5.6.5",
46
+ "less": "^4.5.1",
47
47
  "less-loader": "^12.3.0",
48
48
  "mini-css-extract-plugin": "^2.9.4",
49
49
  "picocolors": "^1.1.1",
50
50
  "postcss": "^8.5.6",
51
51
  "postcss-loader": "^8.2.0",
52
- "postcss-preset-env": "^10.4.0",
53
- "sass": "^1.93.2",
52
+ "postcss-preset-env": "^10.5.0",
53
+ "sass": "^1.97.1",
54
54
  "sass-loader": "^16.0.6",
55
55
  "style-loader": "^4.0.0",
56
- "terser-webpack-plugin": "^5.3.14",
57
- "webpack": "^5.102.1",
56
+ "terser-webpack-plugin": "^5.3.16",
57
+ "webpack": "^5.104.1",
58
58
  "webpack-bundle-analyzer": "^4.10.2",
59
59
  "webpack-dev-server": "^5.2.2",
60
60
  "webpackbar": "^7.0.0"
61
61
  },
62
- "gitHead": "c89b02be8c385738ad80749447133d30e00b1f75"
62
+ "gitHead": "ac4c6829b2cec621ecf66b6324843773e8b5141f"
63
63
  }