webpack.config.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. // styles.scss @imports Bootstrap + bootstrap-icons from node_modules — webpack
  47. // now compiles it (replaces gulp's `mixin` task). quietDeps silences Bootstrap's
  48. // internal sass deprecation noise; url:false keeps the bootstrap-icons font path.
  49. test: /\.scss$/,
  50. use: [
  51. MiniCssExtractPlugin.loader,
  52. { loader: 'css-loader', options: { url: false, import: false } },
  53. {
  54. loader: 'sass-loader',
  55. options: {
  56. implementation: require('sass'),
  57. sassOptions: { quietDeps: true },
  58. },
  59. },
  60. ],
  61. },
  62. ],
  63. },
  64. optimization: {
  65. // '...' keeps webpack's default JS minifier (terser); add CSS minification.
  66. minimizer: [
  67. '...',
  68. // discardComments.removeAll matches the old gulp clean-css (specialComments:0).
  69. new CssMinimizerPlugin({
  70. minimizerOptions: { preset: ['default', { discardComments: { removeAll: true } }] },
  71. }),
  72. ],
  73. },
  74. plugins: [
  75. new MiniCssExtractPlugin({
  76. filename: ({ chunk }) =>
  77. chunk.name === 'v4-style' ? 'v4-style.min.css' : 'build/[name].css',
  78. }),
  79. new BrowserSyncPlugin({
  80. host: 'daw.stu',
  81. port: 81,
  82. proxy: 'https://daw.stu',
  83. https: {
  84. key: '/opt/homebrew/etc/httpd/ssl/daw.stu-key.pem',
  85. cert: '/opt/homebrew/etc/httpd/ssl/daw.stu-cert.pem',
  86. },
  87. files: [
  88. './**/*.php',
  89. './src/**/*.js',
  90. './src/**/*.css',
  91. './templates/**/*.html',
  92. './parts/**/*.html',
  93. './patterns/**/*.php',
  94. './theme.json',
  95. './.bs-reload', // touched by save_post (functions.php) → reload after Gutenberg "Update"
  96. ],
  97. ignore: ['node_modules', 'build', 'js/v4-*', '*.min.*'],
  98. open: 'external',
  99. reloadDelay: 50,
  100. injectChanges: true,
  101. notify: false,
  102. // Serve dev responses uncached so a reload always reflects the latest edit
  103. // (no stale browser cache while iterating). Pairs with the `files` watch above,
  104. // which already auto-reloads on .php / template / src changes.
  105. middleware: function (req, res, next) {
  106. res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0');
  107. res.setHeader('Pragma', 'no-cache');
  108. res.setHeader('Expires', '0');
  109. next();
  110. },
  111. }),
  112. ],
  113. };