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.

116 lines
3.0 KiB

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: 'image-webpack-loader',
  65. options: {
  66. mozjpeg: {
  67. progressive: true,
  68. quality: 65,
  69. },
  70. // optipng.enabled: false will disable optipng
  71. optipng: {
  72. enabled: false,
  73. },
  74. pngquant: {
  75. quality: [0.65, 0.9],
  76. speed: 4,
  77. },
  78. gifsicle: {
  79. interlaced: true,
  80. },
  81. },
  82. },
  83. ],
  84. },
  85. {
  86. test: /\.svg$/,
  87. use: [
  88. {
  89. loader: 'svg-url-loader',
  90. options: {
  91. limit: 10000,
  92. },
  93. },
  94. ],
  95. },
  96. {
  97. test: /\.(png|jpg|gif)$/i,
  98. use: [
  99. {
  100. loader: 'url-loader',
  101. options: {
  102. name: 'images/[name].[ext]',
  103. limit: 10000,
  104. esModule: false
  105. },
  106. },
  107. ]
  108. }
  109. ],
  110. },
  111. };