Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
80 lines (74 loc) · 1.94 KB
/
Copy pathwebpack.config.js
File metadata and controls
80 lines (74 loc) · 1.94 KB
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
const path = require('path')
const fs = require('fs')
function getComponentEntries(dirPath) {
const entries = {}
function collectEntries(currentPath, parentPath = '') {
fs.readdirSync(currentPath).forEach((file) => {
const filePath = path.resolve(currentPath, file)
const stat = fs.statSync(filePath)
if (stat.isDirectory()) {
const componentName = path.join(parentPath, file)
const indexPath = path.resolve(filePath, 'index.ts')
if (fs.existsSync(indexPath)) {
entries[componentName] = path.resolve(filePath, 'index.ts')
}
collectEntries(filePath, componentName) // Recursively collect entries in nested directories
}
})
}
collectEntries(dirPath)
return entries
}
function getOutputFilename(pathData) {
if (pathData.chunk.name === 'library') {
return 'index.js'
} else if (pathData.chunk.name === 'theme') {
return 'rusticTheme.js'
}
return `components/${pathData.chunk.name}/index.js`
}
const commonConfig = {
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js'],
},
entry: {
library: path.resolve(__dirname, 'src/components/index.ts'),
theme: path.resolve(__dirname, 'src/rusticTheme.ts'),
...getComponentEntries(path.resolve(__dirname, 'src/components')),
},
output: {
filename: getOutputFilename,
path: path.resolve(__dirname, 'dist'),
library: {
name: '@rustic-ai/ui-components',
type: 'umd',
},
clean: true,
},
experiments: {
asyncWebAssembly: false,
syncWebAssembly: false,
},
}
module.exports = {
...commonConfig,
module: {
rules: [
{
test: /\.(t|j)sx?$/,
use: {
loader: 'ts-loader',
options: {
configFile: 'tsconfig.json',
},
},
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
}
exports.commonConfig = commonConfig