@flatjs/evolve 2.1.0-next.12 → 2.1.0-next.13
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/compiler/create-global-compiler.d.ts +2 -0
- package/dist/compiler/create-global-compiler.js +1 -0
- package/dist/constants.js +1 -36
- package/dist/create-webpack/create-externals.js +1 -6
- package/dist/create-webpack/create-optimization.js +1 -43
- package/dist/create-webpack/create-output.js +1 -35
- package/dist/create-webpack/create-performance.js +1 -7
- package/dist/create-webpack/create-plugins.js +1 -78
- package/dist/create-webpack/create-resolve.js +1 -37
- package/dist/create-webpack/create-rule-sets.js +1 -20
- package/dist/create-webpack/load-watch-options.d.ts +12 -0
- package/dist/create-webpack/load-watch-options.js +1 -0
- package/dist/create-webpack/load-webpack-config.js +1 -57
- package/dist/create-webpack/resolve-public-path.js +1 -15
- package/dist/create-webpack/rule-sets/constants.js +1 -3
- package/dist/create-webpack/rule-sets/rule-assets.js +1 -52
- package/dist/create-webpack/rule-sets/rule-css.js +1 -111
- package/dist/create-webpack/rule-sets/rule-less.js +1 -44
- package/dist/create-webpack/rule-sets/rule-scripts.d.ts +2 -0
- package/dist/create-webpack/rule-sets/rule-scripts.js +1 -34
- package/dist/create-webpack/rule-sets/rule-svg-icon.js +1 -25
- package/dist/create-webpack/rule-sets/rule-utils.js +1 -10
- package/dist/create-webpack/types.d.ts +1 -1
- package/dist/create-webpack/types.js +1 -1
- package/dist/default-options.js +1 -83
- package/dist/define-config/define-config.d.ts +2 -2
- package/dist/define-config/define-config.js +1 -4
- package/dist/define-config/index.js +1 -1
- package/dist/dev-server/add-compiler-to-dev-server.js +1 -58
- package/dist/dev-server/create-app-page-route.js +1 -13
- package/dist/dev-server/create-dev-server-compiler-task.js +1 -55
- package/dist/dev-server/create-dev-server-entries.js +1 -25
- package/dist/dev-server/create-dev-server.js +1 -24
- package/dist/dev-server/index.d.ts +3 -3
- package/dist/dev-server/index.js +1 -6
- package/dist/dev-server/middlewares/create-page-middleware.js +1 -33
- package/dist/dev-server/middlewares/create-public-assets-middleware.js +1 -25
- package/dist/dev-server/middlewares/get-all-sorted-modules.js +1 -24
- package/dist/dev-server/middlewares/get-bundle-asset.js +1 -7
- package/dist/dev-server/middlewares/get-dev-server-host-uri.js +1 -5
- package/dist/dev-server/middlewares/get-hmr-runtime-chunks.js +1 -14
- package/dist/dev-server/middlewares/get-normalized-entry-name.js +1 -14
- package/dist/dev-server/middlewares/get-page-main-html.js +1 -49
- package/dist/dev-server/middlewares/get-page-module-html.js +1 -123
- package/dist/dev-server/middlewares/get-project-virtual-path.js +1 -3
- package/dist/dev-server/middlewares/get-runtime-manifest.js +1 -25
- package/dist/dev-server/middlewares/index.js +1 -2
- package/dist/dev-server/middlewares/types.js +1 -1
- package/dist/errors/evolve-build-error.js +1 -10
- package/dist/helpers/allow-px2rem-for-module.js +1 -6
- package/dist/helpers/assert-group-entry-item.js +1 -19
- package/dist/helpers/assert-single-compiler.js +1 -45
- package/dist/helpers/chunk-entry-map.js +1 -21
- package/dist/helpers/delete-object-keys.js +1 -20
- package/dist/helpers/enable-bundle-hashname-for-module.js +1 -6
- package/dist/helpers/filter-actived-entries.js +1 -42
- package/dist/helpers/flat-entry-map.js +1 -11
- package/dist/helpers/get-bundle-file-name.js +1 -23
- package/dist/helpers/get-git-root.js +1 -4
- package/dist/helpers/get-html-plugin-config.js +1 -47
- package/dist/helpers/get-max-process-tasks.js +1 -7
- package/dist/helpers/get-pacakge-dir.js +1 -13
- package/dist/helpers/get-runtime-cdn-base.d.ts +1 -1
- package/dist/helpers/get-runtime-cdn-base.js +1 -21
- package/dist/helpers/index.d.ts +11 -11
- package/dist/helpers/index.js +1 -27
- package/dist/helpers/is-deep-equal.js +1 -67
- package/dist/helpers/json-serializer.js +1 -52
- package/dist/helpers/merge-babel-options.js +1 -45
- package/dist/helpers/normalize-check-entry-options.js +1 -28
- package/dist/helpers/normalize-entry-map.js +1 -59
- package/dist/helpers/normalize-group-name.js +1 -16
- package/dist/helpers/normalize-page-proxy.js +1 -9
- package/dist/helpers/normalize-resolve-alias.js +1 -7
- package/dist/helpers/normalize-template-inject-tokens.js +1 -22
- package/dist/helpers/open-page.js +1 -15
- package/dist/helpers/print-log.js +1 -49
- package/dist/helpers/refresh-evolve-mock-options.js +1 -34
- package/dist/helpers/resolve-entry-map-input-files.js +1 -20
- package/dist/helpers/script-injects.d.ts +1 -1
- package/dist/helpers/script-injects.js +1 -39
- package/dist/helpers/should-enable-react-fast-refresh.js +1 -14
- package/dist/helpers/split-to-entry-group.d.ts +1 -1
- package/dist/helpers/split-to-entry-group.js +1 -139
- package/dist/helpers/verify-group-entry-options.js +1 -21
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -5
- package/dist/load-config/index.js +1 -1
- package/dist/load-config/load-evolve-config.js +1 -41
- package/dist/load-config/types.js +1 -1
- package/dist/loaders/loader-icon.cjs +2 -1
- package/dist/main/create-thread-worker.js +1 -51
- package/dist/main/env-verify.js +1 -21
- package/dist/main/get-worker-path.js +1 -5
- package/dist/main/index.d.ts +1 -1
- package/dist/main/index.js +1 -4
- package/dist/main/prepare-build.js +1 -39
- package/dist/main/prepare-serve.js +1 -69
- package/dist/main/prepare-static.js +1 -30
- package/dist/main/start-build-dynamic.js +1 -171
- package/dist/main/start-build-worker.js +1 -44
- package/dist/main/start-build.js +1 -69
- package/dist/main/start-group-entry-build.d.ts +1 -1
- package/dist/main/start-group-entry-build.js +1 -32
- package/dist/main/start-serve.js +1 -34
- package/dist/main/start-static.js +1 -19
- package/dist/minimizer/create-minimizers.js +1 -25
- package/dist/minimizer/default-options.js +1 -14
- package/dist/minimizer/image-minimizer.js +1 -65
- package/dist/minimizer/index.js +1 -1
- package/dist/minimizer/terser-minimizer.js +3 -15
- package/dist/minimizer/types.js +1 -1
- package/dist/plugins/circular-dependency/circular-dependency-plugin.js +1 -119
- package/dist/plugins/circular-dependency/index.js +1 -15
- package/dist/plugins/clean-webpack/clean-webpack-plugin.js +1 -173
- package/dist/plugins/clean-webpack/index.js +1 -22
- package/dist/plugins/define-variable/define-variable-plugin.js +1 -28
- package/dist/plugins/define-variable/index.js +1 -1
- package/dist/plugins/html-inject-scripts/plugin-html-inject-script.js +1 -27
- package/dist/plugins/module-federation/external-template-remotes.js +1 -92
- package/dist/plugins/module-federation/index.js +1 -1
- package/dist/plugins/module-federation/module-federation.js +1 -100
- package/dist/plugins/multi-html/index.js +1 -16
- package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -83
- package/dist/plugins/multi-html/multi-html-plugin.js +1 -65
- package/dist/plugins/ts-checker/ts-checker-guard-plugin.d.ts +13 -0
- package/dist/plugins/ts-checker/ts-checker-guard-plugin.js +1 -0
- package/dist/plugins/ts-checker/ts-checker-plugin.d.ts +1 -2
- package/dist/plugins/ts-checker/ts-checker-plugin.js +1 -24
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +1 -8
- package/dist/types/types-ci.js +1 -1
- package/dist/types/types-dev-server.d.ts +5 -6
- package/dist/types/types-dev-server.js +1 -1
- package/dist/types/types-entry-map.js +1 -1
- package/dist/types/types-federation.js +1 -1
- package/dist/types/types-global-compiler-options.d.ts +7 -0
- package/dist/types/types-global-compiler-options.js +1 -0
- package/dist/types/types-loader-options.d.ts +2 -7
- package/dist/types/types-loader-options.js +1 -1
- package/dist/types/types-modular-import.js +1 -1
- package/dist/types/types-multi-html.js +1 -1
- package/dist/types/types-options.d.ts +6 -1
- package/dist/types/types-options.js +1 -1
- package/dist/types/types-plugin-options.js +1 -1
- package/dist/types/types-threads-options.js +1 -1
- package/dist/types/types-webpack.d.ts +1 -1
- package/dist/types/types-webpack.js +1 -1
- package/package.json +30 -32
- package/dist/plugins/ts-checker/index.d.ts +0 -1
- package/dist/plugins/ts-checker/index.js +0 -1
@@ -1,171 +1 @@
|
|
1
|
-
import {
|
2
|
-
import { getDiffFiles, getCommitIdOfBranch } from '@armit/git';
|
3
|
-
import { arraysIntersect, chalk, logger, requireResolve } from '@flatjs/common';
|
4
|
-
import { traverseGraph } from '@flatjs/graph';
|
5
|
-
import Listr from 'listr';
|
6
|
-
import { ignoreEntryOptionKeys, moduleName } from '../constants.js';
|
7
|
-
import { filterActivedEntriesByEntryInputs, filterActivedEntriesByModule, } from '../helpers/filter-actived-entries.js';
|
8
|
-
import { getGitRoot } from '../helpers/get-git-root.js';
|
9
|
-
import { getMaxProcessTasks } from '../helpers/get-max-process-tasks.js';
|
10
|
-
import { jsonSerializer } from '../helpers/json-serializer.js';
|
11
|
-
import { normalizeEvolveEntryMap } from '../helpers/normalize-entry-map.js';
|
12
|
-
import { resolveEntryMapInputFiles } from '../helpers/resolve-entry-map-input-files.js';
|
13
|
-
import { splitToEntryGroup } from '../helpers/split-to-entry-group.js';
|
14
|
-
import { loadEvolveConfig } from '../load-config/load-evolve-config.js';
|
15
|
-
import { createThreadWorker } from './create-thread-worker.js';
|
16
|
-
import { envVerify } from './env-verify.js';
|
17
|
-
export async function getBuildEntryFiles(projectCwd, diffFiles, allEntryInputs, resolveAlias, graphTreeNodeFilter) {
|
18
|
-
const toBuildEntryFiles = [];
|
19
|
-
const entryInputsPendingToCheck = [];
|
20
|
-
for (const entryInput of allEntryInputs) {
|
21
|
-
// If entry have been existed in diff files, need to rebuild.
|
22
|
-
if (diffFiles.includes(entryInput)) {
|
23
|
-
toBuildEntryFiles.push(entryInput);
|
24
|
-
}
|
25
|
-
else {
|
26
|
-
entryInputsPendingToCheck.push(entryInput);
|
27
|
-
}
|
28
|
-
}
|
29
|
-
if (graphTreeNodeFilter) {
|
30
|
-
logger.info(`Use custom graph traverse filter`, moduleName);
|
31
|
-
}
|
32
|
-
// If there has pedding entry inputs to check.
|
33
|
-
if (entryInputsPendingToCheck.length) {
|
34
|
-
const graphDeps = await traverseGraph({
|
35
|
-
input: entryInputsPendingToCheck,
|
36
|
-
projectCwd,
|
37
|
-
treeNodeFilter: graphTreeNodeFilter || (() => true),
|
38
|
-
lessImportOptions: {
|
39
|
-
projectCwd,
|
40
|
-
aliases: resolveAlias,
|
41
|
-
},
|
42
|
-
});
|
43
|
-
if (!graphDeps) {
|
44
|
-
return toBuildEntryFiles;
|
45
|
-
}
|
46
|
-
logger.debug(`DependencyGraph:\n${JSON.stringify(graphDeps, null, 2)}`);
|
47
|
-
for (const entryInputToCheck of entryInputsPendingToCheck) {
|
48
|
-
const dependsFiles = graphDeps[entryInputToCheck] || [];
|
49
|
-
if (arraysIntersect(dependsFiles, diffFiles)) {
|
50
|
-
toBuildEntryFiles.push(entryInputToCheck);
|
51
|
-
}
|
52
|
-
}
|
53
|
-
}
|
54
|
-
return toBuildEntryFiles;
|
55
|
-
}
|
56
|
-
/**
|
57
|
-
* Dynamic check which entry modules need to build.
|
58
|
-
* @returns
|
59
|
-
*/
|
60
|
-
export async function dynamicCheckBuildEntryMap(projectCwd, earlyCommit, lastCommit, overrideEvolveOptions, configLoaderOptions) {
|
61
|
-
const command = {
|
62
|
-
projectCwd,
|
63
|
-
command: 'build',
|
64
|
-
resolve: requireResolve,
|
65
|
-
};
|
66
|
-
// 1. Try to load evolve configuration from `flatjs-evolve.config.ts`
|
67
|
-
const newEvolveOptions = await loadEvolveConfig(command, projectCwd, overrideEvolveOptions, configLoaderOptions);
|
68
|
-
// 2. Check if we have fixed build modules.
|
69
|
-
if (newEvolveOptions.ci?.fixedBuildModules &&
|
70
|
-
newEvolveOptions.ci?.fixedBuildModules.length) {
|
71
|
-
logger.info('Use `fixedBuildModules` configuration to build...');
|
72
|
-
const buildEntries = filterActivedEntriesByModule(newEvolveOptions.entryMap, newEvolveOptions.ci?.fixedBuildModules);
|
73
|
-
return { buildEntries, newEvolveOptions };
|
74
|
-
}
|
75
|
-
logger.info('Dynamicly checking code changed modules ...');
|
76
|
-
// 3. Resolve diff files based on specificed branch.
|
77
|
-
// Check if we have fixed `early commit` if no resolve based on `Branch` from evolve config file.
|
78
|
-
if (!earlyCommit) {
|
79
|
-
const basedBranch = newEvolveOptions.ci?.basedBranch || 'origin/master';
|
80
|
-
earlyCommit = await getCommitIdOfBranch(basedBranch);
|
81
|
-
// Try resolve based branch commit hash.
|
82
|
-
logger.info(`Resolving base branch "${basedBranch}" commit hash "${earlyCommit}" ...`);
|
83
|
-
}
|
84
|
-
// `packages/evolve/tests/main/fixtures/src/home/index.ts` without repo cwd.
|
85
|
-
let diffFiles = earlyCommit
|
86
|
-
? await getDiffFiles(earlyCommit, lastCommit)
|
87
|
-
: [];
|
88
|
-
const gitRoot = getGitRoot(projectCwd);
|
89
|
-
if (!gitRoot) {
|
90
|
-
throw new Error(`No .git root (${projectCwd}) found`);
|
91
|
-
}
|
92
|
-
// Hack diff files with git repo root dir.
|
93
|
-
diffFiles = diffFiles.map((diffFile) => {
|
94
|
-
return isAbsolute(diffFile) ? diffFile : join(gitRoot, diffFile);
|
95
|
-
});
|
96
|
-
logger.debug(`Diff files: \n${JSON.stringify(diffFiles, null, 2)}`);
|
97
|
-
// No code changed here.
|
98
|
-
if (!diffFiles.length) {
|
99
|
-
logger.warn('It seems that there are no code files changed.');
|
100
|
-
return {
|
101
|
-
buildEntries: {},
|
102
|
-
newEvolveOptions,
|
103
|
-
};
|
104
|
-
}
|
105
|
-
// 4. Resolve entry input files.
|
106
|
-
const allEntryInputs = await resolveEntryMapInputFiles(projectCwd, newEvolveOptions.entryMap);
|
107
|
-
// 5. Flag changed entries (with absolute filepath)
|
108
|
-
const toBuildEntryFiles = await getBuildEntryFiles(projectCwd, diffFiles, allEntryInputs, newEvolveOptions.webpack?.resolve?.alias, newEvolveOptions.ci?.graphTreeNodeFilter);
|
109
|
-
logger.debug(`To build entry files: \n${JSON.stringify(toBuildEntryFiles, null, 2)}`);
|
110
|
-
// 6. Filter entry map items which need to build.
|
111
|
-
const buildEntries = await filterActivedEntriesByEntryInputs(projectCwd, newEvolveOptions.entryMap, toBuildEntryFiles);
|
112
|
-
return { buildEntries, newEvolveOptions };
|
113
|
-
}
|
114
|
-
/**
|
115
|
-
* The main entry to start an evolve `build` with automatically detect modules which have been changed between two commits.
|
116
|
-
* @param projectCwd The Root directory (workspace) of this project.
|
117
|
-
* @param earlyCommit The diff based earlier commit hash
|
118
|
-
* @param lastCommit If is omitted, it will have the same effect as using HEAD instead.
|
119
|
-
*/
|
120
|
-
export const startDynamicBuild = async (projectCwd, earlyCommit, lastCommit, overrideEvolveOptions = {}, configLoaderOptions) => {
|
121
|
-
// 1. Fetch all changed files between two `commit`
|
122
|
-
const { buildEntries, newEvolveOptions } = await dynamicCheckBuildEntryMap(projectCwd, earlyCommit, lastCommit, overrideEvolveOptions, configLoaderOptions);
|
123
|
-
await envVerify(projectCwd, newEvolveOptions);
|
124
|
-
// Make sure that each entry option includes the groupName
|
125
|
-
const normalizedBuildOneEntry = normalizeEvolveEntryMap(buildEntries, newEvolveOptions.entryMap);
|
126
|
-
const entryMapGroupList = splitToEntryGroup(normalizedBuildOneEntry, newEvolveOptions, ignoreEntryOptionKeys, false);
|
127
|
-
if (!entryMapGroupList.length) {
|
128
|
-
logger.warn(`No build entries provided!`);
|
129
|
-
return [];
|
130
|
-
}
|
131
|
-
const buildEntryGroupNames = entryMapGroupList.map((group) => {
|
132
|
-
return Object.values(group)?.[0]?.groupName;
|
133
|
-
});
|
134
|
-
const { threads = {} } = newEvolveOptions;
|
135
|
-
const maxThreads = getMaxProcessTasks(entryMapGroupList.length, threads?.maxThreads);
|
136
|
-
logger.info(`Start dynamic build with (${chalk(['magenta'])(String(maxThreads))}) workers:\n${JSON.stringify({ buildEntriesGroup: buildEntryGroupNames }, null, 2)}`);
|
137
|
-
const worker = createThreadWorker({ ...threads, maxThreads });
|
138
|
-
const buildTasks = new Listr([], {
|
139
|
-
concurrent: maxThreads,
|
140
|
-
exitOnError: true,
|
141
|
-
});
|
142
|
-
const buildResults = [];
|
143
|
-
for (const entryMapGroupItem of entryMapGroupList) {
|
144
|
-
const groupName = Object.values(entryMapGroupItem)?.[0]?.groupName || '';
|
145
|
-
const entryKeys = Object.keys(entryMapGroupItem);
|
146
|
-
buildTasks.add({
|
147
|
-
title: `Build group ${groupName}: ${chalk(['magenta'])(`${JSON.stringify(entryKeys, null, 2)}`)} ...`,
|
148
|
-
task: async () => {
|
149
|
-
const buildResult = await worker.startBuildWorker({
|
150
|
-
projectCwd: projectCwd,
|
151
|
-
entryKeys: entryKeys,
|
152
|
-
serializedEvolveOptions: jsonSerializer.stringify(overrideEvolveOptions),
|
153
|
-
configLoaderOptions: configLoaderOptions,
|
154
|
-
});
|
155
|
-
buildResults.push(buildResult);
|
156
|
-
},
|
157
|
-
});
|
158
|
-
}
|
159
|
-
if (buildTasks.tasks.length) {
|
160
|
-
try {
|
161
|
-
await buildTasks.run();
|
162
|
-
}
|
163
|
-
catch (err) {
|
164
|
-
worker.terminate();
|
165
|
-
// we need to catch the error here, make sure the `worker` can be terminated.
|
166
|
-
throw err;
|
167
|
-
}
|
168
|
-
}
|
169
|
-
worker.terminate();
|
170
|
-
return buildResults;
|
171
|
-
};
|
1
|
+
import Listr from"listr";import{isAbsolute,join}from"node:path";import{getCommitIdOfBranch,getDiffFiles}from"@armit/git";import{arraysIntersect,chalk,logger,requireResolve}from"@flatjs/common";import{traverseGraph}from"@flatjs/graph";import{createGlobalCompiler}from"../compiler/create-global-compiler.js";import{ignoreEntryOptionKeys,moduleName}from"../constants.js";import{filterActivedEntriesByEntryInputs,filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{getGitRoot}from"../helpers/get-git-root.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{resolveEntryMapInputFiles}from"../helpers/resolve-entry-map-input-files.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export async function getBuildEntryFiles(e,r,t,o,i){const n=[],s=[];for(const e of t)r.includes(e)?n.push(e):s.push(e);if(i&&logger.info("Use custom graph traverse filter",moduleName),s.length){const t=await traverseGraph({input:s,projectCwd:e,treeNodeFilter:i||(()=>!0),lessImportOptions:{projectCwd:e,aliases:o}});if(!t)return n;logger.debug(`DependencyGraph:\n${JSON.stringify(t,null,2)}`);for(const e of s){const o=t[e]||[];arraysIntersect(o,r)&&n.push(e)}}return n}export async function dynamicCheckBuildEntryMap(e,r,t,o,i){const n={projectCwd:e,command:"build",resolve:requireResolve},s=await loadEvolveConfig(n,e,o,i);if(s.ci?.fixedBuildModules&&s.ci?.fixedBuildModules.length){logger.info("Use `fixedBuildModules` configuration to build...");return{buildEntries:filterActivedEntriesByModule(s.entryMap,s.ci?.fixedBuildModules),newEvolveOptions:s}}if(logger.info("Dynamicly checking code changed modules ..."),!r){const e=s.ci?.basedBranch||"origin/master";r=await getCommitIdOfBranch(e),logger.info(`Resolving base branch "${e}" commit hash "${r}" ...`)}let a=r?await getDiffFiles(r,t):[];const l=getGitRoot(e);if(!l)throw new Error(`No .git root (${e}) found`);if(a=a.map((e=>isAbsolute(e)?e:join(l,e))),logger.debug(`Diff files: \n${JSON.stringify(a,null,2)}`),!a.length)return logger.warn("It seems that there are no code files changed."),{buildEntries:{},newEvolveOptions:s};const c=await resolveEntryMapInputFiles(e,s.entryMap),p=await getBuildEntryFiles(e,a,c,s.webpack?.resolve?.alias,s.ci?.graphTreeNodeFilter);logger.debug(`To build entry files: \n${JSON.stringify(p,null,2)}`);return{buildEntries:await filterActivedEntriesByEntryInputs(e,s.entryMap,p),newEvolveOptions:s}}export const startDynamicBuild=async(e,r,t,o={},i)=>{const{buildEntries:n,newEvolveOptions:s}=await dynamicCheckBuildEntryMap(e,r,t,o,i);await envVerify(e,s);const a=normalizeEvolveEntryMap(n,s.entryMap),l=splitToEntryGroup(a,s,ignoreEntryOptionKeys,!1);if(!l.length)return logger.warn("No build entries provided!"),[];const c=l.map((e=>Object.values(e)?.[0]?.groupName));await createGlobalCompiler(!1,s);const{threads:p={}}=s,d=getMaxProcessTasks(l.length,p?.maxThreads);logger.info(`Start dynamic build with (${chalk(["magenta"])(String(d))}) workers:\n${JSON.stringify({buildEntriesGroup:c},null,2)}`);const m=createThreadWorker({...p,maxThreads:d}),f=new Listr([],{concurrent:d,exitOnError:!0}),g=[];for(const r of l){const t=Object.values(r)?.[0]?.groupName||"",n=Object.keys(r);f.add({title:`Build group ${t}: ${chalk(["magenta"])(`${JSON.stringify(n,null,2)}`)} ...`,task:async()=>{const r=await m.startBuildWorker({projectCwd:e,entryKeys:n,serializedEvolveOptions:jsonSerializer.stringify(o),configLoaderOptions:i});g.push(r)}})}if(f.tasks.length)try{await f.run()}catch(e){throw m.terminate(),e}return m.terminate(),g};
|
@@ -1,44 +1 @@
|
|
1
|
-
import
|
2
|
-
import { ignoreEntryOptionKeys } from '../constants.js';
|
3
|
-
import { filterActivedEntriesByModule } from '../helpers/filter-actived-entries.js';
|
4
|
-
import { jsonSerializer } from '../helpers/json-serializer.js';
|
5
|
-
import { normalizeEvolveEntryMap } from '../helpers/normalize-entry-map.js';
|
6
|
-
import { splitToEntryGroup } from '../helpers/split-to-entry-group.js';
|
7
|
-
import { loadEvolveConfig } from '../load-config/load-evolve-config.js';
|
8
|
-
import { prepareBuild } from './prepare-build.js';
|
9
|
-
/**
|
10
|
-
* FIXME: The main entry to start an evolve `build`, NOTE: avoid pass configuration with `function` here.
|
11
|
-
* If you need to call build api avoid `worker` you can directly call `prepareBuild`
|
12
|
-
* @internal
|
13
|
-
* @param options.projectCwd The Root directory (workspace) of this project.
|
14
|
-
* @param options.entryKey The `entryKey` for one entry build task
|
15
|
-
* @param options.serializedEvolveOptions The overrided evolve options, NOTE: we will serialize `function` property here first
|
16
|
-
* @param options.configLoaderOptions Evolve config loader options, NOTE: avoid pass configuration with `function` here.
|
17
|
-
*/
|
18
|
-
export default async (options) => {
|
19
|
-
const { projectCwd, entryKeys, serializedEvolveOptions, configLoaderOptions, } = options;
|
20
|
-
const command = {
|
21
|
-
projectCwd,
|
22
|
-
command: 'build',
|
23
|
-
resolve: requireResolve,
|
24
|
-
};
|
25
|
-
const overrideEvolveOptions = jsonSerializer.parse(serializedEvolveOptions) || {};
|
26
|
-
// Try to load evolve configuration from `flatjs-evolve.config.ts`
|
27
|
-
// FIXME: Cause of `worker-theads` do not support pass configuration with `function` reference.
|
28
|
-
const newEvolveOptions = await loadEvolveConfig(command, projectCwd, overrideEvolveOptions, configLoaderOptions);
|
29
|
-
// FIXME: Cause of `worker threads` we need avoid pass entryItem config directly
|
30
|
-
// because we have some config node item with `function`
|
31
|
-
// It will break `worker threads` comunication, e.g below shown.
|
32
|
-
// DataCloneError: function (url) {
|
33
|
-
// if (url.indexOf('dev.flatjs.com') > 0) return 'me';
|
34
|
-
// if (url.indexOf('.qa.') > 0) retur...<omitted>... } could not be cloned.
|
35
|
-
// at new DOMException (node:internal/per_context/domexception:53:5)
|
36
|
-
// So we need to re cacalculate the build entry via `entryKey`
|
37
|
-
const modulesRegList = entryKeys.map((key) => new RegExp(`^${key}$`));
|
38
|
-
const buildGroupEntry = filterActivedEntriesByModule(newEvolveOptions.entryMap,
|
39
|
-
// Make sure that the entryKey is correct match.
|
40
|
-
modulesRegList);
|
41
|
-
const normalizedBuildGroupEntry = normalizeEvolveEntryMap(buildGroupEntry, newEvolveOptions.entryMap);
|
42
|
-
const entryMapGroupList = splitToEntryGroup(normalizedBuildGroupEntry, newEvolveOptions, ignoreEntryOptionKeys, false);
|
43
|
-
return prepareBuild(entryMapGroupList[0], newEvolveOptions);
|
44
|
-
};
|
1
|
+
import{requireResolve}from"@flatjs/common";import{ignoreEntryOptionKeys}from"../constants.js";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareBuild}from"./prepare-build.js";export default async e=>{const{projectCwd:r,entryKeys:o,serializedEvolveOptions:i,configLoaderOptions:t}=e,n={projectCwd:r,command:"build",resolve:requireResolve},p=jsonSerializer.parse(i)||{},l=await loadEvolveConfig(n,r,p,t),s=o.map((e=>new RegExp(`^${e}$`))),a=filterActivedEntriesByModule(l.entryMap,s),m=normalizeEvolveEntryMap(a,l.entryMap),d=splitToEntryGroup(m,l,ignoreEntryOptionKeys,!1);return prepareBuild(d[0],l)};
|
package/dist/main/start-build.js
CHANGED
@@ -1,69 +1 @@
|
|
1
|
-
import {
|
2
|
-
import Listr from 'listr';
|
3
|
-
import { ignoreEntryOptionKeys } from '../constants.js';
|
4
|
-
import { filterActivedEntriesByModule } from '../helpers/filter-actived-entries.js';
|
5
|
-
import { getMaxProcessTasks } from '../helpers/get-max-process-tasks.js';
|
6
|
-
import { jsonSerializer } from '../helpers/json-serializer.js';
|
7
|
-
import { normalizeEvolveEntryMap } from '../helpers/normalize-entry-map.js';
|
8
|
-
import { splitToEntryGroup } from '../helpers/split-to-entry-group.js';
|
9
|
-
import { loadEvolveConfig } from '../load-config/load-evolve-config.js';
|
10
|
-
import { createThreadWorker } from './create-thread-worker.js';
|
11
|
-
import { envVerify } from './env-verify.js';
|
12
|
-
export const startBuild = async (projectCwd, buildModules, overrideEvolveOptions = {}, configLoaderOptions) => {
|
13
|
-
const command = {
|
14
|
-
projectCwd,
|
15
|
-
command: 'build',
|
16
|
-
resolve: requireResolve,
|
17
|
-
};
|
18
|
-
// Try to load evolve configuration from `flatjs-evolve.config.ts`
|
19
|
-
const newEvolveOptions = await loadEvolveConfig(command, projectCwd, overrideEvolveOptions, configLoaderOptions);
|
20
|
-
await envVerify(projectCwd, newEvolveOptions);
|
21
|
-
const buildEntries = filterActivedEntriesByModule(newEvolveOptions.entryMap, buildModules);
|
22
|
-
// Make sure that each entry option includes the groupName
|
23
|
-
const normalizedBuildOneEntry = normalizeEvolveEntryMap(buildEntries, newEvolveOptions.entryMap);
|
24
|
-
const entryMapGroupList = splitToEntryGroup(normalizedBuildOneEntry, newEvolveOptions, ignoreEntryOptionKeys, false);
|
25
|
-
if (!entryMapGroupList.length) {
|
26
|
-
logger.warn(`No build entries provided!`);
|
27
|
-
return [];
|
28
|
-
}
|
29
|
-
const buildEntryGroupNames = entryMapGroupList.map((group) => {
|
30
|
-
return Object.values(group)?.[0]?.groupName;
|
31
|
-
});
|
32
|
-
const { threads = {} } = newEvolveOptions;
|
33
|
-
const maxThreads = getMaxProcessTasks(entryMapGroupList.length, threads?.maxThreads);
|
34
|
-
logger.info(`Start standard build with (${chalk(['magenta'])(String(maxThreads))}) workers:\n${JSON.stringify({ buildEntriesGroup: buildEntryGroupNames }, null, 2)}`);
|
35
|
-
const worker = createThreadWorker({ ...threads, maxThreads });
|
36
|
-
const buildTasks = new Listr([], {
|
37
|
-
concurrent: maxThreads,
|
38
|
-
exitOnError: true,
|
39
|
-
});
|
40
|
-
const buildResults = [];
|
41
|
-
for (const entryMapGroupItem of entryMapGroupList) {
|
42
|
-
const groupName = Object.values(entryMapGroupItem)?.[0]?.groupName || '';
|
43
|
-
const entryKeys = Object.keys(entryMapGroupItem);
|
44
|
-
buildTasks.add({
|
45
|
-
title: `Build group ${groupName}: ${chalk(['magenta'])(`${JSON.stringify(entryKeys, null, 2)}`)} ...`,
|
46
|
-
task: async () => {
|
47
|
-
const buildResult = await worker.startBuildWorker({
|
48
|
-
projectCwd: projectCwd,
|
49
|
-
entryKeys: entryKeys,
|
50
|
-
serializedEvolveOptions: jsonSerializer.stringify(overrideEvolveOptions),
|
51
|
-
configLoaderOptions: configLoaderOptions,
|
52
|
-
});
|
53
|
-
buildResults.push(buildResult);
|
54
|
-
},
|
55
|
-
});
|
56
|
-
}
|
57
|
-
if (buildTasks.tasks.length) {
|
58
|
-
try {
|
59
|
-
await buildTasks.run();
|
60
|
-
}
|
61
|
-
catch (err) {
|
62
|
-
worker.terminate();
|
63
|
-
// we need to catch the error here, make sure the `worker` can be terminated.
|
64
|
-
throw err;
|
65
|
-
}
|
66
|
-
}
|
67
|
-
worker.terminate();
|
68
|
-
return buildResults;
|
69
|
-
};
|
1
|
+
import Listr from"listr";import{chalk,logger,requireResolve}from"@flatjs/common";import{createGlobalCompiler}from"../compiler/create-global-compiler.js";import{ignoreEntryOptionKeys}from"../constants.js";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{getMaxProcessTasks}from"../helpers/get-max-process-tasks.js";import{jsonSerializer}from"../helpers/json-serializer.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{createThreadWorker}from"./create-thread-worker.js";import{envVerify}from"./env-verify.js";export const startBuild=async(r,e,t={},o)=>{const i={projectCwd:r,command:"build",resolve:requireResolve},s=await loadEvolveConfig(i,r,t,o);await envVerify(r,s);const a=filterActivedEntriesByModule(s.entryMap,e),n=normalizeEvolveEntryMap(a,s.entryMap),l=splitToEntryGroup(n,s,ignoreEntryOptionKeys,!1);if(!l.length)return logger.warn("No build entries provided!"),[];const p=l.map((r=>Object.values(r)?.[0]?.groupName));await createGlobalCompiler(!1,s);const{threads:m={}}=s,c=getMaxProcessTasks(l.length,m?.maxThreads);logger.info(`Start standard build with (${chalk(["magenta"])(String(c))}) workers:\n${JSON.stringify({buildEntriesGroup:p},null,2)}`);const d=createThreadWorker({...m,maxThreads:c}),f=new Listr([],{concurrent:c,exitOnError:!0}),g=[];for(const e of l){const i=Object.values(e)?.[0]?.groupName||"",s=Object.keys(e);f.add({title:`Build group ${i}: ${chalk(["magenta"])(`${JSON.stringify(s,null,2)}`)} ...`,task:async()=>{const e=await d.startBuildWorker({projectCwd:r,entryKeys:s,serializedEvolveOptions:jsonSerializer.stringify(t),configLoaderOptions:o});g.push(e)}})}if(f.tasks.length)try{await f.run()}catch(r){throw d.terminate(),r}return d.terminate(),g};
|
@@ -1,32 +1 @@
|
|
1
|
-
import webpack from
|
2
|
-
import { loadWebpackConfig } from '../create-webpack/load-webpack-config.js';
|
3
|
-
import { assertSingleCompiler } from '../helpers/assert-single-compiler.js';
|
4
|
-
/**
|
5
|
-
* Starts the build process for a group of entry files.
|
6
|
-
*
|
7
|
-
* @param groupBuildEntry - The map of entry files to be built.
|
8
|
-
* @param evolveOptions - The options for the build process.
|
9
|
-
* @returns A promise that resolves to the build result.
|
10
|
-
*/
|
11
|
-
export const startGroupEntryBuild = async (groupBuildEntry, evolveOptions) => {
|
12
|
-
// Try to load webpack configuration
|
13
|
-
const webpackConfig = await loadWebpackConfig('production', groupBuildEntry, evolveOptions);
|
14
|
-
const currCompiler = assertSingleCompiler(groupBuildEntry, webpackConfig, evolveOptions, false);
|
15
|
-
// Run the single build.
|
16
|
-
return new Promise((resolve, reject) => {
|
17
|
-
webpack(currCompiler, (err, stats) => {
|
18
|
-
if (err) {
|
19
|
-
// Handle errors here
|
20
|
-
return reject(err);
|
21
|
-
}
|
22
|
-
const statsJson = stats?.toJson();
|
23
|
-
if (statsJson?.errors?.length) {
|
24
|
-
return reject(statsJson.errors);
|
25
|
-
}
|
26
|
-
if (evolveOptions.rejectWarnings && statsJson?.warnings?.length) {
|
27
|
-
return reject(statsJson.warnings);
|
28
|
-
}
|
29
|
-
resolve({ name: currCompiler.name, warningStats: statsJson?.warnings });
|
30
|
-
});
|
31
|
-
});
|
32
|
-
};
|
1
|
+
import webpack from"webpack";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{assertSingleCompiler}from"../helpers/assert-single-compiler.js";import{normalizeEvolveEntryName}from"../helpers/normalize-entry-map.js";export const startGroupEntryBuild=async(r,e)=>{const n=await loadWebpackConfig("production",r,e),o=assertSingleCompiler(r,n,e,!1);return new Promise(((n,t)=>{webpack(o,((o,a)=>{if(o)return t(o);const i=a?.toJson();if(i?.errors?.length)return t(i.errors);if(e.rejectWarnings&&i?.warnings?.length)return t(i.warnings);const{projectVirtualPath:s}=e,p=Object.keys(r).map((r=>normalizeEvolveEntryName(r,s)));n({name:p,warningStats:i?.warnings})}))}))};
|
package/dist/main/start-serve.js
CHANGED
@@ -1,34 +1 @@
|
|
1
|
-
import
|
2
|
-
import { filterActivedEntriesByModule } from '../helpers/filter-actived-entries.js';
|
3
|
-
import { normalizeEvolveEntryMap } from '../helpers/normalize-entry-map.js';
|
4
|
-
import { loadEvolveConfig } from '../load-config/load-evolve-config.js';
|
5
|
-
import { prepareServe } from './prepare-serve.js';
|
6
|
-
/**
|
7
|
-
* The main entry to start evolve serve
|
8
|
-
* @param projectCwd The Root directory (workspace) of this project.
|
9
|
-
* @param serveModules The filter pattern to detect modules we want to serve.
|
10
|
-
* @param overrideEvolveOptions The overrided evolve options
|
11
|
-
* @param configLoaderOptions Evolve config loader options
|
12
|
-
*/
|
13
|
-
export const startServe = async (projectCwd, serveModules, overrideEvolveOptions = {}, configLoaderOptions) => {
|
14
|
-
const command = {
|
15
|
-
projectCwd,
|
16
|
-
command: 'serve',
|
17
|
-
resolve: requireResolve,
|
18
|
-
};
|
19
|
-
// Try to load evolve configuration from `flatjs-evolve.config.ts`
|
20
|
-
const evolveOptions = await loadEvolveConfig(command, projectCwd, overrideEvolveOptions, configLoaderOptions);
|
21
|
-
const servedEntries = filterActivedEntriesByModule(evolveOptions.entryMap, serveModules);
|
22
|
-
const servedEntryKeys = Object.keys(servedEntries);
|
23
|
-
// Make sure that we have at least one serve entry module.
|
24
|
-
if (!servedEntryKeys.length) {
|
25
|
-
logger.warn(`No served entries providered!`);
|
26
|
-
return [];
|
27
|
-
}
|
28
|
-
logger.info({
|
29
|
-
servedEntries: servedEntryKeys,
|
30
|
-
});
|
31
|
-
// Normalized served entries to make sure we have latested entry options.
|
32
|
-
const normalizedServedEntries = normalizeEvolveEntryMap(servedEntries, evolveOptions.entryMap);
|
33
|
-
return prepareServe(projectCwd, normalizedServedEntries, evolveOptions);
|
34
|
-
};
|
1
|
+
import{logger,requireResolve}from"@flatjs/common";import{createGlobalCompiler}from"../compiler/create-global-compiler.js";import{filterActivedEntriesByModule}from"../helpers/filter-actived-entries.js";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareServe}from"./prepare-serve.js";export const startServe=async(e,r,o={},t)=>{const l={projectCwd:e,command:"serve",resolve:requireResolve},i=await loadEvolveConfig(l,e,o,t),a=filterActivedEntriesByModule(i.entryMap,r),n=Object.keys(a);if(!n.length)return logger.warn("No served entries providered!"),[];logger.info({servedEntries:n});const p=normalizeEvolveEntryMap(a,i.entryMap);return await createGlobalCompiler(!0,i),prepareServe(e,p,i)};
|
@@ -1,19 +1 @@
|
|
1
|
-
import
|
2
|
-
import { loadEvolveConfig } from '../load-config/load-evolve-config.js';
|
3
|
-
import { prepareStatic } from './prepare-static.js';
|
4
|
-
/**
|
5
|
-
* The main entry to start evolve static server to proxy all modules of `production` build
|
6
|
-
* @param projectCwd The Root directory (workspace) of this project.
|
7
|
-
* @param overrideEvolveOptions The overrided evolve options
|
8
|
-
* @param configLoaderOptions Evolve config loader options
|
9
|
-
*/
|
10
|
-
export const startStatic = async (projectCwd, overrideEvolveOptions = {}, configLoaderOptions) => {
|
11
|
-
const command = {
|
12
|
-
projectCwd,
|
13
|
-
command: 'static',
|
14
|
-
resolve: requireResolve,
|
15
|
-
};
|
16
|
-
// Try to load evolve configuration from `flatjs-evolve.config.ts`
|
17
|
-
const evolveOptions = await loadEvolveConfig(command, projectCwd, overrideEvolveOptions, configLoaderOptions);
|
18
|
-
return prepareStatic(projectCwd, evolveOptions);
|
19
|
-
};
|
1
|
+
import{requireResolve}from"@flatjs/common";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareStatic}from"./prepare-static.js";export const startStatic=async(o,e={},r)=>{const t={projectCwd:o,command:"static",resolve:requireResolve},a=await loadEvolveConfig(t,o,e,r);return prepareStatic(o,a)};
|
@@ -1,25 +1 @@
|
|
1
|
-
import
|
2
|
-
import { moduleName } from '../constants.js';
|
3
|
-
import { printInfo } from '../helpers/print-log.js';
|
4
|
-
import { imageMinimizer } from './image-minimizer.js';
|
5
|
-
import { terserMinimizer } from './terser-minimizer.js';
|
6
|
-
export const createMinimizers = (serveMode, webpackOptions) => {
|
7
|
-
const minimizers = [];
|
8
|
-
if (serveMode) {
|
9
|
-
logger.debug('Ignore minimizer plugin for `serve` mode', moduleName);
|
10
|
-
return minimizers;
|
11
|
-
}
|
12
|
-
if (webpackOptions?.minimizer === false) {
|
13
|
-
printInfo('Note `minimizer` has been disabled for now');
|
14
|
-
return minimizers;
|
15
|
-
}
|
16
|
-
if (webpackOptions?.minimizer?.imageMin) {
|
17
|
-
const imageMinPlugin = imageMinimizer();
|
18
|
-
if (imageMinPlugin) {
|
19
|
-
minimizers.push(imageMinPlugin);
|
20
|
-
}
|
21
|
-
}
|
22
|
-
const terserPlugin = terserMinimizer(webpackOptions?.minimizer?.terserOptions || {});
|
23
|
-
minimizers.push(terserPlugin);
|
24
|
-
return minimizers;
|
25
|
-
};
|
1
|
+
import{logger}from"@flatjs/common";import{moduleName}from"../constants.js";import{printInfo}from"../helpers/print-log.js";import{imageMinimizer}from"./image-minimizer.js";import{terserMinimizer}from"./terser-minimizer.js";export const createMinimizers=(i,r)=>{const e=[];if(i)return logger.debug("Ignore minimizer plugin for `serve` mode",moduleName),e;if(!1===r?.minimizer)return printInfo("Note `minimizer` has been disabled for now"),e;if(r?.minimizer?.imageMin){const i=imageMinimizer();i&&e.push(i)}const m=terserMinimizer(r?.minimizer?.terserOptions||{});return e.push(m),e};
|
@@ -1,14 +1 @@
|
|
1
|
-
export const defaultTerserOptions
|
2
|
-
ecma: undefined,
|
3
|
-
parse: {},
|
4
|
-
compress: {},
|
5
|
-
// Note `mangle.properties` is `false` by default.
|
6
|
-
mangle: true,
|
7
|
-
module: false,
|
8
|
-
output: undefined,
|
9
|
-
toplevel: false,
|
10
|
-
ie8: false,
|
11
|
-
keep_classnames: undefined,
|
12
|
-
keep_fnames: false,
|
13
|
-
safari10: false,
|
14
|
-
};
|
1
|
+
export const defaultTerserOptions={ecma:void 0,parse:{},compress:{},mangle:!0,module:!1,output:void 0,toplevel:!1,ie8:!1,keep_classnames:void 0,keep_fnames:!1,safari10:!1};
|
@@ -1,65 +1 @@
|
|
1
|
-
import {
|
2
|
-
import { chalk, logger, requireResolve } from '@flatjs/common';
|
3
|
-
import ImageMinimizerPlugin from 'image-minimizer-webpack-plugin';
|
4
|
-
import { moduleName } from '../constants.js';
|
5
|
-
const logs = new Map();
|
6
|
-
/**
|
7
|
-
* Install libpng library & gifsicle tool
|
8
|
-
* macos
|
9
|
-
* =====================
|
10
|
-
* brew install libpng
|
11
|
-
* brew install gifsicle
|
12
|
-
*
|
13
|
-
* centos
|
14
|
-
* =====================
|
15
|
-
* sudo yum install libpng
|
16
|
-
* sudo yum install epel-release
|
17
|
-
* sudo yum install gifsicle
|
18
|
-
* @returns
|
19
|
-
*/
|
20
|
-
export const imageMinimizer = () => {
|
21
|
-
const suggestedPlugins = [
|
22
|
-
// Svgo configuration here https://github.com/svg/svgo#configuration
|
23
|
-
['svgo', {}],
|
24
|
-
['gifsicle', {}],
|
25
|
-
['jpegtran', {}],
|
26
|
-
['pngquant', {}],
|
27
|
-
];
|
28
|
-
const logMessage = [];
|
29
|
-
const availabledPlugins = suggestedPlugins
|
30
|
-
.map((item) => {
|
31
|
-
const moduleId = item[0];
|
32
|
-
try {
|
33
|
-
requireResolve(import.meta.url, `imagemin-${moduleId}`);
|
34
|
-
return item;
|
35
|
-
}
|
36
|
-
catch (err) {
|
37
|
-
if (!logs.get(moduleId)) {
|
38
|
-
logs.set(moduleId, true);
|
39
|
-
const command = chalk(['magenta'])(`"${projectHasYarn() ? 'yarn add' : 'npm install'} imagemin-${moduleId} -D"`);
|
40
|
-
logMessage.push(`Execute ${command} for assets optimization`);
|
41
|
-
}
|
42
|
-
return null;
|
43
|
-
}
|
44
|
-
})
|
45
|
-
.filter(Boolean);
|
46
|
-
if (logMessage.length) {
|
47
|
-
for (const msg of logMessage) {
|
48
|
-
logger.warn(msg, moduleName);
|
49
|
-
}
|
50
|
-
}
|
51
|
-
if (availabledPlugins.length) {
|
52
|
-
return new ImageMinimizerPlugin({
|
53
|
-
minimizer: {
|
54
|
-
// Recommended squoosh options for lossless optimization
|
55
|
-
implementation: ImageMinimizerPlugin.imageminMinify,
|
56
|
-
options: {
|
57
|
-
// Lossless optimization with custom option
|
58
|
-
// Feel free to experiment with options for better result for you
|
59
|
-
plugins: availabledPlugins,
|
60
|
-
},
|
61
|
-
},
|
62
|
-
});
|
63
|
-
}
|
64
|
-
return null;
|
65
|
-
};
|
1
|
+
import ImageMinimizerPlugin from"image-minimizer-webpack-plugin";import{projectHasYarn}from"@armit/package";import{chalk,logger,requireResolve}from"@flatjs/common";import{moduleName}from"../constants.js";const logs=new Map;export const imageMinimizer=()=>{const e=[],i=[["svgo",{}],["gifsicle",{}],["jpegtran",{}],["pngquant",{}]].map((i=>{const n=i[0];try{return requireResolve(import.meta.url,`imagemin-${n}`),i}catch{if(!logs.get(n)){logs.set(n,!0);const i=chalk(["magenta"])(`"${projectHasYarn()?"yarn add":"npm install"} imagemin-${n} -D"`);e.push(`Execute ${i} for assets optimization`)}return null}})).filter(Boolean);if(e.length)for(const i of e)logger.warn(i,moduleName);return i.length?new ImageMinimizerPlugin({minimizer:{implementation:ImageMinimizerPlugin.imageminMinify,options:{plugins:i}}}):null};
|
package/dist/minimizer/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export
|
1
|
+
export*from"./create-minimizers.js";
|
@@ -1,15 +1,3 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
/**
|
5
|
-
* https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
|
6
|
-
*/
|
7
|
-
export const terserMinimizer = (terserOptions) => {
|
8
|
-
return new TerserPlugin({
|
9
|
-
parallel: true,
|
10
|
-
// Disable Extract all or some (use /^\**!|@preserve|@license|@cc_on/i RegExp) comments.
|
11
|
-
extractComments: false,
|
12
|
-
// Terser minify options.
|
13
|
-
terserOptions: mergeOptions(defaultTerserOptions, terserOptions),
|
14
|
-
});
|
15
|
-
};
|
1
|
+
import TerserPlugin from"terser-webpack-plugin";import{mergeOptions}from"@flatjs/common";import{defaultTerserOptions}from"./default-options.js";export const terserMinimizer=e=>new TerserPlugin({parallel:!0,
|
2
|
+
// Disable Extract all or some (use /^\**!|@preserve|@license|@cc_on/i RegExp) comments.
|
3
|
+
extractComments:!1,terserOptions:mergeOptions(defaultTerserOptions,e)});
|
package/dist/minimizer/types.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export
|
1
|
+
export{};
|