coda-builder 1.0.1 → 1.0.8
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 +191 -0
- package/build/index.js +1 -1
- package/build/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,3 +88,194 @@ const webpackConfig: Configuration = resolveWebpackConfig(config);
|
|
|
88
88
|
|
|
89
89
|
export default webpackConfig;
|
|
90
90
|
```
|
|
91
|
+
|
|
92
|
+
chrome插件 配置示例
|
|
93
|
+
|
|
94
|
+
```TypeScript
|
|
95
|
+
import * as path from 'path';
|
|
96
|
+
import type {Configuration} from 'webpack';
|
|
97
|
+
import {resolveWebpackConfig, CodaUserConfig} from 'coda-builder';
|
|
98
|
+
|
|
99
|
+
const config: CodaUserConfig = {
|
|
100
|
+
platformTarget: 'chrome-ext',
|
|
101
|
+
techRoute: 'web',
|
|
102
|
+
entry: {
|
|
103
|
+
background: './src/background.ts',
|
|
104
|
+
sidepanel: './src/sidepanel.ts',
|
|
105
|
+
},
|
|
106
|
+
mode: 'production',
|
|
107
|
+
devtool: false, //一定要关闭
|
|
108
|
+
optimization: {
|
|
109
|
+
runtimeChunk: false, //一定要关闭
|
|
110
|
+
splitChunks: false, //一定要关闭
|
|
111
|
+
},
|
|
112
|
+
output: {
|
|
113
|
+
path: path.resolve(__dirname, 'dist'),
|
|
114
|
+
},
|
|
115
|
+
alias: {
|
|
116
|
+
'chat-shared-ui': path.resolve(__dirname, '../../coda-ui/chat-shared-ui/resources'),
|
|
117
|
+
},
|
|
118
|
+
extensions: ['.ts'],
|
|
119
|
+
copyRules: [
|
|
120
|
+
{
|
|
121
|
+
type: 'single',
|
|
122
|
+
from: path.resolve(__dirname, 'manifest.json'),
|
|
123
|
+
to: 'manifest.json',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
type: 'template',
|
|
127
|
+
from: path.resolve(__dirname, '../../coda-ui/chat-shared-ui/resources/chat.html'),
|
|
128
|
+
to: 'sidepanel.html',
|
|
129
|
+
data: {
|
|
130
|
+
'{{styleUri}}': 'main.css',
|
|
131
|
+
'{{scriptUri}}': 'sidepanel.js',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
type: 'single',
|
|
136
|
+
from: path.resolve(__dirname, '../../coda-ui/chat-shared-ui/resources/main.css'),
|
|
137
|
+
to: 'main.css',
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const webpackConfig: Configuration = resolveWebpackConfig(config);
|
|
143
|
+
|
|
144
|
+
export default webpackConfig;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
vscode插件 配置示例
|
|
148
|
+
|
|
149
|
+
```TypeScript
|
|
150
|
+
import * as path from 'path';
|
|
151
|
+
import type {Configuration} from 'webpack';
|
|
152
|
+
import {resolveWebpackConfig, CodaUserConfig} from 'coda-builder';
|
|
153
|
+
|
|
154
|
+
const config: CodaUserConfig = {
|
|
155
|
+
techRoute: 'typescript',
|
|
156
|
+
platformTarget: 'vscode-ext',
|
|
157
|
+
entry: './src/extension.ts',
|
|
158
|
+
mode: 'production',
|
|
159
|
+
output: {
|
|
160
|
+
path: path.resolve(__dirname, 'dist'),
|
|
161
|
+
filename: 'extension.js',//vscode专属脚本名称
|
|
162
|
+
libraryTarget: 'commonjs',//一定要设置成commonjs
|
|
163
|
+
},
|
|
164
|
+
alias: {
|
|
165
|
+
'chat-shared-ui': path.resolve(__dirname, '../../coda-ui/chat-shared-ui/resources'),
|
|
166
|
+
},
|
|
167
|
+
copyRules: [
|
|
168
|
+
{
|
|
169
|
+
type: 'single',
|
|
170
|
+
from: path.resolve(__dirname, '../../coda-ui/chat-shared-ui/resources/chat.html'),
|
|
171
|
+
to: 'main.html',
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
type: 'single',
|
|
175
|
+
from: path.resolve(__dirname, '../../coda-ui/chat-shared-ui/resources/main.css'),
|
|
176
|
+
to: 'main.css',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
type: 'single',
|
|
180
|
+
from: path.resolve(__dirname, 'resources', 'main.js'),
|
|
181
|
+
to: 'main.js',
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
type: 'single',
|
|
185
|
+
from: path.resolve(__dirname, 'resources', 'icon.svg'),
|
|
186
|
+
to: 'icon.svg',
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const webpackConfig: Configuration = resolveWebpackConfig(config);
|
|
192
|
+
|
|
193
|
+
export default webpackConfig;
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
命令行工具 配置示例
|
|
198
|
+
|
|
199
|
+
```TypeScript
|
|
200
|
+
import * as path from 'path';
|
|
201
|
+
import * as fs from 'fs';
|
|
202
|
+
import type {Configuration} from 'webpack';
|
|
203
|
+
import {resolveWebpackConfig, CodaUserConfig} from 'coda-builder';
|
|
204
|
+
|
|
205
|
+
function getEntries(srcDir: string) {
|
|
206
|
+
let entries: Record<string, string> = {};
|
|
207
|
+
|
|
208
|
+
function scan(dir: string) {
|
|
209
|
+
const files = fs.readdirSync(dir, {withFileTypes: true});
|
|
210
|
+
files.forEach(file => {
|
|
211
|
+
const fullPath = path.join(dir, file.name);
|
|
212
|
+
if (file.isDirectory()) {
|
|
213
|
+
if (file.name !== 'tmpl' && file.name !== 'templates') {
|
|
214
|
+
scan(fullPath);
|
|
215
|
+
}
|
|
216
|
+
} else if (file.name === 'index.ts' || file.name === 'index.js') {
|
|
217
|
+
const relativePath = path.relative(srcDir, fullPath);
|
|
218
|
+
const entryKey = relativePath.replace(/\\/g, '/').replace(/\.tsx?$/, '');
|
|
219
|
+
entries[entryKey] = fullPath;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
scan(srcDir);
|
|
225
|
+
return entries;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const srcPath = path.resolve(__dirname, 'src');
|
|
229
|
+
|
|
230
|
+
const config: CodaUserConfig = {
|
|
231
|
+
techRoute: 'typescript',
|
|
232
|
+
platformTarget: 'nodejs-cli',
|
|
233
|
+
entry: getEntries(srcPath),
|
|
234
|
+
mode: process.env.NODE_ENV === 'development' ? 'development' : 'production',
|
|
235
|
+
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : 'cheap-module-source-map',
|
|
236
|
+
gzip: false,
|
|
237
|
+
output: {
|
|
238
|
+
path: path.resolve(__dirname, 'dist'),
|
|
239
|
+
clean: false,
|
|
240
|
+
},
|
|
241
|
+
maxChunks: 1,
|
|
242
|
+
alias: {
|
|
243
|
+
'@': path.resolve(__dirname, 'src'),
|
|
244
|
+
},
|
|
245
|
+
extensionAlias: {
|
|
246
|
+
'.js': ['.ts', '.js'],
|
|
247
|
+
'.ts': ['.ts', '.js'],
|
|
248
|
+
},//命令行工具一定要配置这个后缀映射关系
|
|
249
|
+
copyRules: [
|
|
250
|
+
{
|
|
251
|
+
type: 'single',
|
|
252
|
+
from: path.resolve(__dirname, 'package.json'),
|
|
253
|
+
to: 'package.json',
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
type: 'single',
|
|
257
|
+
from: path.resolve(__dirname, 'README.md'),
|
|
258
|
+
to: 'README.md',
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
type: 'directory',
|
|
262
|
+
from: path.resolve(__dirname, 'src', 'config'),
|
|
263
|
+
to: 'config',
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
type: 'directory',
|
|
267
|
+
from: path.resolve(__dirname, 'src', 'service'),
|
|
268
|
+
to: 'service',
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
type: 'directory',
|
|
272
|
+
from: path.resolve(__dirname, 'templates'),
|
|
273
|
+
to: 'templates',
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const webpackConfig: Configuration = resolveWebpackConfig(config);
|
|
279
|
+
|
|
280
|
+
export default webpackConfig;
|
|
281
|
+
```
|
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var j=Object.create;var h=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var i in e)h(t,i,{get:e[i],enumerable:!0})},C=(t,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of T(e))!F.call(t,s)&&s!==i&&h(t,s,{get:()=>e[s],enumerable:!(o=q(e,s))||o.enumerable});return t};var d=(t,e,i)=>(i=t!=null?j(N(t)):{},C(e||!t||!t.__esModule?h(i,"default",{value:t,enumerable:!0}):i,t)),U=t=>C(h({},"__esModule",{value:!0}),t);var G={};D(G,{resolveWebpackConfig:()=>M});module.exports=U(G);var v=d(require("webpack-node-externals")),O=require("webpack-bundle-analyzer");var w=d(require("path")),z=d(require("os")),S=d(require("webpackbar")),u={js:/\.(ts|js)$/,css:/\.css$/,image:/\.(png|jpg|jpeg|gif|svg)$/,font:/\.(woff|woff2|eot|ttf|otf)$/,media:/\.(mp4|webm|ogg|mp3|wav)$/},y=(t={},e="development")=>{let i=z.default.cpus().length||4;return{name:t.name||"ts-thread",workers:t.workers||(e==="development"?2:Math.max(1,Math.floor((i-2)/2))),workerParallelJobs:t.workerParallelJobs||(e==="development"?40:20),workerNodeArgs:Array.isArray(t.workerNodeArgs)?t.workerNodeArgs:[t.workerNodeArgs||(e==="development"?"--max-old-space-size=512":"--max-old-space-size=256")],poolRespawn:t.poolRespawn??e!=="development",poolTimeout:t.poolTimeout||500,poolParallelJobs:t.poolParallelJobs||(e==="development"?200:100)}},A=(t=!1,e)=>{let i=[];if(e?.thread){let o=y(e.workerOptions,e.mode);i.push({loader:"thread-loader",options:o})}return i.push({loader:"ts-loader",options:{compilerOptions:{declaration:!1,declarationMap:!1}}}),{mode:"none",output:{path:w.default.resolve(__dirname,"dist"),clean:!0},resolve:{extensions:[".ts",".js"],modules:["node_modules"]},module:{rules:[{test:u.js,use:i,exclude:/node_modules/},{test:u.css,use:[t?{loader:require("mini-css-extract-plugin").loader}:"style-loader",{loader:"css-loader",options:{sourceMap:!0,importLoaders:1}},"postcss-loader"]},{test:u.image,type:"asset/resource",generator:{filename:"assets/img/[hash][ext]"}},{test:u.font,type:"asset/resource",generator:{filename:"assets/font/[name][ext]"}},{test:u.media,type:"asset/resource",generator:{filename:"assets/media/[name][ext]"}}]},plugins:[new S.default({name:"coda-builder",color:"#0052cc"})],devServer:{historyApiFallback:!0,port:8080,compress:!1,open:!1,hot:!0,static:{directory:w.default.join(process.cwd(),"dist")}},stats:"minimal"}};var g=class{config;constructor(e){this.config={...e}}setMode(e){return this.config.mode=e,this}setEntry(e){return this.config.entry=e,this}setContext(e){return e!==void 0&&(this.config.context=e),this}setOutput(e){return e?(this.config.output={...this.config.output,...e},this):this}setDevtool(e){return e!==void 0&&(this.config.devtool=e),this}setTarget(e){return e!==void 0&&(this.config.target=e),this}setCache(e){return e!==void 0&&(this.config.cache=e),this}setResolve(e,i){let o=i?.modules,s=i?.mainFields,n=i?.alias,r=i?.extensions,a=i?.extensionAlias;return this.config.resolve={...this.config.resolve,...o?{modules:o}:{},...s?{mainFields:s}:{},...n?{alias:n}:{},...r?{extensions:r}:{},...a?{extensionAlias:a}:{},...e},this}setModule(e,i){let o=this.config.module?.rules||[],s=i?.rules||[],n=i?.noParse;return this.config.module={...this.config.module||{},...n?{noParse:n}:{},rules:[...o,...s],...e},this}setOptimization(e,i,o,s,n,r,a){let l=i;l===void 0&&(s==="web"||s==="chrome-ext")&&(l={chunks:"all",minSize:2e4,maxSize:2e5,minChunks:1,maxAsyncRequests:6,maxInitialRequests:6,cacheGroups:{libs:{name:"chunk-libs",test:/[\\/]node_modules[\\/]/,chunks:"initial",priority:20,reuseExistingChunk:!0},common:{name:"chunk-common",minChunks:2,priority:2,reuseExistingChunk:!0}}});let m=r!==void 0?r:n==="production"||n==="analyzer",p=e?.minimizer||this.config.optimization?.minimizer;if(m&&!p)try{let P=require("terser-webpack-plugin"),E=require("css-minimizer-webpack-plugin"),R=o!==void 0?o:{parse:{ecma:8},compress:{ecma:5,comparisons:!1,inline:2,warnings:!1},mangle:!0,module:!1,output:{ecma:5,comments:!1},toplevel:!1,ie8:!1,safari10:!1},W=a||2;p=[new P({parallel:W,terserOptions:R}),new E({parallel:W})]}catch{}let f=e?.runtimeChunk||this.config.optimization?.runtimeChunk;return l!==void 0&&!f&&(f={name:"manifest"}),this.config.optimization={...this.config.optimization||{},minimize:m,...l!==void 0?{splitChunks:l}:{},...p!==void 0?{minimizer:p}:{},...f!==void 0?{runtimeChunk:f}:{},...e},this}setStats(e){return e!==void 0&&(this.config.stats=e),this}setDevServer(e){if(!e)return this;let i=this.config.devServer||{};return this.config.devServer={...i,...e,...e.static?{static:typeof e.static=="object"&&typeof i.static=="object"?{...i.static,...e.static}:e.static}:{}},this}setWatch(e){return e!==void 0&&(this.config.watch=e),this}setWatchOptions(e){return e?(this.config.watchOptions={...this.config.watchOptions,...e},this):this}setExternals(e){return e!==void 0&&(this.config.externals=e),this}addPlugin(e){return this.config.plugins=this.config.plugins||[],this.config.plugins.push(e),this}addPlugins(e){return!e||!Array.isArray(e)?this:(e.forEach(i=>{i&&this.addPlugin(i)}),this)}setMaxChunks(e){if(e===void 0)return this;let i=require("webpack");return this.addPlugin(new i.optimize.LimitChunkCountPlugin({maxChunks:e})),this}getConfig(){return this.config}setConfig(e){return this.config={...this.config,...e},this}};var c=d(require("fs")),b=d(require("path")),k=class{rules;constructor(e=[]){this.rules=e}apply(e){e.hooks.thisCompilation.tap("CodaCopyWebpackPlugin",i=>{i.hooks.processAssets.tap({name:"CodaCopyWebpackPlugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},()=>{this.rules.forEach(o=>{c.default.existsSync(o.from)&&(o.type==="single"?this.processSingleFile(i,o.from,o.to):o.type==="directory"?this.processDirectory(i,o.from,o.to,o.ignore||[]):o.type==="template"&&this.processTemplate(i,o.from,o.to,o.data))})})})}processSingleFile(e,i,o){let s=c.default.readFileSync(i);e.emitAsset(o,new e.compiler.webpack.sources.RawSource(s))}processDirectory(e,i,o,s){c.default.readdirSync(i,{recursive:!0}).forEach(r=>{let a=b.default.join(i,r);if(c.default.statSync(a).isDirectory())return;let l=b.default.relative(i,a);if(s.some(p=>l.includes(p)))return;let x=b.default.join(o,l).replace(/\\/g,"/"),m=c.default.readFileSync(a);e.emitAsset(x,new e.compiler.webpack.sources.RawSource(m))})}processTemplate(e,i,o,s){let n=c.default.readFileSync(i,"utf-8");Object.keys(s).forEach(r=>{let a=r.replace(/{{\s*|\s*}}/g,""),l=new RegExp(`{{\\s*${a}\\s*}}`,"g");n=n.replace(l,String(s[r]))}),e.emitAsset(o,new e.compiler.webpack.sources.RawSource(Buffer.from(n)))}};function _(t){if(!t.techRoute)throw new Error("[coda-builder] Missing required config: techRoute");if(!t.platformTarget)throw new Error("[coda-builder] Missing required config: platformTarget");if(!t.mode)throw new Error("[coda-builder] Missing required config: mode");if(!t.entry)throw new Error("[coda-builder] Missing required config: entry")}function I(t){let e=t.mode==="production"||t.mode==="analyzer";return A(e,t)}function B(t,e){let{platformTarget:i}=t;["nodejs-cli","node-server","vscode-ext"].includes(i)?(e.setTarget("node"),i==="vscode-ext"?e.setExternals([(0,v.default)(),{vscode:"commonjs vscode"}]):e.setExternals([(0,v.default)()])):i==="chrome-ext"&&e.setTarget("web")}function $(t,e){let i=t.mode==="analyzer"?"production":t.mode;e.setMode(i).setEntry(t.entry).setContext(t.context).setOutput(t.output).setDevtool(t.devtool).setCache(t.cache).setMaxChunks(t.maxChunks).setStats(t.stats).setDevServer(t.devServer).setWatch(t.watch).setWatchOptions(t.watchOptions),e.setOptimization(t.optimization,t.splitChunks,t.terserOptions,t.platformTarget,i,t.minimize,t.parallel),e.setResolve(t.resolve,{alias:t.alias,extensions:t.extensions,extensionAlias:t.extensionAlias,modules:t.modules,mainFields:t.mainFields}),e.setModule(t.module,{noParse:t.noParse,rules:t.rules}),t.target&&e.setTarget(t.target),t.externals&&e.setExternals(t.externals)}function J(t,e){let i=t.mode==="production"||t.mode==="analyzer";if(t.copyRules&&t.copyRules.length>0&&e.addPlugin(new k(t.copyRules)),t.html)try{let o=require("html-webpack-plugin"),s=typeof t.html=="object"?t.html:{};e.addPlugin(new o(s))}catch{throw new Error('[coda-builder] html-webpack-plugin is required when using "html" config. Please install it.')}if(i)try{let o=require("mini-css-extract-plugin");e.addPlugin(new o({filename:"css/[name].[contenthash:8].css",chunkFilename:"css/[name].[contenthash:8].chunk.css"}))}catch{throw new Error("[coda-builder] mini-css-extract-plugin is required in production mode. Please install it.")}if(t.gzip!==!1&&(t.gzip||i))try{let o=require("compression-webpack-plugin"),s={filename:"[path][base].gz",algorithm:"gzip",test:/\.(js|css|png|jpg|jpeg|svg)(\?.*)?$/i,threshold:8192,minRatio:.8,deleteOriginalAssets:!1,exclude:[/node_modules/]},n=typeof t.gzip=="object"?{...s,...t.gzip}:s;e.addPlugin(new o(n))}catch{throw new Error('[coda-builder] compression-webpack-plugin is required when using "gzip" config. Please install it.')}t.plugins&&t.plugins.length>0&&e.addPlugins(t.plugins),t.mode==="analyzer"&&e.addPlugin(new O.BundleAnalyzerPlugin({analyzerMode:"server"}))}function L(t,e){if(t.configureWebpack&&typeof t.configureWebpack=="function"){let i=t.configureWebpack(e,t.mode);if(i)return i}return e}function M(t,e){if(_(t),t.thread&&t.mode==="development")try{let n=require("thread-loader"),r=y(t.workerOptions||{name:"ts-thread",workers:2,workerParallelJobs:40,workerNodeArgs:"--max-old-space-size=512",poolRespawn:!1,poolParallelJobs:200},t.mode);n.warmup({workerBabelArgs:r},["ts-loader"])}catch{}let i=I(t),o=new g(i);o.setConfig({context:process.cwd()}),B(t,o),$(t,o),J(t,o);let s=o.getConfig();if(s=L(t,s),t.speedMeasure&&(t.mode==="development"||t.mode==="analyzer"))try{let n=require("speed-measure-webpack-v5-plugin");s=new n().wrap(s)}catch{throw new Error('[coda-builder] speed-measure-webpack-v5-plugin is required when using "speedMeasure" config. Please install it.')}return e&&(console.log("webpack\u914D\u7F6E:"),console.dir(i,{depth:null})),s}0&&(module.exports={resolveWebpackConfig});
|
|
1
|
+
"use strict";var j=Object.create;var b=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var i in e)b(t,i,{get:e[i],enumerable:!0})},z=(t,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of N(e))!F.call(t,s)&&s!==i&&b(t,s,{get:()=>e[s],enumerable:!(o=q(e,s))||o.enumerable});return t};var u=(t,e,i)=>(i=t!=null?j(T(t)):{},z(e||!t||!t.__esModule?b(i,"default",{value:t,enumerable:!0}):i,t)),U=t=>z(b({},"__esModule",{value:!0}),t);var G={};D(G,{resolveWebpackConfig:()=>M});module.exports=U(G);var W=u(require("webpack-node-externals")),E=require("webpack-bundle-analyzer");var x=u(require("path")),S=u(require("os")),O=u(require("webpackbar")),f={js:/\.(ts|js)$/,css:/\.css$/,image:/\.(png|jpg|jpeg|gif|svg)$/,font:/\.(woff|woff2|eot|ttf|otf)$/,media:/\.(mp4|webm|ogg|mp3|wav)$/},P=(t={},e="development")=>{let i=S.default.cpus().length||4;return{name:t.name||"ts-thread",workers:t.workers||(e==="development"?2:Math.max(1,Math.floor((i-2)/2))),workerParallelJobs:t.workerParallelJobs||(e==="development"?40:20),workerNodeArgs:Array.isArray(t.workerNodeArgs)?t.workerNodeArgs:[t.workerNodeArgs||(e==="development"?"--max-old-space-size=512":"--max-old-space-size=256")],poolRespawn:t.poolRespawn??e!=="development",poolTimeout:t.poolTimeout||500,poolParallelJobs:t.poolParallelJobs||(e==="development"?200:100)}},A=(t=!1,e)=>{let i=[];if(e?.thread){let o=P(e.workerOptions,e.mode);i.push({loader:"thread-loader",options:o})}return i.push({loader:"ts-loader",options:{compilerOptions:{declaration:!1,declarationMap:!1}}}),{mode:"none",output:{path:x.default.resolve(__dirname,"dist"),clean:!0},resolve:{extensions:[".ts",".js"],modules:["node_modules"]},module:{rules:[{test:f.js,use:i,exclude:/node_modules/},{test:f.css,use:[t?{loader:require("mini-css-extract-plugin").loader}:"style-loader",{loader:"css-loader",options:{sourceMap:!0,importLoaders:1}},"postcss-loader"]},{test:f.image,type:"asset/resource",generator:{filename:"assets/img/[hash][ext]"}},{test:f.font,type:"asset/resource",generator:{filename:"assets/font/[name][ext]"}},{test:f.media,type:"asset/resource",generator:{filename:"assets/media/[name][ext]"}}]},plugins:[new O.default({name:"coda-builder",color:"#0052cc"})],devServer:{historyApiFallback:!0,port:8080,compress:!1,open:!1,hot:!0,static:{directory:x.default.join(process.cwd(),"dist")}},stats:"minimal",devtool:e?.mode==="development"?"source-map":"cheap-module-source-map"}};var k=class{config;constructor(e){this.config={...e}}setMode(e){return this.config.mode=e,this}setEntry(e){return this.config.entry=e,this}setContext(e){return e!==void 0&&(this.config.context=e),this}setOutput(e){return e?(this.config.output={...this.config.output,...e},this):this}setDevtool(e){return e!==void 0&&(this.config.devtool=e),this}setTarget(e){return e!==void 0&&(this.config.target=e),this}setCache(e){return e!==void 0&&(this.config.cache=e),this}setResolve(e,i){let o=i?.modules,s=i?.mainFields,n=i?.alias,a=i?.extensions,r=i?.extensionAlias;return this.config.resolve={...this.config.resolve,...o?{modules:o}:{},...s?{mainFields:s}:{},...n?{alias:n}:{},...a?{extensions:a}:{},...r?{extensionAlias:r}:{},...e},this}setModule(e,i){let o=this.config.module?.rules||[],s=i?.rules||[],n=i?.noParse;return this.config.module={...this.config.module||{},...n?{noParse:n}:{},rules:[...o,...s],...e},this}setOptimization(e,i,o,s,n,a,r){let l=i;l===void 0&&(s==="web"||s==="chrome-ext")&&(l={chunks:"all",minSize:2e4,maxSize:2e5,minChunks:1,maxAsyncRequests:6,maxInitialRequests:6,cacheGroups:{libs:{name:"chunk-libs",test:/[\\/]node_modules[\\/]/,chunks:"initial",priority:20,reuseExistingChunk:!0},common:{name:"chunk-common",minChunks:2,priority:2,reuseExistingChunk:!0}}});let m=a!==void 0?a:n==="production"||n==="analyzer",c=e?.minimizer||this.config.optimization?.minimizer;if(m&&!c)try{let g=require("terser-webpack-plugin"),v=require("css-minimizer-webpack-plugin"),R=o!==void 0?o:{parse:{ecma:8},compress:{ecma:5,comparisons:!1,inline:2,warnings:!1},mangle:!0,module:!1,output:{ecma:5,comments:!1},toplevel:!1,ie8:!1,safari10:!1},C=r||2;c=[new g({parallel:C,terserOptions:R}),new v({parallel:C})]}catch{}let d=e?.runtimeChunk||this.config.optimization?.runtimeChunk;return l!==void 0&&!d&&(d={name:"manifest"}),this.config.optimization={...this.config.optimization||{},minimize:m,...l!==void 0?{splitChunks:l}:{},...c!==void 0?{minimizer:c}:{},...d!==void 0?{runtimeChunk:d}:{},...e},this}setStats(e){return e!==void 0&&(this.config.stats=e),this}setDevServer(e){if(!e)return this;let i=this.config.devServer||{};return this.config.devServer={...i,...e,...e.static?{static:typeof e.static=="object"&&typeof i.static=="object"?{...i.static,...e.static}:e.static}:{}},this}setWatch(e){return e!==void 0&&(this.config.watch=e),this}setWatchOptions(e){return e?(this.config.watchOptions={...this.config.watchOptions,...e},this):this}setExternals(e){return e!==void 0&&(this.config.externals=e),this}addPlugin(e){return this.config.plugins=this.config.plugins||[],this.config.plugins.push(e),this}addPlugins(e){return!e||!Array.isArray(e)?this:(e.forEach(i=>{i&&this.addPlugin(i)}),this)}setMaxChunks(e){if(e===void 0)return this;let i=require("webpack");return this.addPlugin(new i.optimize.LimitChunkCountPlugin({maxChunks:e})),this}getConfig(){return this.config}setConfig(e){return this.config={...this.config,...e},this}};var p=u(require("fs")),w=u(require("path")),y=class{rules;constructor(e=[]){this.rules=e}apply(e){e.hooks.thisCompilation.tap("CodaCopyWebpackPlugin",i=>{i.hooks.processAssets.tap({name:"CodaCopyWebpackPlugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},()=>{this.rules.forEach(o=>{p.default.existsSync(o.from)&&(o.type==="single"?this.processSingleFile(i,o.from,o.to):o.type==="directory"?this.processDirectory(i,o.from,o.to,o.ignore||[]):o.type==="template"&&this.processTemplate(i,o.from,o.to,o.data))})})})}processSingleFile(e,i,o){let s=p.default.readFileSync(i);e.emitAsset(o,new e.compiler.webpack.sources.RawSource(s))}processDirectory(e,i,o,s){p.default.readdirSync(i,{recursive:!0}).forEach(a=>{let r=w.default.join(i,a);if(p.default.statSync(r).isDirectory())return;let l=w.default.relative(i,r);if(s.some(c=>l.includes(c)))return;let h=w.default.join(o,l).replace(/\\/g,"/"),m=p.default.readFileSync(r);e.emitAsset(h,new e.compiler.webpack.sources.RawSource(m))})}processTemplate(e,i,o,s){let n=p.default.readFileSync(i,"utf-8");Object.keys(s).forEach(a=>{let r=a.replace(/{{\s*|\s*}}/g,""),l=new RegExp(`{{\\s*${r}\\s*}}`,"g");n=n.replace(l,String(s[a]))}),e.emitAsset(o,new e.compiler.webpack.sources.RawSource(Buffer.from(n)))}};function $(t){if(!t.techRoute)throw new Error("[coda-builder] Missing required config: techRoute");if(!t.platformTarget)throw new Error("[coda-builder] Missing required config: platformTarget");if(!t.mode)throw new Error("[coda-builder] Missing required config: mode");if(!t.entry)throw new Error("[coda-builder] Missing required config: entry")}function _(t){let e=t.mode==="production"||t.mode==="analyzer";return A(e,t)}function B(t,e){let{platformTarget:i}=t;["nodejs-cli","node-server","vscode-ext"].includes(i)?(e.setTarget("node"),i==="vscode-ext"?e.setExternals([(0,W.default)(),{vscode:"commonjs vscode"}]):e.setExternals([(0,W.default)()])):i==="chrome-ext"&&e.setTarget("web")}function I(t,e){let i=t.mode==="analyzer"?"production":t.mode;e.setMode(i).setEntry(t.entry).setContext(t.context).setOutput(t.output).setDevtool(t.devtool).setCache(t.cache).setMaxChunks(t.maxChunks).setStats(t.stats).setDevServer(t.devServer).setWatch(t.watch).setWatchOptions(t.watchOptions),e.setOptimization(t.optimization,t.splitChunks,t.terserOptions,t.platformTarget,i,t.minimize,t.parallel),e.setResolve(t.resolve,{alias:t.alias,extensions:t.extensions,extensionAlias:t.extensionAlias,modules:t.modules,mainFields:t.mainFields}),e.setModule(t.module,{noParse:t.noParse,rules:t.rules}),t.target&&e.setTarget(t.target),t.externals&&e.setExternals(t.externals)}function J(t,e){let i=t.mode==="production"||t.mode==="analyzer";if(t.copyRules&&t.copyRules.length>0&&e.addPlugin(new y(t.copyRules)),t.html)try{let o=require("html-webpack-plugin"),s=typeof t.html=="object"?t.html:{};e.addPlugin(new o(s))}catch{throw new Error('[coda-builder] html-webpack-plugin is required when using "html" config. Please install it.')}if(i)try{let o=require("mini-css-extract-plugin");e.addPlugin(new o({filename:"css/[name].[contenthash:8].css",chunkFilename:"css/[name].[contenthash:8].chunk.css"}))}catch{throw new Error("[coda-builder] mini-css-extract-plugin is required in production mode. Please install it.")}if(t.gzip!==!1&&(t.gzip||i))try{let o=require("compression-webpack-plugin"),s={filename:"[path][base].gz",algorithm:"gzip",test:/\.(js|css|png|jpg|jpeg|svg)(\?.*)?$/i,threshold:8192,minRatio:.8,deleteOriginalAssets:!1,exclude:[/node_modules/]},n=typeof t.gzip=="object"?{...s,...t.gzip}:s;e.addPlugin(new o(n))}catch{throw new Error('[coda-builder] compression-webpack-plugin is required when using "gzip" config. Please install it.')}if(t.plugins&&t.plugins.length>0&&e.addPlugins(t.plugins),t.mode==="analyzer"&&e.addPlugin(new E.BundleAnalyzerPlugin({analyzerMode:"server"})),t.platformTarget==="nodejs-cli")try{let o=require("fs"),s=require("path"),n=require("webpack"),a=s.resolve(process.cwd(),"package.json");if(o.existsSync(a)){let r=JSON.parse(o.readFileSync(a,"utf-8"));if(r.bin){let l=[];typeof r.bin=="string"?l=[r.bin]:typeof r.bin=="object"&&r.bin!==null&&(l=Object.values(r.bin)),l.forEach(h=>{let c=h.replace(/^\.\//,"").split("/"),d=c.pop()||"index.js",g=c.pop()||"bin",v=new RegExp(`${g}[\\\\/]${d}$`);e.addPlugin(new n.BannerPlugin({banner:"#!/usr/bin/env node",raw:!0,test:v}))})}}}catch{}}function L(t,e){if(t.configureWebpack&&typeof t.configureWebpack=="function"){let i=t.configureWebpack(e,t.mode);if(i)return i}return e}function M(t,e){if($(t),t.thread&&t.mode==="development")try{let n=require("thread-loader"),a=P(t.workerOptions||{name:"ts-thread",workers:2,workerParallelJobs:40,workerNodeArgs:"--max-old-space-size=512",poolRespawn:!1,poolParallelJobs:200},t.mode);n.warmup({workerBabelArgs:a},["ts-loader"])}catch{}let i=_(t),o=new k(i);o.setConfig({context:process.cwd()}),B(t,o),I(t,o),J(t,o);let s=o.getConfig();if(s=L(t,s),t.speedMeasure&&(t.mode==="development"||t.mode==="analyzer"))try{let n=require("speed-measure-webpack-v5-plugin");s=new n().wrap(s)}catch{throw new Error('[coda-builder] speed-measure-webpack-v5-plugin is required when using "speedMeasure" config. Please install it.')}return e&&(console.log("webpack\u914D\u7F6E:"),console.dir(i,{depth:null})),s}0&&(module.exports={resolveWebpackConfig});
|
package/build/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var c=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,i)=>(typeof require<"u"?require:e)[i]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import W from"webpack-node-externals";import{BundleAnalyzerPlugin as O}from"webpack-bundle-analyzer";import x from"path";import S from"os";import A from"webpackbar";var u={js:/\.(ts|js)$/,css:/\.css$/,image:/\.(png|jpg|jpeg|gif|svg)$/,font:/\.(woff|woff2|eot|ttf|otf)$/,media:/\.(mp4|webm|ogg|mp3|wav)$/},b=(t={},e="development")=>{let i=S.cpus().length||4;return{name:t.name||"ts-thread",workers:t.workers||(e==="development"?2:Math.max(1,Math.floor((i-2)/2))),workerParallelJobs:t.workerParallelJobs||(e==="development"?40:20),workerNodeArgs:Array.isArray(t.workerNodeArgs)?t.workerNodeArgs:[t.workerNodeArgs||(e==="development"?"--max-old-space-size=512":"--max-old-space-size=256")],poolRespawn:t.poolRespawn??e!=="development",poolTimeout:t.poolTimeout||500,poolParallelJobs:t.poolParallelJobs||(e==="development"?200:100)}},P=(t=!1,e)=>{let i=[];if(e?.thread){let o=b(e.workerOptions,e.mode);i.push({loader:"thread-loader",options:o})}return i.push({loader:"ts-loader",options:{compilerOptions:{declaration:!1,declarationMap:!1}}}),{mode:"none",output:{path:x.resolve(__dirname,"dist"),clean:!0},resolve:{extensions:[".ts",".js"],modules:["node_modules"]},module:{rules:[{test:u.js,use:i,exclude:/node_modules/},{test:u.css,use:[t?{loader:c("mini-css-extract-plugin").loader}:"style-loader",{loader:"css-loader",options:{sourceMap:!0,importLoaders:1}},"postcss-loader"]},{test:u.image,type:"asset/resource",generator:{filename:"assets/img/[hash][ext]"}},{test:u.font,type:"asset/resource",generator:{filename:"assets/font/[name][ext]"}},{test:u.media,type:"asset/resource",generator:{filename:"assets/media/[name][ext]"}}]},plugins:[new A({name:"coda-builder",color:"#0052cc"})],devServer:{historyApiFallback:!0,port:8080,compress:!1,open:!1,hot:!0,static:{directory:x.join(process.cwd(),"dist")}},stats:"minimal"}};var h=class{config;constructor(e){this.config={...e}}setMode(e){return this.config.mode=e,this}setEntry(e){return this.config.entry=e,this}setContext(e){return e!==void 0&&(this.config.context=e),this}setOutput(e){return e?(this.config.output={...this.config.output,...e},this):this}setDevtool(e){return e!==void 0&&(this.config.devtool=e),this}setTarget(e){return e!==void 0&&(this.config.target=e),this}setCache(e){return e!==void 0&&(this.config.cache=e),this}setResolve(e,i){let o=i?.modules,s=i?.mainFields,n=i?.alias,r=i?.extensions,a=i?.extensionAlias;return this.config.resolve={...this.config.resolve,...o?{modules:o}:{},...s?{mainFields:s}:{},...n?{alias:n}:{},...r?{extensions:r}:{},...a?{extensionAlias:a}:{},...e},this}setModule(e,i){let o=this.config.module?.rules||[],s=i?.rules||[],n=i?.noParse;return this.config.module={...this.config.module||{},...n?{noParse:n}:{},rules:[...o,...s],...e},this}setOptimization(e,i,o,s,n,r,a){let l=i;l===void 0&&(s==="web"||s==="chrome-ext")&&(l={chunks:"all",minSize:2e4,maxSize:2e5,minChunks:1,maxAsyncRequests:6,maxInitialRequests:6,cacheGroups:{libs:{name:"chunk-libs",test:/[\\/]node_modules[\\/]/,chunks:"initial",priority:20,reuseExistingChunk:!0},common:{name:"chunk-common",minChunks:2,priority:2,reuseExistingChunk:!0}}});let m=r!==void 0?r:n==="production"||n==="analyzer",p=e?.minimizer||this.config.optimization?.minimizer;if(m&&!p)try{let y=c("terser-webpack-plugin"),C=c("css-minimizer-webpack-plugin"),z=o!==void 0?o:{parse:{ecma:8},compress:{ecma:5,comparisons:!1,inline:2,warnings:!1},mangle:!0,module:!1,output:{ecma:5,comments:!1},toplevel:!1,ie8:!1,safari10:!1},v=a||2;p=[new y({parallel:v,terserOptions:z}),new C({parallel:v})]}catch{}let f=e?.runtimeChunk||this.config.optimization?.runtimeChunk;return l!==void 0&&!f&&(f={name:"manifest"}),this.config.optimization={...this.config.optimization||{},minimize:m,...l!==void 0?{splitChunks:l}:{},...p!==void 0?{minimizer:p}:{},...f!==void 0?{runtimeChunk:f}:{},...e},this}setStats(e){return e!==void 0&&(this.config.stats=e),this}setDevServer(e){if(!e)return this;let i=this.config.devServer||{};return this.config.devServer={...i,...e,...e.static?{static:typeof e.static=="object"&&typeof i.static=="object"?{...i.static,...e.static}:e.static}:{}},this}setWatch(e){return e!==void 0&&(this.config.watch=e),this}setWatchOptions(e){return e?(this.config.watchOptions={...this.config.watchOptions,...e},this):this}setExternals(e){return e!==void 0&&(this.config.externals=e),this}addPlugin(e){return this.config.plugins=this.config.plugins||[],this.config.plugins.push(e),this}addPlugins(e){return!e||!Array.isArray(e)?this:(e.forEach(i=>{i&&this.addPlugin(i)}),this)}setMaxChunks(e){if(e===void 0)return this;let i=c("webpack");return this.addPlugin(new i.optimize.LimitChunkCountPlugin({maxChunks:e})),this}getConfig(){return this.config}setConfig(e){return this.config={...this.config,...e},this}};import d from"fs";import k from"path";var g=class{rules;constructor(e=[]){this.rules=e}apply(e){e.hooks.thisCompilation.tap("CodaCopyWebpackPlugin",i=>{i.hooks.processAssets.tap({name:"CodaCopyWebpackPlugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},()=>{this.rules.forEach(o=>{d.existsSync(o.from)&&(o.type==="single"?this.processSingleFile(i,o.from,o.to):o.type==="directory"?this.processDirectory(i,o.from,o.to,o.ignore||[]):o.type==="template"&&this.processTemplate(i,o.from,o.to,o.data))})})})}processSingleFile(e,i,o){let s=d.readFileSync(i);e.emitAsset(o,new e.compiler.webpack.sources.RawSource(s))}processDirectory(e,i,o,s){d.readdirSync(i,{recursive:!0}).forEach(r=>{let a=k.join(i,r);if(d.statSync(a).isDirectory())return;let l=k.relative(i,a);if(s.some(p=>l.includes(p)))return;let w=k.join(o,l).replace(/\\/g,"/"),m=d.readFileSync(a);e.emitAsset(w,new e.compiler.webpack.sources.RawSource(m))})}processTemplate(e,i,o,s){let n=d.readFileSync(i,"utf-8");Object.keys(s).forEach(r=>{let a=r.replace(/{{\s*|\s*}}/g,""),l=new RegExp(`{{\\s*${a}\\s*}}`,"g");n=n.replace(l,String(s[r]))}),e.emitAsset(o,new e.compiler.webpack.sources.RawSource(Buffer.from(n)))}};function M(t){if(!t.techRoute)throw new Error("[coda-builder] Missing required config: techRoute");if(!t.platformTarget)throw new Error("[coda-builder] Missing required config: platformTarget");if(!t.mode)throw new Error("[coda-builder] Missing required config: mode");if(!t.entry)throw new Error("[coda-builder] Missing required config: entry")}function E(t){let e=t.mode==="production"||t.mode==="analyzer";return P(e,t)}function R(t,e){let{platformTarget:i}=t;["nodejs-cli","node-server","vscode-ext"].includes(i)?(e.setTarget("node"),i==="vscode-ext"?e.setExternals([W(),{vscode:"commonjs vscode"}]):e.setExternals([W()])):i==="chrome-ext"&&e.setTarget("web")}function j(t,e){let i=t.mode==="analyzer"?"production":t.mode;e.setMode(i).setEntry(t.entry).setContext(t.context).setOutput(t.output).setDevtool(t.devtool).setCache(t.cache).setMaxChunks(t.maxChunks).setStats(t.stats).setDevServer(t.devServer).setWatch(t.watch).setWatchOptions(t.watchOptions),e.setOptimization(t.optimization,t.splitChunks,t.terserOptions,t.platformTarget,i,t.minimize,t.parallel),e.setResolve(t.resolve,{alias:t.alias,extensions:t.extensions,extensionAlias:t.extensionAlias,modules:t.modules,mainFields:t.mainFields}),e.setModule(t.module,{noParse:t.noParse,rules:t.rules}),t.target&&e.setTarget(t.target),t.externals&&e.setExternals(t.externals)}function q(t,e){let i=t.mode==="production"||t.mode==="analyzer";if(t.copyRules&&t.copyRules.length>0&&e.addPlugin(new g(t.copyRules)),t.html)try{let o=c("html-webpack-plugin"),s=typeof t.html=="object"?t.html:{};e.addPlugin(new o(s))}catch{throw new Error('[coda-builder] html-webpack-plugin is required when using "html" config. Please install it.')}if(i)try{let o=c("mini-css-extract-plugin");e.addPlugin(new o({filename:"css/[name].[contenthash:8].css",chunkFilename:"css/[name].[contenthash:8].chunk.css"}))}catch{throw new Error("[coda-builder] mini-css-extract-plugin is required in production mode. Please install it.")}if(t.gzip!==!1&&(t.gzip||i))try{let o=c("compression-webpack-plugin"),s={filename:"[path][base].gz",algorithm:"gzip",test:/\.(js|css|png|jpg|jpeg|svg)(\?.*)?$/i,threshold:8192,minRatio:.8,deleteOriginalAssets:!1,exclude:[/node_modules/]},n=typeof t.gzip=="object"?{...s,...t.gzip}:s;e.addPlugin(new o(n))}catch{throw new Error('[coda-builder] compression-webpack-plugin is required when using "gzip" config. Please install it.')}t.plugins&&t.plugins.length>0&&e.addPlugins(t.plugins),t.mode==="analyzer"&&e.addPlugin(new O({analyzerMode:"server"}))}function T(t,e){if(t.configureWebpack&&typeof t.configureWebpack=="function"){let i=t.configureWebpack(e,t.mode);if(i)return i}return e}function N(t,e){if(M(t),t.thread&&t.mode==="development")try{let n=c("thread-loader"),r=b(t.workerOptions||{name:"ts-thread",workers:2,workerParallelJobs:40,workerNodeArgs:"--max-old-space-size=512",poolRespawn:!1,poolParallelJobs:200},t.mode);n.warmup({workerBabelArgs:r},["ts-loader"])}catch{}let i=E(t),o=new h(i);o.setConfig({context:process.cwd()}),R(t,o),j(t,o),q(t,o);let s=o.getConfig();if(s=T(t,s),t.speedMeasure&&(t.mode==="development"||t.mode==="analyzer"))try{let n=c("speed-measure-webpack-v5-plugin");s=new n().wrap(s)}catch{throw new Error('[coda-builder] speed-measure-webpack-v5-plugin is required when using "speedMeasure" config. Please install it.')}return e&&(console.log("webpack\u914D\u7F6E:"),console.dir(i,{depth:null})),s}export{N as resolveWebpackConfig};
|
|
1
|
+
var c=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,i)=>(typeof require<"u"?require:e)[i]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import C from"webpack-node-externals";import{BundleAnalyzerPlugin as A}from"webpack-bundle-analyzer";import P from"path";import S from"os";import O from"webpackbar";var f={js:/\.(ts|js)$/,css:/\.css$/,image:/\.(png|jpg|jpeg|gif|svg)$/,font:/\.(woff|woff2|eot|ttf|otf)$/,media:/\.(mp4|webm|ogg|mp3|wav)$/},y=(t={},e="development")=>{let i=S.cpus().length||4;return{name:t.name||"ts-thread",workers:t.workers||(e==="development"?2:Math.max(1,Math.floor((i-2)/2))),workerParallelJobs:t.workerParallelJobs||(e==="development"?40:20),workerNodeArgs:Array.isArray(t.workerNodeArgs)?t.workerNodeArgs:[t.workerNodeArgs||(e==="development"?"--max-old-space-size=512":"--max-old-space-size=256")],poolRespawn:t.poolRespawn??e!=="development",poolTimeout:t.poolTimeout||500,poolParallelJobs:t.poolParallelJobs||(e==="development"?200:100)}},W=(t=!1,e)=>{let i=[];if(e?.thread){let o=y(e.workerOptions,e.mode);i.push({loader:"thread-loader",options:o})}return i.push({loader:"ts-loader",options:{compilerOptions:{declaration:!1,declarationMap:!1}}}),{mode:"none",output:{path:P.resolve(__dirname,"dist"),clean:!0},resolve:{extensions:[".ts",".js"],modules:["node_modules"]},module:{rules:[{test:f.js,use:i,exclude:/node_modules/},{test:f.css,use:[t?{loader:c("mini-css-extract-plugin").loader}:"style-loader",{loader:"css-loader",options:{sourceMap:!0,importLoaders:1}},"postcss-loader"]},{test:f.image,type:"asset/resource",generator:{filename:"assets/img/[hash][ext]"}},{test:f.font,type:"asset/resource",generator:{filename:"assets/font/[name][ext]"}},{test:f.media,type:"asset/resource",generator:{filename:"assets/media/[name][ext]"}}]},plugins:[new O({name:"coda-builder",color:"#0052cc"})],devServer:{historyApiFallback:!0,port:8080,compress:!1,open:!1,hot:!0,static:{directory:P.join(process.cwd(),"dist")}},stats:"minimal",devtool:e?.mode==="development"?"source-map":"cheap-module-source-map"}};var b=class{config;constructor(e){this.config={...e}}setMode(e){return this.config.mode=e,this}setEntry(e){return this.config.entry=e,this}setContext(e){return e!==void 0&&(this.config.context=e),this}setOutput(e){return e?(this.config.output={...this.config.output,...e},this):this}setDevtool(e){return e!==void 0&&(this.config.devtool=e),this}setTarget(e){return e!==void 0&&(this.config.target=e),this}setCache(e){return e!==void 0&&(this.config.cache=e),this}setResolve(e,i){let o=i?.modules,s=i?.mainFields,n=i?.alias,a=i?.extensions,r=i?.extensionAlias;return this.config.resolve={...this.config.resolve,...o?{modules:o}:{},...s?{mainFields:s}:{},...n?{alias:n}:{},...a?{extensions:a}:{},...r?{extensionAlias:r}:{},...e},this}setModule(e,i){let o=this.config.module?.rules||[],s=i?.rules||[],n=i?.noParse;return this.config.module={...this.config.module||{},...n?{noParse:n}:{},rules:[...o,...s],...e},this}setOptimization(e,i,o,s,n,a,r){let l=i;l===void 0&&(s==="web"||s==="chrome-ext")&&(l={chunks:"all",minSize:2e4,maxSize:2e5,minChunks:1,maxAsyncRequests:6,maxInitialRequests:6,cacheGroups:{libs:{name:"chunk-libs",test:/[\\/]node_modules[\\/]/,chunks:"initial",priority:20,reuseExistingChunk:!0},common:{name:"chunk-common",minChunks:2,priority:2,reuseExistingChunk:!0}}});let m=a!==void 0?a:n==="production"||n==="analyzer",p=e?.minimizer||this.config.optimization?.minimizer;if(m&&!p)try{let g=c("terser-webpack-plugin"),w=c("css-minimizer-webpack-plugin"),z=o!==void 0?o:{parse:{ecma:8},compress:{ecma:5,comparisons:!1,inline:2,warnings:!1},mangle:!0,module:!1,output:{ecma:5,comments:!1},toplevel:!1,ie8:!1,safari10:!1},x=r||2;p=[new g({parallel:x,terserOptions:z}),new w({parallel:x})]}catch{}let d=e?.runtimeChunk||this.config.optimization?.runtimeChunk;return l!==void 0&&!d&&(d={name:"manifest"}),this.config.optimization={...this.config.optimization||{},minimize:m,...l!==void 0?{splitChunks:l}:{},...p!==void 0?{minimizer:p}:{},...d!==void 0?{runtimeChunk:d}:{},...e},this}setStats(e){return e!==void 0&&(this.config.stats=e),this}setDevServer(e){if(!e)return this;let i=this.config.devServer||{};return this.config.devServer={...i,...e,...e.static?{static:typeof e.static=="object"&&typeof i.static=="object"?{...i.static,...e.static}:e.static}:{}},this}setWatch(e){return e!==void 0&&(this.config.watch=e),this}setWatchOptions(e){return e?(this.config.watchOptions={...this.config.watchOptions,...e},this):this}setExternals(e){return e!==void 0&&(this.config.externals=e),this}addPlugin(e){return this.config.plugins=this.config.plugins||[],this.config.plugins.push(e),this}addPlugins(e){return!e||!Array.isArray(e)?this:(e.forEach(i=>{i&&this.addPlugin(i)}),this)}setMaxChunks(e){if(e===void 0)return this;let i=c("webpack");return this.addPlugin(new i.optimize.LimitChunkCountPlugin({maxChunks:e})),this}getConfig(){return this.config}setConfig(e){return this.config={...this.config,...e},this}};import u from"fs";import v from"path";var k=class{rules;constructor(e=[]){this.rules=e}apply(e){e.hooks.thisCompilation.tap("CodaCopyWebpackPlugin",i=>{i.hooks.processAssets.tap({name:"CodaCopyWebpackPlugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},()=>{this.rules.forEach(o=>{u.existsSync(o.from)&&(o.type==="single"?this.processSingleFile(i,o.from,o.to):o.type==="directory"?this.processDirectory(i,o.from,o.to,o.ignore||[]):o.type==="template"&&this.processTemplate(i,o.from,o.to,o.data))})})})}processSingleFile(e,i,o){let s=u.readFileSync(i);e.emitAsset(o,new e.compiler.webpack.sources.RawSource(s))}processDirectory(e,i,o,s){u.readdirSync(i,{recursive:!0}).forEach(a=>{let r=v.join(i,a);if(u.statSync(r).isDirectory())return;let l=v.relative(i,r);if(s.some(p=>l.includes(p)))return;let h=v.join(o,l).replace(/\\/g,"/"),m=u.readFileSync(r);e.emitAsset(h,new e.compiler.webpack.sources.RawSource(m))})}processTemplate(e,i,o,s){let n=u.readFileSync(i,"utf-8");Object.keys(s).forEach(a=>{let r=a.replace(/{{\s*|\s*}}/g,""),l=new RegExp(`{{\\s*${r}\\s*}}`,"g");n=n.replace(l,String(s[a]))}),e.emitAsset(o,new e.compiler.webpack.sources.RawSource(Buffer.from(n)))}};function E(t){if(!t.techRoute)throw new Error("[coda-builder] Missing required config: techRoute");if(!t.platformTarget)throw new Error("[coda-builder] Missing required config: platformTarget");if(!t.mode)throw new Error("[coda-builder] Missing required config: mode");if(!t.entry)throw new Error("[coda-builder] Missing required config: entry")}function M(t){let e=t.mode==="production"||t.mode==="analyzer";return W(e,t)}function R(t,e){let{platformTarget:i}=t;["nodejs-cli","node-server","vscode-ext"].includes(i)?(e.setTarget("node"),i==="vscode-ext"?e.setExternals([C(),{vscode:"commonjs vscode"}]):e.setExternals([C()])):i==="chrome-ext"&&e.setTarget("web")}function j(t,e){let i=t.mode==="analyzer"?"production":t.mode;e.setMode(i).setEntry(t.entry).setContext(t.context).setOutput(t.output).setDevtool(t.devtool).setCache(t.cache).setMaxChunks(t.maxChunks).setStats(t.stats).setDevServer(t.devServer).setWatch(t.watch).setWatchOptions(t.watchOptions),e.setOptimization(t.optimization,t.splitChunks,t.terserOptions,t.platformTarget,i,t.minimize,t.parallel),e.setResolve(t.resolve,{alias:t.alias,extensions:t.extensions,extensionAlias:t.extensionAlias,modules:t.modules,mainFields:t.mainFields}),e.setModule(t.module,{noParse:t.noParse,rules:t.rules}),t.target&&e.setTarget(t.target),t.externals&&e.setExternals(t.externals)}function q(t,e){let i=t.mode==="production"||t.mode==="analyzer";if(t.copyRules&&t.copyRules.length>0&&e.addPlugin(new k(t.copyRules)),t.html)try{let o=c("html-webpack-plugin"),s=typeof t.html=="object"?t.html:{};e.addPlugin(new o(s))}catch{throw new Error('[coda-builder] html-webpack-plugin is required when using "html" config. Please install it.')}if(i)try{let o=c("mini-css-extract-plugin");e.addPlugin(new o({filename:"css/[name].[contenthash:8].css",chunkFilename:"css/[name].[contenthash:8].chunk.css"}))}catch{throw new Error("[coda-builder] mini-css-extract-plugin is required in production mode. Please install it.")}if(t.gzip!==!1&&(t.gzip||i))try{let o=c("compression-webpack-plugin"),s={filename:"[path][base].gz",algorithm:"gzip",test:/\.(js|css|png|jpg|jpeg|svg)(\?.*)?$/i,threshold:8192,minRatio:.8,deleteOriginalAssets:!1,exclude:[/node_modules/]},n=typeof t.gzip=="object"?{...s,...t.gzip}:s;e.addPlugin(new o(n))}catch{throw new Error('[coda-builder] compression-webpack-plugin is required when using "gzip" config. Please install it.')}if(t.plugins&&t.plugins.length>0&&e.addPlugins(t.plugins),t.mode==="analyzer"&&e.addPlugin(new A({analyzerMode:"server"})),t.platformTarget==="nodejs-cli")try{let o=c("fs"),s=c("path"),n=c("webpack"),a=s.resolve(process.cwd(),"package.json");if(o.existsSync(a)){let r=JSON.parse(o.readFileSync(a,"utf-8"));if(r.bin){let l=[];typeof r.bin=="string"?l=[r.bin]:typeof r.bin=="object"&&r.bin!==null&&(l=Object.values(r.bin)),l.forEach(h=>{let p=h.replace(/^\.\//,"").split("/"),d=p.pop()||"index.js",g=p.pop()||"bin",w=new RegExp(`${g}[\\\\/]${d}$`);e.addPlugin(new n.BannerPlugin({banner:"#!/usr/bin/env node",raw:!0,test:w}))})}}}catch{}}function N(t,e){if(t.configureWebpack&&typeof t.configureWebpack=="function"){let i=t.configureWebpack(e,t.mode);if(i)return i}return e}function T(t,e){if(E(t),t.thread&&t.mode==="development")try{let n=c("thread-loader"),a=y(t.workerOptions||{name:"ts-thread",workers:2,workerParallelJobs:40,workerNodeArgs:"--max-old-space-size=512",poolRespawn:!1,poolParallelJobs:200},t.mode);n.warmup({workerBabelArgs:a},["ts-loader"])}catch{}let i=M(t),o=new b(i);o.setConfig({context:process.cwd()}),R(t,o),j(t,o),q(t,o);let s=o.getConfig();if(s=N(t,s),t.speedMeasure&&(t.mode==="development"||t.mode==="analyzer"))try{let n=c("speed-measure-webpack-v5-plugin");s=new n().wrap(s)}catch{throw new Error('[coda-builder] speed-measure-webpack-v5-plugin is required when using "speedMeasure" config. Please install it.')}return e&&(console.log("webpack\u914D\u7F6E:"),console.dir(i,{depth:null})),s}export{T as resolveWebpackConfig};
|