@genesislcap/webpack-builder 15.19.0 → 15.19.1
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/package.json +3 -4
- package/src/commands/build.ts +0 -26
- package/src/commands/dev.ts +0 -7
- package/src/commands/index.ts +0 -2
- package/src/config/devServer.ts +0 -77
- package/src/config/entry.ts +0 -24
- package/src/config/federation.ts +0 -95
- package/src/config/getConfig.ts +0 -51
- package/src/config/index.ts +0 -1
- package/src/config/module.ts +0 -22
- package/src/config/optimization.ts +0 -46
- package/src/config/output.ts +0 -35
- package/src/config/plugins.ts +0 -104
- package/src/config/resolveLoader.ts +0 -21
- package/src/config/rules/fileRules.ts +0 -26
- package/src/config/rules/scriptRules.ts +0 -14
- package/src/config/rules/styleRules.ts +0 -38
- package/src/index.ts +0 -30
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genesislcap/webpack-builder",
|
|
3
3
|
"description": "Webpack builder",
|
|
4
|
-
"version": "15.19.
|
|
4
|
+
"version": "15.19.1",
|
|
5
5
|
"license": "SEE LICENSE IN license.txt",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"lint:fix": "genx lint -l ox --fix"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@genesislcap/build-kit": "15.19.
|
|
20
|
+
"@genesislcap/build-kit": "15.19.1",
|
|
21
21
|
"@pixability-ui/federated-types": "^0.2.0",
|
|
22
22
|
"@types/webpack-env": "^1.18.4",
|
|
23
23
|
"camel-case": "^4.1.2",
|
|
@@ -55,6 +55,5 @@
|
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
|
-
}
|
|
59
|
-
"gitHead": "83695de98c2288c2e89992215cb391652f6c5eec"
|
|
58
|
+
}
|
|
60
59
|
}
|
package/src/commands/build.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import consola from 'consola';
|
|
2
|
-
import type { Compiler } from 'webpack';
|
|
3
|
-
import webpack from 'webpack';
|
|
4
|
-
|
|
5
|
-
export const build = async (compiler: Compiler) => {
|
|
6
|
-
const stats = await new Promise<webpack.Stats>((success, error) => {
|
|
7
|
-
compiler.run((err, result) => (err ? error(err) : success(result!)));
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
if (stats.hasErrors()) {
|
|
11
|
-
const error = new Error('Build error');
|
|
12
|
-
error.stack = stats.toString('errors-only');
|
|
13
|
-
consola.error(error.stack);
|
|
14
|
-
throw error;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
process.stdout.write(
|
|
18
|
-
stats.toString({
|
|
19
|
-
colors: true,
|
|
20
|
-
modules: false,
|
|
21
|
-
children: false,
|
|
22
|
-
chunks: false,
|
|
23
|
-
chunkModules: false,
|
|
24
|
-
}) + '\n\n',
|
|
25
|
-
);
|
|
26
|
-
};
|
package/src/commands/dev.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Compiler, Configuration } from 'webpack';
|
|
2
|
-
import WebpackDevServer from 'webpack-dev-server';
|
|
3
|
-
|
|
4
|
-
export const dev = async (compiler: Compiler, config: Configuration) => {
|
|
5
|
-
const server = new WebpackDevServer(config.devServer, compiler);
|
|
6
|
-
await server.start();
|
|
7
|
-
};
|
package/src/commands/index.ts
DELETED
package/src/config/devServer.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
|
-
import type { BuildContext } from '@genesislcap/build-kit';
|
|
3
|
-
import {
|
|
4
|
-
createDevProxiesArray,
|
|
5
|
-
getDevCertOptions,
|
|
6
|
-
getPort,
|
|
7
|
-
getPublicPath,
|
|
8
|
-
} from '@genesislcap/build-kit';
|
|
9
|
-
import type { Configuration } from 'webpack';
|
|
10
|
-
|
|
11
|
-
const getServer = (isHTTPS = false) => {
|
|
12
|
-
if (isHTTPS) {
|
|
13
|
-
const options = getDevCertOptions();
|
|
14
|
-
if (options) {
|
|
15
|
-
return {
|
|
16
|
-
type: 'https',
|
|
17
|
-
options,
|
|
18
|
-
};
|
|
19
|
-
} else {
|
|
20
|
-
console.warn(`Falling back to HTTP.`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
type: 'http',
|
|
26
|
-
options: {},
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const devServer = (ctx: BuildContext): Configuration['devServer'] => {
|
|
31
|
-
const {
|
|
32
|
-
cli: {
|
|
33
|
-
isDev,
|
|
34
|
-
options: { open, https },
|
|
35
|
-
},
|
|
36
|
-
dirs: { cwd },
|
|
37
|
-
env: { isCI },
|
|
38
|
-
pkg,
|
|
39
|
-
config: { webpack },
|
|
40
|
-
} = ctx;
|
|
41
|
-
|
|
42
|
-
if (!isDev) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
open: open && !isCI ? getPublicPath() : false,
|
|
48
|
-
historyApiFallback: process.env.PUBLIC_PATH
|
|
49
|
-
? {
|
|
50
|
-
rewrites: [{ from: /./, to: `${getPublicPath()}/index.html` }],
|
|
51
|
-
}
|
|
52
|
-
: true,
|
|
53
|
-
allowedHosts: 'all',
|
|
54
|
-
host: '0.0.0.0',
|
|
55
|
-
port: getPort(pkg),
|
|
56
|
-
server: getServer(https),
|
|
57
|
-
client: {
|
|
58
|
-
overlay: {
|
|
59
|
-
runtimeErrors: false,
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
proxy: createDevProxiesArray(),
|
|
63
|
-
headers: {
|
|
64
|
-
'Access-Control-Allow-Origin': '*',
|
|
65
|
-
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
66
|
-
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
|
|
67
|
-
},
|
|
68
|
-
static: [
|
|
69
|
-
{
|
|
70
|
-
directory: resolve(cwd, './public'),
|
|
71
|
-
publicPath: getPublicPath(),
|
|
72
|
-
watch: true,
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
devMiddleware: webpack?.writeToDisk ? { writeToDisk: true } : undefined,
|
|
76
|
-
};
|
|
77
|
-
};
|
package/src/config/entry.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
|
-
import type { BuildContext } from '@genesislcap/build-kit';
|
|
3
|
-
import type { Configuration } from 'webpack';
|
|
4
|
-
import { resolveFederatedIndex, federatedIndexExists } from './federation';
|
|
5
|
-
|
|
6
|
-
export const entry = (ctx: BuildContext): Configuration['entry'] => {
|
|
7
|
-
const {
|
|
8
|
-
dirs: { cwd },
|
|
9
|
-
config: { serviceWorker },
|
|
10
|
-
} = ctx;
|
|
11
|
-
|
|
12
|
-
const main = federatedIndexExists()
|
|
13
|
-
? resolveFederatedIndex()
|
|
14
|
-
: resolve(cwd, './src/' + 'index.ts');
|
|
15
|
-
|
|
16
|
-
if (serviceWorker?.registration) {
|
|
17
|
-
return {
|
|
18
|
-
main,
|
|
19
|
-
swRegistration: resolve(cwd, './src/' + serviceWorker.registration),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return main;
|
|
24
|
-
};
|
package/src/config/federation.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
-
import { getPublicPath } from '@genesislcap/build-kit';
|
|
4
|
-
import { camelCase } from 'camel-case';
|
|
5
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
6
|
-
import { PackageJson } from 'pkg-types';
|
|
7
|
-
import { container } from 'webpack';
|
|
8
|
-
|
|
9
|
-
const { ModuleFederationPlugin } = container;
|
|
10
|
-
type ModuleFederationPluginOptions = ConstructorParameters<
|
|
11
|
-
typeof container.ModuleFederationPlugin
|
|
12
|
-
>[0]; // eslint-disable-line @typescript-eslint/no-magic-numbers
|
|
13
|
-
|
|
14
|
-
const remoteEntryFilename = 'remoteEntry.js';
|
|
15
|
-
|
|
16
|
-
export const getFederatedPkgName = (pkgName) => {
|
|
17
|
-
try {
|
|
18
|
-
return camelCase(pkgName.split('/').pop());
|
|
19
|
-
} catch (e) {
|
|
20
|
-
return pkgName;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const federatedIndex = './src/index.federated.ts';
|
|
25
|
-
|
|
26
|
-
export const resolveFederatedIndex = () => resolve(process.cwd(), federatedIndex);
|
|
27
|
-
|
|
28
|
-
export const federatedIndexExists = () => {
|
|
29
|
-
const federatedIndexPath = resolveFederatedIndex();
|
|
30
|
-
return existsSync(federatedIndexPath);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* TODO: Add prod version logic
|
|
35
|
-
*/
|
|
36
|
-
export const getRemoteEntryUrl = (port, host = 'localhost') =>
|
|
37
|
-
`http://${host}:${port}/${remoteEntryFilename}`;
|
|
38
|
-
|
|
39
|
-
export const getRemoteEntry = (name, port, host = 'localhost') =>
|
|
40
|
-
`${name}@${getRemoteEntryUrl(port, host)}`;
|
|
41
|
-
|
|
42
|
-
export const resolveFederationOptions = (
|
|
43
|
-
options: ModuleFederationPluginOptions = {},
|
|
44
|
-
pkg: PackageJson,
|
|
45
|
-
): ModuleFederationPluginOptions => {
|
|
46
|
-
const { name, exposes: mfExposes = {}, remotes: mfRemotes = {}, shared: mfShared = {} } = options;
|
|
47
|
-
|
|
48
|
-
const exposes = {
|
|
49
|
-
'./index': federatedIndex,
|
|
50
|
-
...mfExposes,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// workspace:* is a pnpm specifier — webpack can't resolve it as a module path.
|
|
54
|
-
// Convert it to { requiredVersion: false } so webpack shares the locally-resolved version.
|
|
55
|
-
const normalizedDeps: ModuleFederationPluginOptions['shared'] = Object.fromEntries(
|
|
56
|
-
Object.entries(pkg.dependencies ?? {}).map(([k, v]) => [
|
|
57
|
-
k,
|
|
58
|
-
v?.startsWith('workspace:') ? { requiredVersion: false as const } : v,
|
|
59
|
-
]),
|
|
60
|
-
);
|
|
61
|
-
const shared = {
|
|
62
|
-
...normalizedDeps,
|
|
63
|
-
...mfShared,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
name: name || getFederatedPkgName(pkg.name),
|
|
68
|
-
filename: remoteEntryFilename,
|
|
69
|
-
remotes: mfRemotes,
|
|
70
|
-
exposes,
|
|
71
|
-
shared,
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const getFederationPlugins = (
|
|
76
|
-
federatedIndexPresent: boolean,
|
|
77
|
-
rootElement: string,
|
|
78
|
-
options: ModuleFederationPluginOptions,
|
|
79
|
-
pkg: PackageJson,
|
|
80
|
-
) =>
|
|
81
|
-
federatedIndexPresent
|
|
82
|
-
? [
|
|
83
|
-
new HtmlWebpackPlugin({
|
|
84
|
-
title: `${pkg.description} (Federated)`,
|
|
85
|
-
template: resolve(__dirname, '../../public/info.html'),
|
|
86
|
-
filename: rootElement ? 'info.html' : 'index.html',
|
|
87
|
-
inject: false,
|
|
88
|
-
// Passing arbitrary data to the template for display
|
|
89
|
-
moduleFederationDetails: JSON.stringify(options, undefined, 2),
|
|
90
|
-
minify: false,
|
|
91
|
-
base: getPublicPath(),
|
|
92
|
-
}),
|
|
93
|
-
new ModuleFederationPlugin(options),
|
|
94
|
-
]
|
|
95
|
-
: [];
|
package/src/config/getConfig.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { BuildContext } from '@genesislcap/build-kit';
|
|
2
|
-
import type { Configuration } from 'webpack';
|
|
3
|
-
import { devServer } from './devServer';
|
|
4
|
-
import { entry } from './entry';
|
|
5
|
-
import { moduleConfig } from './module';
|
|
6
|
-
import { optimization } from './optimization';
|
|
7
|
-
import { output } from './output';
|
|
8
|
-
import { plugins } from './plugins';
|
|
9
|
-
import { resolveLoader } from './resolveLoader';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param ctx Build context
|
|
14
|
-
* @returns Webpack config
|
|
15
|
-
*/
|
|
16
|
-
export const getConfig = (ctx: BuildContext): Configuration => {
|
|
17
|
-
const {
|
|
18
|
-
cli: { isDev },
|
|
19
|
-
config: { webpack },
|
|
20
|
-
resolve: { alias },
|
|
21
|
-
} = ctx;
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
entry: entry(ctx),
|
|
25
|
-
mode: isDev ? 'development' : 'production',
|
|
26
|
-
// Be aware of CSP if changing this to eval: https://github.com/symfony/webpack-encore/issues/695
|
|
27
|
-
devtool: isDev ? 'inline-source-map' : 'source-map',
|
|
28
|
-
devServer: devServer(ctx),
|
|
29
|
-
optimization: optimization(ctx),
|
|
30
|
-
plugins: plugins(ctx),
|
|
31
|
-
output: output(ctx),
|
|
32
|
-
resolve: {
|
|
33
|
-
extensions: ['.tsx', '.ts', '.js'],
|
|
34
|
-
modules: ['node_modules'],
|
|
35
|
-
alias,
|
|
36
|
-
},
|
|
37
|
-
resolveLoader: resolveLoader(ctx),
|
|
38
|
-
module: moduleConfig(ctx),
|
|
39
|
-
experiments: {
|
|
40
|
-
topLevelAwait: true,
|
|
41
|
-
lazyCompilation: false,
|
|
42
|
-
},
|
|
43
|
-
performance: {
|
|
44
|
-
hints: false,
|
|
45
|
-
maxEntrypointSize: 512000,
|
|
46
|
-
maxAssetSize: 512000,
|
|
47
|
-
},
|
|
48
|
-
target: webpack?.target,
|
|
49
|
-
node: webpack?.node as Configuration['node'],
|
|
50
|
-
};
|
|
51
|
-
};
|
package/src/config/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getConfig';
|
package/src/config/module.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { BuildContext } from '@genesislcap/build-kit';
|
|
2
|
-
import type { Configuration } from 'webpack';
|
|
3
|
-
import { appFileRules } from './rules/fileRules';
|
|
4
|
-
import { appScriptRules } from './rules/scriptRules';
|
|
5
|
-
import { appStyleRules } from './rules/styleRules';
|
|
6
|
-
|
|
7
|
-
// module is reserved keyword in CommonJS
|
|
8
|
-
export const moduleConfig = (ctx: BuildContext): Configuration['module'] => ({
|
|
9
|
-
rules: [
|
|
10
|
-
appScriptRules.typescript(),
|
|
11
|
-
|
|
12
|
-
// Files
|
|
13
|
-
appFileRules.fonts(),
|
|
14
|
-
appFileRules.html(),
|
|
15
|
-
appFileRules.images(),
|
|
16
|
-
appFileRules.videos(),
|
|
17
|
-
|
|
18
|
-
// Styles
|
|
19
|
-
appStyleRules.headCss(),
|
|
20
|
-
appStyleRules.css(),
|
|
21
|
-
],
|
|
22
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { BuildContext } from '@genesislcap/build-kit';
|
|
2
|
-
import TerserPlugin from 'terser-webpack-plugin';
|
|
3
|
-
import type { Configuration } from 'webpack';
|
|
4
|
-
|
|
5
|
-
const vendorCacheGroup = {
|
|
6
|
-
vendor: {
|
|
7
|
-
test: /[\\/]node_modules[\\/]/,
|
|
8
|
-
name: (module) => {
|
|
9
|
-
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
|
|
10
|
-
// npm package names are URL-safe, but some servers don't like @ symbols
|
|
11
|
-
return `npm.${packageName.replace('@', '')}`;
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const optimization = (ctx: BuildContext): Configuration['optimization'] => {
|
|
17
|
-
const {
|
|
18
|
-
config: { webpack },
|
|
19
|
-
cli: { isDev },
|
|
20
|
-
} = ctx;
|
|
21
|
-
|
|
22
|
-
// user-supplied custom config
|
|
23
|
-
if (typeof webpack?.optimization === 'function') {
|
|
24
|
-
return webpack.optimization({ isDev });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// defaults
|
|
28
|
-
return isDev
|
|
29
|
-
? {
|
|
30
|
-
usedExports: false,
|
|
31
|
-
minimize: false,
|
|
32
|
-
runtimeChunk: 'single',
|
|
33
|
-
}
|
|
34
|
-
: {
|
|
35
|
-
usedExports: true,
|
|
36
|
-
minimize: true,
|
|
37
|
-
minimizer: [new TerserPlugin()],
|
|
38
|
-
splitChunks: {
|
|
39
|
-
chunks: 'all',
|
|
40
|
-
maxInitialRequests: 100,
|
|
41
|
-
cacheGroups: {
|
|
42
|
-
...vendorCacheGroup,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
};
|
package/src/config/output.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
|
-
import type { BuildContext, WebpackFilenames } from '@genesislcap/build-kit';
|
|
3
|
-
import { getPublicPath } from '@genesislcap/build-kit';
|
|
4
|
-
import type { Configuration } from 'webpack';
|
|
5
|
-
|
|
6
|
-
const defaultGetters: WebpackFilenames = {
|
|
7
|
-
file: ({ isDev }) => (isDev ? '[name].js' : '[name].[contenthash].js'),
|
|
8
|
-
chunk: ({ isDev }) => (isDev ? '[name].[id].js' : '[name].[id].[contenthash].js'),
|
|
9
|
-
sourceMap: ({ isDev }) => (isDev ? '[name].js.map' : '[name].[contenthash].js.map'),
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const filenameGetters = (config: WebpackFilenames = {}): WebpackFilenames => ({
|
|
13
|
-
file: config.file || defaultGetters.file,
|
|
14
|
-
chunk: config.chunk || defaultGetters.chunk,
|
|
15
|
-
sourceMap: config.sourceMap || defaultGetters.sourceMap,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export const output = (ctx: BuildContext): Configuration['output'] => {
|
|
19
|
-
const {
|
|
20
|
-
cli: { isDev },
|
|
21
|
-
dirs: { cwd },
|
|
22
|
-
config: { webpack },
|
|
23
|
-
} = ctx;
|
|
24
|
-
|
|
25
|
-
const getters = filenameGetters(webpack?.filenames);
|
|
26
|
-
return {
|
|
27
|
-
strictModuleErrorHandling: true,
|
|
28
|
-
strictModuleExceptionHandling: true,
|
|
29
|
-
path: resolve(cwd, './dist'),
|
|
30
|
-
publicPath: getPublicPath(),
|
|
31
|
-
filename: getters.file({ isDev }),
|
|
32
|
-
chunkFilename: getters.chunk({ isDev }),
|
|
33
|
-
sourceMapFilename: getters.sourceMap({ isDev }),
|
|
34
|
-
};
|
|
35
|
-
};
|
package/src/config/plugins.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { resolve, join } from 'node:path';
|
|
3
|
-
import type { BuildContext } from '@genesislcap/build-kit';
|
|
4
|
-
import { getPublicPath, objToSnakeCase, resolveDefineConfig } from '@genesislcap/build-kit';
|
|
5
|
-
import CircularDependencyPlugin from 'circular-dependency-plugin';
|
|
6
|
-
import CopyPlugin from 'copy-webpack-plugin';
|
|
7
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
8
|
-
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
9
|
-
import type { Configuration } from 'webpack';
|
|
10
|
-
import { DefinePlugin } from 'webpack';
|
|
11
|
-
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
|
12
|
-
import WebpackPwaManifest from 'webpack-pwa-manifest';
|
|
13
|
-
import WebpackBar from 'webpackbar';
|
|
14
|
-
import { InjectManifest } from 'workbox-webpack-plugin';
|
|
15
|
-
import { getFederationPlugins, federatedIndexExists, resolveFederationOptions } from './federation';
|
|
16
|
-
|
|
17
|
-
const getTemplate = (cwd) => {
|
|
18
|
-
const templateApp = resolve(cwd, 'index.html');
|
|
19
|
-
const template = existsSync(templateApp)
|
|
20
|
-
? templateApp
|
|
21
|
-
: resolve(__dirname, '../public/index.html');
|
|
22
|
-
console.log(`Using index template: ${template}`);
|
|
23
|
-
return `!!handlebars-loader!${template}`;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const plugins = (ctx: BuildContext): Configuration['plugins'] => {
|
|
27
|
-
const {
|
|
28
|
-
cli: { isAnalyze },
|
|
29
|
-
dirs: { cwd },
|
|
30
|
-
config: {
|
|
31
|
-
serviceWorker,
|
|
32
|
-
pwa,
|
|
33
|
-
federation,
|
|
34
|
-
app: { rootElement },
|
|
35
|
-
http,
|
|
36
|
-
env,
|
|
37
|
-
},
|
|
38
|
-
pkg,
|
|
39
|
-
} = ctx;
|
|
40
|
-
|
|
41
|
-
const federatedIndexPresent = federatedIndexExists();
|
|
42
|
-
const moduleFederationOptions = resolveFederationOptions(federation, pkg);
|
|
43
|
-
const define = resolveDefineConfig(env, http, 'webpack');
|
|
44
|
-
const appPublic = resolve(cwd, 'public');
|
|
45
|
-
|
|
46
|
-
return [
|
|
47
|
-
existsSync(appPublic) &&
|
|
48
|
-
new CopyPlugin({
|
|
49
|
-
patterns: [
|
|
50
|
-
{
|
|
51
|
-
from: appPublic,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
}),
|
|
55
|
-
new DefinePlugin(define),
|
|
56
|
-
new CircularDependencyPlugin({
|
|
57
|
-
// exclude detection of files based on a RegExp
|
|
58
|
-
exclude: /a\.js|node_modules/,
|
|
59
|
-
// add errors to webpack instead of warnings
|
|
60
|
-
failOnError: false, // TODO: set back to true after resolving detected issues
|
|
61
|
-
// allow import cycles that include an asyncronous import,
|
|
62
|
-
// e.g. via import(/* webpackMode: "weak" */ './file.js')
|
|
63
|
-
allowAsyncCycles: false,
|
|
64
|
-
// set the current working directory for displaying module paths
|
|
65
|
-
cwd: process.cwd(),
|
|
66
|
-
}),
|
|
67
|
-
new WebpackBar(),
|
|
68
|
-
new MiniCssExtractPlugin(),
|
|
69
|
-
(rootElement || !federatedIndexPresent) &&
|
|
70
|
-
new HtmlWebpackPlugin({
|
|
71
|
-
title: `${pkg.description}`,
|
|
72
|
-
template: getTemplate(cwd),
|
|
73
|
-
customElementTagName: rootElement,
|
|
74
|
-
minify: false,
|
|
75
|
-
base: getPublicPath(),
|
|
76
|
-
}),
|
|
77
|
-
...getFederationPlugins(federatedIndexPresent, rootElement, moduleFederationOptions, pkg),
|
|
78
|
-
isAnalyze &&
|
|
79
|
-
new BundleAnalyzerPlugin({
|
|
80
|
-
reportTitle: `Webpack Visualizer`,
|
|
81
|
-
reportFilename: join(cwd, './dist', 'webpack.stats.html'),
|
|
82
|
-
analyzerMode: 'static',
|
|
83
|
-
openAnalyzer: false,
|
|
84
|
-
}),
|
|
85
|
-
pwa &&
|
|
86
|
-
new WebpackPwaManifest({
|
|
87
|
-
...objToSnakeCase(pwa),
|
|
88
|
-
name: pwa.name,
|
|
89
|
-
icons:
|
|
90
|
-
Array.isArray(pwa.icons) &&
|
|
91
|
-
pwa.icons.map((icon) => ({
|
|
92
|
-
sizes: icon.sizes,
|
|
93
|
-
src: resolve(cwd, icon.src),
|
|
94
|
-
})),
|
|
95
|
-
}),
|
|
96
|
-
serviceWorker &&
|
|
97
|
-
new InjectManifest({
|
|
98
|
-
swSrc: './src/' + serviceWorker.worker,
|
|
99
|
-
swDest: serviceWorker.assetName,
|
|
100
|
-
exclude: serviceWorker.exclude,
|
|
101
|
-
maximumFileSizeToCacheInBytes: serviceWorker.maximumFileSizeToCache,
|
|
102
|
-
}),
|
|
103
|
-
].filter(Boolean);
|
|
104
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
|
-
import type { BuildContext } from '@genesislcap/build-kit';
|
|
3
|
-
import type { Configuration } from 'webpack';
|
|
4
|
-
|
|
5
|
-
export const resolveLoader = (ctx: BuildContext): Configuration['resolveLoader'] => {
|
|
6
|
-
const {
|
|
7
|
-
dirs: { cwd, workspace },
|
|
8
|
-
} = ctx;
|
|
9
|
-
return {
|
|
10
|
-
modules: [
|
|
11
|
-
// webpack-builder node_modules
|
|
12
|
-
resolve(__dirname, '../../node_modules'),
|
|
13
|
-
// workspace folder node_modules (if set)
|
|
14
|
-
workspace ? resolve(workspace, 'node_modules') : '',
|
|
15
|
-
// package node_modules
|
|
16
|
-
resolve(cwd, 'node_modules'),
|
|
17
|
-
// root workspace node_modules (for hoisted dependencies like handlebars-loader)
|
|
18
|
-
resolve(cwd, '../../../node_modules'),
|
|
19
|
-
].filter(Boolean),
|
|
20
|
-
};
|
|
21
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/* eslint prefer-named-capture-group: "off" */
|
|
2
|
-
// In this config named capturing isn't desired.
|
|
3
|
-
// May cause adverse affects with webpack.
|
|
4
|
-
|
|
5
|
-
export const appFileRules = {
|
|
6
|
-
fonts: () => ({
|
|
7
|
-
test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
|
8
|
-
type: 'asset/resource',
|
|
9
|
-
}),
|
|
10
|
-
html: () => ({
|
|
11
|
-
test: /\.html$/,
|
|
12
|
-
use: [
|
|
13
|
-
{
|
|
14
|
-
loader: 'html-loader',
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
}),
|
|
18
|
-
images: () => ({
|
|
19
|
-
test: /\.(png|svg|jpg|jpeg|gif)$/i,
|
|
20
|
-
type: 'asset/resource',
|
|
21
|
-
}),
|
|
22
|
-
videos: () => ({
|
|
23
|
-
test: /\.(mp4|ogg|webm)$/i,
|
|
24
|
-
type: 'asset/resource',
|
|
25
|
-
}),
|
|
26
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const cssLoader = (importLoaders = 1, useHash = true) => ({
|
|
2
|
-
loader: 'css-loader',
|
|
3
|
-
options: {
|
|
4
|
-
importLoaders,
|
|
5
|
-
},
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
const postCSSLoader = () => ({
|
|
9
|
-
loader: 'postcss-loader',
|
|
10
|
-
options: {
|
|
11
|
-
postcssOptions: {
|
|
12
|
-
plugins: [
|
|
13
|
-
'postcss-import',
|
|
14
|
-
[
|
|
15
|
-
'postcss-preset-env',
|
|
16
|
-
{
|
|
17
|
-
browsers: 'last 2 versions',
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const headCssPatterns = [/main\.css$/i, /head\.css$/i, /index\.css$/i];
|
|
26
|
-
|
|
27
|
-
export const appStyleRules = {
|
|
28
|
-
headCss: () => ({
|
|
29
|
-
test: /\.css$/i,
|
|
30
|
-
include: headCssPatterns,
|
|
31
|
-
use: ['style-loader', cssLoader(), postCSSLoader()],
|
|
32
|
-
}),
|
|
33
|
-
css: (useHash = true) => ({
|
|
34
|
-
test: /\.css$/i,
|
|
35
|
-
exclude: [...headCssPatterns],
|
|
36
|
-
use: [cssLoader(), postCSSLoader()],
|
|
37
|
-
}),
|
|
38
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { BuildContext } from '@genesislcap/build-kit';
|
|
2
|
-
import { run, resolveBin } from '@genesislcap/build-kit';
|
|
3
|
-
import webpack from 'webpack';
|
|
4
|
-
import { build, dev } from './commands';
|
|
5
|
-
import { getConfig } from './config';
|
|
6
|
-
|
|
7
|
-
export default async (ctx: BuildContext) => {
|
|
8
|
-
const {
|
|
9
|
-
dirs: { cwd },
|
|
10
|
-
cli: { isDev, isAnalyze, isBuild, options },
|
|
11
|
-
enable: { mft },
|
|
12
|
-
} = ctx;
|
|
13
|
-
|
|
14
|
-
if (mft) {
|
|
15
|
-
const mftCLI = await resolveBin('make-federated-types', '@pixability-ui/federated-types');
|
|
16
|
-
run(cwd, `${mftCLI}`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (isDev) {
|
|
20
|
-
const config = getConfig(ctx);
|
|
21
|
-
const compiler = webpack(config);
|
|
22
|
-
dev(compiler, config);
|
|
23
|
-
} else if (isBuild || isAnalyze) {
|
|
24
|
-
const config = getConfig(ctx);
|
|
25
|
-
const compiler = webpack(config);
|
|
26
|
-
await build(compiler);
|
|
27
|
-
} else {
|
|
28
|
-
throw new Error(`Unrecognized command: ${JSON.stringify(options)}`);
|
|
29
|
-
}
|
|
30
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declarationDir": "./dist",
|
|
5
|
-
"lib": ["ES2015", "ES2016", "ES2017", "ES2019"],
|
|
6
|
-
"module": "commonjs",
|
|
7
|
-
"outDir": "./dist",
|
|
8
|
-
"rootDir": "./src",
|
|
9
|
-
"types": ["webpack-env"]
|
|
10
|
-
},
|
|
11
|
-
"include": ["src/**/*"]
|
|
12
|
-
}
|
package/tsconfig.tsbuildinfo
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["./src/index.ts","./src/commands/build.ts","./src/commands/dev.ts","./src/commands/index.ts","./src/config/devServer.ts","./src/config/entry.ts","./src/config/federation.ts","./src/config/getConfig.ts","./src/config/index.ts","./src/config/module.ts","./src/config/optimization.ts","./src/config/output.ts","./src/config/plugins.ts","./src/config/resolveLoader.ts","./src/config/rules/fileRules.ts","./src/config/rules/scriptRules.ts","./src/config/rules/styleRules.ts"],"version":"5.9.2"}
|