webpack.config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * Build config for the v0.5.0 FSE migration (@wordpress/scripts + webpack).
  3. *
  4. * Phase 1 (CSS): webpack now produces the site-wide stylesheet `v4-style.min.css`
  5. * (the old gulp `build` task). The legacy gulp pipeline still handles the JS bundles
  6. * for now — those migrate later, as their jQuery-era behaviors get modernized during
  7. * the template phases (see _claude/notes/upgrade-plan.md).
  8. *
  9. * Output layout (output.path = theme root so nothing escapes it):
  10. * - JS → build/[name].js (src/index.js seed; block view scripts later)
  11. * - v4-style → v4-style.min.css (theme root — keeps the `style-min` enqueue + font url()s valid)
  12. * - other CSS → build/[name].css
  13. */
  14. const path = require('path');
  15. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  16. const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
  17. const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
  18. module.exports = {
  19. entry: {
  20. index: './src/index.js',
  21. // Reproduces gulp `build` → v4-style.min.css (concat of the 5 CSS sources, in order).
  22. 'v4-style': './src/legacy-style.js',
  23. },
  24. output: {
  25. path: path.resolve(__dirname), // theme root
  26. filename: 'build/[name].js', // JS bundles live under build/
  27. clean: false, // NEVER clean — output.path is the theme root
  28. },
  29. module: {
  30. rules: [
  31. {
  32. test: /\.js$/,
  33. exclude: /node_modules/,
  34. use: { loader: 'babel-loader' },
  35. },
  36. {
  37. test: /\.css$/,
  38. use: [
  39. MiniCssExtractPlugin.loader,
  40. // url:false / import:false → leave url() + @import untouched (gulp-concat parity,
  41. // so the relative `fonts/…` paths keep resolving from the theme root).
  42. { loader: 'css-loader', options: { url: false, import: false } },
  43. ],
  44. },
  45. ],
  46. },
  47. optimization: {
  48. // '...' keeps webpack's default JS minifier (terser); add CSS minification.
  49. minimizer: [
  50. '...',
  51. // discardComments.removeAll matches the old gulp clean-css (specialComments:0).
  52. new CssMinimizerPlugin({
  53. minimizerOptions: { preset: ['default', { discardComments: { removeAll: true } }] },
  54. }),
  55. ],
  56. },
  57. plugins: [
  58. new MiniCssExtractPlugin({
  59. filename: ({ chunk }) =>
  60. chunk.name === 'v4-style' ? 'v4-style.min.css' : 'build/[name].css',
  61. }),
  62. new BrowserSyncPlugin({
  63. host: 'daw.stu',
  64. port: 3030,
  65. proxy: 'https://daw.stu',
  66. https: {
  67. key: '/opt/homebrew/etc/httpd/ssl/daw.stu-key.pem',
  68. cert: '/opt/homebrew/etc/httpd/ssl/daw.stu-cert.pem',
  69. },
  70. files: [
  71. './**/*.php',
  72. './src/**/*.js',
  73. './src/**/*.css',
  74. './templates/**/*.html',
  75. './parts/**/*.html',
  76. './patterns/**/*.php',
  77. './theme.json',
  78. ],
  79. ignore: ['node_modules', 'build', 'js/v4-*', '*.min.*'],
  80. open: 'external',
  81. reloadDelay: 50,
  82. injectChanges: true,
  83. notify: false,
  84. }),
  85. ],
  86. };