MCPcopy Create free account
hub / github.com/ReactTooltip/react-tooltip / writeBundle

Function writeBundle

rollup-plugins/replace-before-save-file.js:27–85  ·  view source on GitHub ↗

* This write bundle is executed after the files being written. * Docs: https://rollupjs.org/plugin-development/#writebundle

(options, bundle)

Source from the content-addressed store, hash-verified

25 * Docs: https://rollupjs.org/plugin-development/#writebundle
26 */
27 async writeBundle(options, bundle) {
28 const replaceKeys = Object.keys(replaceObject)
29 if (replaceKeys.length > 0) {
30 const files = Object.keys(bundle)
31
32 let file = null
33 let key = null
34 let regex = null
35 for (let index = 0; index < files.length; index += 1) {
36 file = files[index]
37
38 if (file && bundle[file].code) {
39 for (let indexKeys = 0; indexKeys < replaceKeys.length; indexKeys += 1) {
40 key = replaceKeys[indexKeys]
41 regex = new RegExp(key, 'g')
42
43 if (bundle[file].code.includes(key)) {
44 if (key.includes('css') && replaceObject[key].includes('file:')) {
45 const [, fileName] = replaceObject[key].split(':')
46 const fileContent = await readFile(`./dist/${fileName}`, 'utf8')
47
48 const splittedCSSContent = fileContent.split('/** end - core styles **/')
49
50 if (key.includes('core-css')) {
51 if (options.file.includes('.min')) {
52 bundle[file].code = bundle[file].code.replace(
53 regex,
54 `\`${cssMinifier(splittedCSSContent[0])}\``,
55 )
56 } else {
57 bundle[file].code = bundle[file].code.replace(
58 regex,
59 `\`${splittedCSSContent[0]}\``,
60 )
61 }
62 } else if (!key.includes('core-css')) {
63 if (options.file.includes('.min')) {
64 bundle[file].code = bundle[file].code.replace(
65 regex,
66 `\`${cssMinifier(splittedCSSContent[1])}\``,
67 )
68 } else {
69 bundle[file].code = bundle[file].code.replace(
70 regex,
71 `\`${splittedCSSContent[1]}\``,
72 )
73 }
74 }
75 } else {
76 bundle[file].code = bundle[file].code.replace(regex, replaceObject[key])
77 }
78
79 await writeFile(options.file, bundle[file].code)
80 }
81 }
82 }
83 }
84 }

Callers

nothing calls this directly

Calls 1

cssMinifierFunction · 0.85

Tested by

no test coverage detected