-
Notifications
You must be signed in to change notification settings - Fork 102
/
cypress.webpack.config.ts
148 lines (139 loc) · 4.64 KB
/
cypress.webpack.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// @ts-nocheck
import path from 'path';
import { createJoinFunction, createJoinImplementation, asGenerator, defaultJoinGenerator } from 'resolve-url-loader';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { glob } from 'glob';
import { readFileSync } from 'fs';
function importVariants(url: string) {
const parsedUrl = path.parse(url);
let variants = [url];
if (parsedUrl.dir && !parsedUrl.ext) {
const moduleName = url.split('/').pop();
variants = [`${url.replace(new RegExp(`${moduleName}$`), `_${moduleName}`)}.scss`, `${url}.scss`];
}
return variants;
}
// call default generator then pair different variations of uri with each base
const myGenerator = asGenerator((item: unknown, ...rest) => {
const defaultTuples = [...defaultJoinGenerator(item, ...rest)];
if (item.uri.includes('./assets')) {
return defaultTuples.map(([base]) => {
if (base.includes('@patternfly/patternfly')) {
return [base, path.relative(base, path.resolve(__dirname, './node_modules/@patternfly/patternfly', item.uri))];
}
});
}
return defaultTuples;
});
function localAliasHoisting() {
const localPackages = glob.sync(path.resolve(__dirname, 'packages/*')).reduce((acc, curr) => {
const pck = JSON.parse(readFileSync(path.resolve(curr, 'package.json'), 'utf-8'));
acc[pck.name] = curr + '/src';
return acc
}, {});
return localPackages;
}
const localPackages = localAliasHoisting();
export default {
devtool: 'inline-source-map',
target: 'web',
module: {
rules: [
{
test: /\.(js|ts)x?$/,
exclude: /(node_modules|dist)/,
use: {
loader: 'swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
transform: {
react: {
runtime: 'automatic',
},
},
},
},
},
},
{
test: /\.s?[ac]ss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'resolve-url-loader'
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
webpackImporter: false,
api: "modern",
sassOptions: {
includePaths: [...glob.sync(path.resolve(__dirname, './packages/*/src')), path.resolve(__dirname, './node_modules')],
importers: [{
findFileUrl(url: string) {
let variants: string[] = []
let sassPath: string;
if (url.startsWith('~@redhat-cloud-services')) {
const repoPackage = url.split('~').pop();
const segments = repoPackage.split('/');
const sourcePackage = localPackages[`${segments[0]}/${segments[1]}`];
if(sourcePackage) {
// resolve local packages to local directory
return new URL(`file://${path.resolve(sourcePackage, ...segments.slice(2))}`);
}
}
if(url.startsWith('~')) {
const localPackage = path.resolve(process.cwd(), './node_modules/', url.split('~').pop());
variants = importVariants(localPackage);
sassPath = variants.find((v) => glob.sync(v).length);
if(sassPath) {
return new URL(`file://${sassPath}`);
}
const globalPackage = path.resolve(__dirname, './node_modules/', url.split('~').pop());
variants = importVariants(globalPackage);
sassPath = variants.find((v) => glob.sync(v).length);
if(sassPath) {
return new URL(`file://${sassPath}`);
}
}
return new URL(url);
}
}]
}
},
},
],
},
{
test: /\.(jpe?g|svg|png|gif|ico|eot|ttf|woff2?)(\?v=\d+\.\d+\.\d+)?$/i,
type: 'asset/resource',
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
// make sure the runner hoists the local packages, not the build packages
...localPackages,
},
},
output: {
filename: 'bundle.js',
hashFunction: 'xxhash64',
path: path.resolve(__dirname, 'dist'),
},
stats: {
errorDetails: true,
},
plugins: [
new MiniCssExtractPlugin({
ignoreOrder: true,
}),
]
};