You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.3 KiB

2 years ago
2 years ago
2 years ago
  1. const glob = require('glob');
  2. const path = require('path');
  3. const CopyWebpackPlugin = require('copy-webpack-plugin');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. // not sure why this 'entries' is post-specific; tried adding other paths and they failed;
  7. const entries = glob.sync(path.resolve(__dirname, 'src/assets/images/posts/*.{png,gif,jpg,jpeg}'));
  8. entries.push(path.resolve(__dirname, 'src/assets/styles/main.css'));
  9. // TODO: Remove if the blog does not need syntax highlight
  10. entries.push(path.resolve(__dirname, 'src/assets/styles/prism-atom-dark.css'));
  11. let cssFileName = 'styles/[name].css';
  12. if (process.env.NODE_ENV === 'production') {
  13. cssFileName = 'styles/[name].[contenthash].css';
  14. }
  15. module.exports = {
  16. mode: 'development',
  17. entry: entries,
  18. output: {
  19. path: path.resolve(__dirname, '_site/assets'),
  20. publicPath: '/',
  21. },
  22. plugins: [
  23. new CopyWebpackPlugin({
  24. patterns: [{ from: path.resolve(__dirname, 'public'), to: path.resolve(__dirname, '_site') }],
  25. }),
  26. new MiniCssExtractPlugin({
  27. filename: cssFileName,
  28. }),
  29. new HtmlWebpackPlugin({
  30. template: path.resolve(__dirname, 'webpack.html'),
  31. filename: path.resolve(__dirname, 'src/_includes/layouts/webpack.ejs'),
  32. inject: false,
  33. }),
  34. ],
  35. module: {
  36. rules: [
  37. {
  38. test: /\.css$/,
  39. exclude: /node_modules/,
  40. use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
  41. },
  42. {
  43. test: /\.(gif|png|jpg|jpeg)$/i,
  44. use: [
  45. {
  46. loader: 'file-loader',
  47. options: {
  48. name: 'images/[name].[ext]',
  49. },
  50. },
  51. {
  52. loader: 'file-loader',
  53. options: {
  54. name: 'images/screenshots/[name].[ext]',
  55. },
  56. },
  57. {
  58. loader: 'file-loader',
  59. options: {
  60. name: 'images/systems/[name].[ext]',
  61. },
  62. },
  63. {
  64. loader: 'file-loader',
  65. options: {
  66. name: 'images/products/icons/[name].[ext]',
  67. },
  68. },
  69. {
  70. loader: 'file-loader',
  71. options: {
  72. name: 'images/products/heros/[name].[ext]',
  73. },
  74. },
  75. {
  76. loader: 'image-webpack-loader',
  77. options: {
  78. mozjpeg: {
  79. progressive: true,
  80. quality: 65,
  81. },
  82. // optipng.enabled: false will disable optipng
  83. optipng: {
  84. enabled: false,
  85. },
  86. pngquant: {
  87. quality: [0.65, 0.9],
  88. speed: 4,
  89. },
  90. gifsicle: {
  91. interlaced: true,
  92. },
  93. },
  94. },
  95. ],
  96. },
  97. {
  98. test: /\.svg$/,
  99. use: [
  100. {
  101. loader: 'svg-url-loader',
  102. options: {
  103. limit: 10000,
  104. },
  105. },
  106. ],
  107. },
  108. {
  109. test: /\.(png|jpg|gif)$/i,
  110. use: [
  111. {
  112. loader: 'url-loader',
  113. options: {
  114. name: 'images/[name].[ext]',
  115. limit: 10000,
  116. esModule: false
  117. },
  118. },
  119. ]
  120. }
  121. ],
  122. },
  123. };