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.

75 lines
2.4 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. const fs = require('fs');
  2. const path = require('path');
  3. const process = require('process');
  4. const BundleTracker = require('webpack-bundle-tracker');
  5. const VueLoaderPlugin = require('vue-loader/lib/plugin')
  6. const { ContextReplacementPlugin } = require('webpack');
  7. const hljsLanguages = require('./components/hljsLanguages');
  8. const devMode = process.env.DEBUG !== 'False';
  9. const hotReload = process.env.HOT_RELOAD === '1';
  10. const webpackHost = process.env.WEBPACK_HOST || '127.0.0.1';
  11. const webpackPort = process.env.WEBPACK_PORT ? parseInt(process.env.WEBPACK_PORT, 10) : 8080;
  12. const pollMillis = process.env.WEBPACK_POLL_MILLIS ? parseInt(process.env.WEBPACK_POLL_MILLIS, 10) : false;
  13. const noSourceMap = process.env.SOURCE_MAP === 'False';
  14. const pagesRoot = path.join(__dirname, 'pages');
  15. const entryPoints = {};
  16. fs.readdirSync(pagesRoot).forEach((scriptName) => {
  17. const bundleName = path.parse(scriptName).name;
  18. const scriptPath = path.join(pagesRoot, scriptName)
  19. entryPoints[bundleName] = scriptPath;
  20. });
  21. module.exports = {
  22. mode: devMode ? 'development' : 'production',
  23. entry: entryPoints,
  24. output: {
  25. publicPath: hotReload ? `http://127.0.0.1:${webpackPort}/` : '',
  26. path: path.join(__dirname, 'bundle'),
  27. filename: '[name].js'
  28. },
  29. devtool: noSourceMap ? false : (devMode ? 'cheap-eval-source-map' : 'source-map'),
  30. devServer: {
  31. port: webpackPort,
  32. host: webpackHost,
  33. hot: true,
  34. quiet: false,
  35. headers: { 'Access-Control-Allow-Origin': '*' }
  36. },
  37. watchOptions: {
  38. poll: pollMillis,
  39. },
  40. module: {
  41. rules: [
  42. {
  43. test: /\.pug$/,
  44. loader: 'pug-plain-loader'
  45. },
  46. {
  47. test: /\.css$/,
  48. use: [
  49. 'vue-style-loader',
  50. 'css-loader'
  51. ]
  52. },
  53. {
  54. test: /\.vue$/,
  55. loader: 'vue-loader'
  56. }
  57. ]
  58. },
  59. plugins: [
  60. new ContextReplacementPlugin(
  61. /highlight\.js\/lib\/languages$/,
  62. new RegExp(`^./(${hljsLanguages.join('|')})$`)
  63. ),
  64. new BundleTracker({ filename: './webpack-stats.json' }),
  65. new VueLoaderPlugin()
  66. ],
  67. resolve: {
  68. extensions: ['.js', '.vue'],
  69. alias: {
  70. vue$: 'vue/dist/vue.esm.js',
  71. },
  72. },
  73. }