MCPcopy Index your code
hub / github.com/developit/optimize-plugin / optimize

Method optimize

src/index.js:120–224  ·  view source on GitHub ↗
(compiler, compilation, chunkFiles)

Source from the content-addressed store, hash-verified

118 }
119
120 async optimize (compiler, compilation, chunkFiles) {
121 const cwd = compiler.context;
122 const { timings, start, end } = createPerformanceTimings();
123
124 const options = {
125 corejsVersion: getCorejsVersion(),
126 minify: this.options.minify,
127 downlevel: this.options.downlevel,
128 modernize: this.options.modernize,
129 timings: this.options.verbose
130 };
131
132 const processing = new WeakMap();
133 const chunkAssets = Array.from(compilation.additionalChunkAssets || []);
134 const files = [...chunkFiles, ...chunkAssets]
135 .filter((asset) => {
136 for (const pattern of this.options.exclude) {
137 if (pattern.test(asset)) {
138 return false;
139 }
140 }
141 return true;
142 });
143
144 start('Optimize Assets');
145 let transformed;
146 try {
147 transformed = await Promise.all(files.map(file => {
148 // ignore non-JS files
149 if (!file.match(/\.m?[jt]sx?$/i)) return undefined;
150 const asset = compilation.assets[file];
151 let pending = processing.get(asset);
152 if (pending) return pending;
153
154 let source, map;
155 if (this.options.sourceMap && asset.sourceAndMap) {
156 ({ source, map } = asset.sourceAndMap());
157 } else {
158 source = asset.source();
159 }
160
161 const original = { file, source, map, options };
162 // @ts-ignore-next
163 const result = this.workerPool.enqueue(original);
164 pending = result.then(this.buildResultSources.bind(this, original)).catch(console.error);
165 processing.set(asset, pending);
166
167 const t = ` └ ${file}`;
168 start(t);
169 result.then(r => {
170 for (const entry of r.timings) {
171 // entry.name = ' ' + entry.name;
172 entry.depth = 2;
173 timings.push(entry);
174 }
175 end(t);
176 });
177

Callers 1

applyMethod · 0.95

Calls 7

showOutputSummaryMethod · 0.95
createPerformanceTimingsFunction · 0.90
getCorejsVersionFunction · 0.90
startFunction · 0.85
endFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected