|
4 | 4 | * Config based on https://github.com/elastic/next-eui-starter
|
5 | 5 | */
|
6 | 6 |
|
7 |
| -import crypto from 'node:crypto'; |
8 |
| -import fs from 'node:fs'; |
9 |
| -import path from 'node:path'; |
10 |
| -import { fileURLToPath } from 'node:url'; |
11 | 7 | import { withSentryConfig } from '@sentry/nextjs';
|
12 |
| -import CopyWebpackPlugin from 'copy-webpack-plugin'; |
13 | 8 | import dotenv from 'dotenv';
|
14 |
| -import { glob } from 'glob'; |
15 |
| -import capitalize from 'lodash-es/capitalize.js'; |
16 | 9 | import webpack from 'webpack';
|
17 | 10 |
|
18 |
| -const __filename = fileURLToPath(import.meta.url); |
19 |
| -const __dirname = path.dirname(__filename); |
20 |
| - |
21 | 11 | dotenv.config();
|
22 | 12 |
|
23 | 13 | const pathPrefix = '';
|
24 | 14 |
|
25 |
| -const themeConfig = buildThemeConfig(); |
26 |
| - |
27 | 15 | const { EnvironmentPlugin, IgnorePlugin } = webpack;
|
28 | 16 |
|
29 | 17 | /**
|
@@ -106,7 +94,6 @@ const nextConfig = {
|
106 | 94 | */
|
107 | 95 | env: {
|
108 | 96 | PATH_PREFIX: pathPrefix,
|
109 |
| - THEME_CONFIG: JSON.stringify(themeConfig), |
110 | 97 | },
|
111 | 98 |
|
112 | 99 | /**
|
@@ -201,11 +188,6 @@ const nextConfig = {
|
201 | 188 | VERCEL_ENV: '',
|
202 | 189 | }),
|
203 | 190 |
|
204 |
| - // Copy @elastic/eui theme files |
205 |
| - new CopyWebpackPlugin({ |
206 |
| - patterns: buildElasticThemeFileCopyPatterns(), |
207 |
| - }), |
208 |
| - |
209 | 191 | // Moment ships with a large number of locales. Exclude them, leaving
|
210 | 192 | // just the default English locale. If you need other locales, see:
|
211 | 193 | // https://create-react-app.dev/docs/troubleshooting/#momentjs-locales-are-missing
|
@@ -318,93 +300,3 @@ export default withSentryConfig(nextConfig, {
|
318 | 300 | deleteSourcemapsAfterUpload: true,
|
319 | 301 | },
|
320 | 302 | });
|
321 |
| - |
322 |
| -/** |
323 |
| - * Find all EUI themes and construct a theme configuration object. |
324 |
| - * |
325 |
| - * The `copyConfig` key is used to configure CopyWebpackPlugin, which |
326 |
| - * copies the default EUI themes into the `public` directory, injecting a |
327 |
| - * hash into the filename so that when EUI is updated, new copies of the |
328 |
| - * themes will be fetched. |
329 |
| - * |
330 |
| - * The `availableThemes` key is used in the app to includes the themes in |
331 |
| - * the app's `<head>` element, and for theme switching. |
332 |
| - */ |
333 |
| -function buildThemeConfig() { |
334 |
| - const themeFiles = glob.sync( |
335 |
| - path.join( |
336 |
| - __dirname, |
337 |
| - 'node_modules', |
338 |
| - '@elastic', |
339 |
| - 'eui', |
340 |
| - 'dist', |
341 |
| - 'eui_theme_*.min.css' |
342 |
| - ), |
343 |
| - { |
344 |
| - // Only / characters are used by this glob implementation. |
345 |
| - // Since Windows uses \ as a path separator then we enable this option |
346 |
| - // in order for us to use glob patterns created from `path.join`. |
347 |
| - // https://github.com/isaacs/node-glob#windows |
348 |
| - windowsPathsNoEscape: true, |
349 |
| - } |
350 |
| - ); |
351 |
| - |
352 |
| - /** @type {import('./electron/renderer/lib/theme').ThemeConfig} */ |
353 |
| - const themeConfig = { |
354 |
| - availableThemes: [], |
355 |
| - copyConfig: [], |
356 |
| - }; |
357 |
| - |
358 |
| - for (const themeFile of themeFiles) { |
359 |
| - const basename = path.basename(themeFile, '.min.css'); |
360 |
| - const themeId = basename.replace(/^eui_theme_/, ''); |
361 |
| - const themeName = capitalize(themeId).replace(/_/g, ' '); |
362 |
| - const publicPath = `themes/${basename}.${hashFile(themeFile)}.min.css`; |
363 |
| - |
364 |
| - const toPath = path.join( |
365 |
| - __dirname, |
366 |
| - 'electron', |
367 |
| - 'renderer', |
368 |
| - `public`, |
369 |
| - `themes`, |
370 |
| - `${basename}.${hashFile(themeFile)}.min.css` |
371 |
| - ); |
372 |
| - |
373 |
| - themeConfig.availableThemes.push({ |
374 |
| - id: themeId, |
375 |
| - name: themeName, |
376 |
| - publicPath, |
377 |
| - }); |
378 |
| - |
379 |
| - themeConfig.copyConfig.push({ |
380 |
| - from: themeFile, |
381 |
| - to: toPath, |
382 |
| - }); |
383 |
| - } |
384 |
| - |
385 |
| - return themeConfig; |
386 |
| -} |
387 |
| - |
388 |
| -/** |
389 |
| - * @returns {import('copy-webpack-plugin').ObjectPattern[]} |
390 |
| - */ |
391 |
| -function buildElasticThemeFileCopyPatterns() { |
392 |
| - return themeConfig.copyConfig; |
393 |
| -} |
394 |
| - |
395 |
| -/** |
396 |
| - * Given a file, calculate a hash and return the first portion. The number |
397 |
| - * of characters is truncated to match how Webpack generates hashes. |
398 |
| - * |
399 |
| - * @param {string} filePath the absolute path to the file to hash. |
400 |
| - * @return {string} |
401 |
| - */ |
402 |
| -function hashFile(filePath) { |
403 |
| - const hash = crypto.createHash(`sha256`); |
404 |
| - const fileData = fs.readFileSync(filePath); |
405 |
| - hash.update(fileData); |
406 |
| - const fullHash = hash.digest(`hex`); |
407 |
| - |
408 |
| - // Use a hash length that matches what Webpack does |
409 |
| - return fullHash.substring(0, 20); |
410 |
| -} |
0 commit comments