hof 24.0.0-vite-beta.5 → 24.0.0-vite-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,39 +2,36 @@
2
2
  'use strict';
3
3
 
4
4
  import { defineConfig } from 'vite';
5
- import {resolve} from 'path';
6
- const __dirname = import.meta.dirname;
5
+ import { resolve } from 'path';
6
+ import fs from 'fs';
7
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
8
+ import commonjs from '@rollup/plugin-commonjs';
9
+ const projectRoot = process.cwd();
10
+ const publicDir = resolve(projectRoot, 'public');
11
+
12
+ const entryFile = (() => {
13
+ const src = resolve(process.cwd(), 'assets/js/index.js');
14
+ if (fs.existsSync(src)) return src;
15
+
16
+ throw new Error(`vite: entry file not found. Checked: ${src}`);
17
+ })();
7
18
 
8
19
  export default defineConfig({
9
- root: '../../../frontend',
10
- build: {
11
- outDir: resolve(__dirname, '../../../../public/assets'),
12
- emptyOutDir: true,
13
- rollupOptions: {
14
- input: {
15
- index: resolve(__dirname, '../../../../hof/frontend/themes/gov-uk/client-js/index.js'),
16
- styles: resolve(__dirname, '../../../../hof/frontend/themes/gov-uk/styles/govuk.scss')
17
- }
18
- },
19
- css: {
20
- preprocessorOptions: {
21
- scss: {
22
- includes: ['node_modules']
23
- }
24
- }
25
- }
26
- },
27
- // Custom plugin to suppress specific resolve warnings.
28
- // Vite does not process and optimise static images and assets files, it uses a src/ folder.
29
- // the images and assets folders are therefore loaded at runtime from the public/ folder.
30
- // This should be resolved with the v5/nunjucks work so we can ignore these warnings for now.
31
- // TO DO: Remove this when v5/nunjucks is implemented.
32
20
  plugins: [
21
+ commonjs({
22
+ include: [/node_modules/, /assets\/js/, /frontend/]
23
+ }),
24
+ nodeResolve({ browser: true, preferBuiltins: false }),
25
+ // Intercept all console warnings printed during build
26
+ // Custom plugin to suppress specific resolve warnings.
27
+ // Vite does not process and optimise static images and assets files, it uses a src/ folder.
28
+ // the images and assets folders are therefore loaded at runtime from the public/ folder.
29
+ // This should be resolved with the v5/nunjucks work so we can ignore these warnings for now.
30
+ // TO DO: Remove this when v5/nunjucks is implemented.
33
31
  {
34
32
  name: 'suppress-resolve-warnings',
35
33
  apply: 'build',
36
34
  configResolved() {
37
- // Intercept all console warnings printed during build
38
35
  const originalWarning = console.warn;
39
36
  console.warn = (...args) => {
40
37
  if (
@@ -49,5 +46,34 @@ export default defineConfig({
49
46
  };
50
47
  }
51
48
  }
52
- ]
49
+ ],
50
+ target: 'es2018', // ensures browser-compatible output
51
+ base: '/assets/',
52
+ build: {
53
+ outDir: publicDir,
54
+ emptyOutDir: false,
55
+ rollupOptions: {
56
+ input: {
57
+ index: entryFile
58
+ },
59
+ output: {
60
+ entryFileNames: 'js/bundle.js',
61
+ chunkFileNames: 'js/[name]-[hash].js',
62
+ assetFileNames: assetInfo => {
63
+ const ext = assetInfo.name && assetInfo.name.split('.').pop();
64
+ if (/css/i.test(ext)) return 'css/[name]-[hash][extname]';
65
+ if (/svg|png|jpg|jpeg|gif|webp|ico/i.test(ext)) return 'images/[name]-[hash][extname]';
66
+ return 'assets/[name]-[hash][extname]';
67
+ },
68
+ format: 'iife'
69
+ }
70
+ },
71
+ css: {
72
+ preprocessorOptions: {
73
+ scss: {
74
+ includes: ['node_modules']
75
+ }
76
+ }
77
+ }
78
+ }
53
79
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hof",
3
3
  "description": "A bootstrap for HOF projects",
4
- "version": "24.0.0-vite-beta.5",
4
+ "version": "24.0.0-vite-beta.6",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
7
7
  "author": "HomeOffice",
@@ -100,6 +100,8 @@
100
100
  "devDependencies": {
101
101
  "@cucumber/cucumber": "^7.3.2",
102
102
  "@cucumber/pretty-formatter": "^1.0.1",
103
+ "@rollup/plugin-commonjs": "^29.0.0",
104
+ "@rollup/plugin-node-resolve": "^16.0.3",
103
105
  "@types/jest": "^26.0.24",
104
106
  "@xmldom/xmldom": "~0.8.11",
105
107
  "chai": "^3.5.0",