Skip to content

Commit

Permalink
Clean up learn-german app build config
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirohonda committed Aug 26, 2024
1 parent d356f82 commit 0d2bd30
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
37 changes: 37 additions & 0 deletions apps/learn-german/scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# service worker

No longer necessary to write service worker files manually as we use the vite plugin. This folder is just for documentation.

# Generating a build file array

We could add a custom plug-in to generate a file that includes all the generated assets. `generateBundle` is a Vite API that can be called after the bundle is generated.

```ts
plugins: [
nxViteTsPaths(),
// VitePWA({
// registerType: 'autoUpdate',
// manifest: manifestObj as any,
// workbox: {
// globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
// },
// }),
{
name: 'collect-build-files',
generateBundle(options, bundle) {
const files = []

for (const fileName in bundle) {
if (Object.prototype.hasOwnProperty.call(bundle, fileName)) {
files.push(fileName)
}
}

const outDir = options.dir || 'dist'
const outputPath = path.resolve(outDir, 'build-files.js')
const fileContent = `export const buildFiles = ${JSON.stringify(files, null, 2)};`

fs.writeFileSync(outputPath, fileContent, 'utf-8')

console.log(`Build files array written to: ${outputPath}`)
},
},
],
```
28 changes: 0 additions & 28 deletions apps/learn-german/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export default defineConfig({
host: 'localhost',
},

// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },

build: {
outDir: '../../dist/apps/learn-german',
reportCompressedSize: true,
Expand All @@ -50,30 +45,7 @@ export default defineConfig({
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
},
}),
// {
// name: 'collect-build-files',
// generateBundle(options, bundle) {
// // Array to store the file names
// const files = []

// // Iterate through the bundle object to collect file names
// for (const fileName in bundle) {
// if (Object.prototype.hasOwnProperty.call(bundle, fileName)) {
// files.push(fileName)
// }
// }

// const outDir = options.dir || 'dist'
// const outputPath = path.resolve(outDir, 'build-files.js')
// const fileContent = `export const buildFiles = ${JSON.stringify(files, null, 2)};`

// fs.writeFileSync(outputPath, fileContent, 'utf-8')

// console.log(`Build files array written to: ${outputPath}`)
// },
// },
],

test: {
globals: true,
cache: {
Expand Down

0 comments on commit 0d2bd30

Please sign in to comment.