-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
168 lines (165 loc) · 6.36 KB
/
rollup.config.js
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import babel from 'rollup-plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import external from 'rollup-plugin-peer-deps-external'
import commonjs from 'rollup-plugin-commonjs'
import postcss from 'rollup-plugin-postcss'
import { terser } from 'rollup-plugin-terser'
import scss from 'rollup-plugin-scss'
import fs from "fs"
import path from "path"
// Configuration for individual components and entry point per component module folder
const componentsConfig = []
const generateComponentsConfigs = (baseDir) => {
const dr = fs.readdirSync(baseDir)
dr.map((d) => {
const fp = path.join(baseDir, d)
if (fs.lstatSync(fp).isDirectory()) {
// console.log(fp)
generateComponentsConfigs(fp)
}
if (fs.lstatSync(fp).isFile()) {
// console.log(baseDir)
// console.log(fp)
// console.log(d)
const fileName = d.split('.')
let bsDirArr = []
bsDirArr = baseDir.split('\\')
let formattedInputSrc = ''
if (fileName && fileName.length > 0 && fileName.length === 2 && (fileName[1] === 'js' || fileName[1] === 'jsx')) {
// console.log(`FORMATTED PATH: ${bsDirArr.join('/')}/${d}`)
// console.log(fileName[0] + "==" + fileName[1])
formattedInputSrc = `${bsDirArr.join('/')}/${d}`
let exportsType = fileName[0] === 'index' ? 'named' : 'default'
componentsConfig.push({
input: [`${formattedInputSrc}`],
output: [
{ file: `dist/${bsDirArr.join('/')}/${fileName[0]}.js`.replace('src', 'lib'), format: 'esm' },
// { file: `dist/${bsDirArr.join('/')}/${fileName[0]}.esm.js`.replace('src', 'lib'), format: 'esm', sourcemap: true, exports: exportsType },
],
plugins: [
external(),
postcss({
plugins: [],
minimize: true,
extensions: [".css", ".scss"],
}),
resolve({
preferBuiltins: true,
extensions: [".js", ".jsx", ".css", ".scss"]
}),
commonjs({
include: /node_modules/,
namedExports: {
'react': ['React'],
'classnames': ['classNames'],
'react-text-mask': ['MaskedInput'],
'react-hook-form': ['reactHookForm'],
'StepperContext': ['StepperContext'],
}
}),
babel({
exclude: 'node_modules/**',
presets: ['@babel/preset-react'],
}),
terser(),
]
})
}
}
// else {
// // console.log("=====")
// // console.log(baseDir)
// // console.log(fp)
// // console.log(d)
// // console.log("=====")
// componentsConfig.push({
// input: [`./${baseDir}/${d}/index.js`],
// output: [
// { file: `dist/${fp}/${d}.js`.replace('src', 'lib'), format: 'esm' },
// // { file: `dist/${fp}/${d}.js`.replace('src', 'lib'), format: 'esm', sourcemap: true, exports: 'auto' },
// ],
// plugins: [
// postcss({
// plugins: [],
// minimize: true,
// extensions: [".css", ".scss"],
// }),
// resolve({
// preferBuiltins: true,
// extensions: [".js", ".jsx", ".css", ".scss"]
// }),
// commonjs({
// include: /node_modules/,
// namedExports: {
// 'react': ['React'],
// 'classnames': ['classNames'],
// 'react-text-mask': ['MaskedInput'],
// 'react-hook-form': ['reactHookForm'],
// }
// }),
// babel({
// exclude: 'node_modules/**',
// presets: ['@babel/preset-react'],
// }),
// external(),
// terser(),
// ]
// })
// }
})
return componentsConfig
}
const showGeneratedComponentConfig = () => {
console.log(`\n ======COMPONENT CONFIGURATION====== \n`)
console.log(JSON.stringify(componentsConfig))
return []
}
export default [
...generateComponentsConfigs('./src/components'),
{
input: './src/index.js',
output: [
{
file: 'dist/lib/index.js',
format: 'cjs',
},
{
file: 'dist/lib/index.esm.js',
format: 'esm',
}
],
plugins: [
external(),
scss({
// include: [`/**/*/.css`,`/**/*/.scss`,`/**/*/.sass`],
output: `dist/lib/styles/index.css`,
failOnError: true,
runtime: require('sass'),
}),
postcss({
plugins: [],
minimize: true,
extensions: [".css", ".scss"],
}),
resolve({
preferBuiltins: true,
extensions: [".js", ".jsx", ".css", ".scss"]
}),
commonjs({
include: /node_modules/,
namedExports: {
'react': ['React'],
'classnames': ['classNames'],
'react-text-mask': ['MaskedInput'],
'react-hook-form': ['reactHookForm'],
}
}),
babel({
exclude: 'node_modules/**',
presets: ['@babel/preset-react'],
}),
terser(),
],
},
...showGeneratedComponentConfig(),
]