webpack.config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // const webpack = require("webpack");
  2. // const path = require("path");
  3. // let config = {
  4. // mode: 'development',
  5. // entry: [
  6. // "./scripts/main.js",
  7. // "./scripts/extlink.js",
  8. // "./scss/styles.scss",
  9. // ],
  10. // output: {
  11. // path: path.resolve(__dirname, "./dist/assets"),
  12. // filename: "./bundle.js"
  13. // },
  14. // module: {
  15. // rules: [
  16. // {
  17. // test: /\.scss$/i,
  18. // use: [
  19. // {
  20. // loader: 'file-loader',
  21. // options: {
  22. // name: './css/bundle.css',
  23. // }
  24. // },
  25. // // Compile le Sass en CSS
  26. // "sass-loader"
  27. // ],
  28. // },
  29. // ],
  30. // }
  31. // }
  32. // module.exports = config;
  33. // const webpack = require("webpack");
  34. // const path = require("path");
  35. // const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  36. // let config = {
  37. // mode: 'development',
  38. // entry: [
  39. // "./scripts/main.js",
  40. // "./scripts/extlink.js",
  41. // "./scss/styles.scss",
  42. // ],
  43. // output: {
  44. // path: path.resolve(__dirname, "./dist/assets"),
  45. // filename: "./bundle.js",
  46. // },
  47. // module: {
  48. // rules: [
  49. // {
  50. // test: /\.scss$/i,
  51. // use: [
  52. // // Extract CSS to a separate file (instead of injecting with <style>)
  53. // MiniCssExtractPlugin.loader,
  54. // {
  55. // loader: "css-loader",
  56. // options: {
  57. // // Optional: if you don't want url() handling
  58. // // url: false,
  59. // },
  60. // },
  61. // {
  62. // loader: "sass-loader",
  63. // options: {
  64. // // Use Dart Sass and its modern JS API
  65. // implementation: require("sass"),
  66. // },
  67. // },
  68. // ],
  69. // },
  70. // ],
  71. // },
  72. // plugins: [
  73. // new MiniCssExtractPlugin({
  74. // filename: "./css/bundle.css", // same output path/name you had
  75. // }),
  76. // ],
  77. // };
  78. // module.exports = config;
  79. const webpack = require("webpack");
  80. const path = require("path");
  81. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  82. const CopyWebpackPlugin = require("copy-webpack-plugin");
  83. let config = {
  84. mode: "development",
  85. entry: [
  86. "./scripts/main.js",
  87. "./scripts/extlink.js",
  88. "./scripts/print.js",
  89. "./scss/styles.scss",
  90. ],
  91. output: {
  92. path: path.resolve(__dirname, "./dist/assets"),
  93. filename: "./bundle.js",
  94. clean: true, // optional: clean dist between builds
  95. },
  96. module: {
  97. rules: [
  98. // SCSS → CSS
  99. {
  100. test: /\.scss$/i,
  101. use: [
  102. MiniCssExtractPlugin.loader,
  103. {
  104. loader: "css-loader",
  105. options: {
  106. url: false, // 👈 keep url(...) unchanged
  107. importLoaders: 1,
  108. // url: true by default, so url(...) will be processed
  109. },
  110. },
  111. {
  112. loader: "sass-loader",
  113. options: {
  114. implementation: require("sass"), // Dart Sass, modern API
  115. },
  116. },
  117. ],
  118. },
  119. // Images in CSS (and JS)
  120. {
  121. test: /\.(png|jpe?g|gif|svg|webp)$/i,
  122. type: "asset/resource",
  123. generator: {
  124. filename: "./images/[name][hash][ext][query]",
  125. },
  126. },
  127. // Fonts (if you use any)
  128. {
  129. test: /\.(woff2?|eot|ttf|otf)$/i,
  130. type: "asset/resource",
  131. generator: {
  132. filename: "./fonts/[name][hash][ext][query]",
  133. },
  134. },
  135. ],
  136. },
  137. plugins: [
  138. new MiniCssExtractPlugin({
  139. filename: "./css/bundle.css", // same as before
  140. }),
  141. new CopyWebpackPlugin({
  142. patterns: [
  143. {
  144. from: path.resolve(__dirname, "./fonts"),
  145. to: "./fonts",
  146. },
  147. {
  148. from: path.resolve(__dirname, "./images"),
  149. to: "./images",
  150. },
  151. ],
  152. }),
  153. ],
  154. // So you actually see what the 11 errors are if something else happens
  155. stats: {
  156. errorDetails: true,
  157. },
  158. };
  159. module.exports = config;