webpack.config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  4. const Visualizer = require('webpack-visualizer-plugin');
  5. const CopyWebpackPlugin = require('copy-webpack-plugin');
  6. module.exports = {
  7. entry: {
  8. main: './src/frontend/js/index.js',
  9. login: './src/frontend/js/login.js'
  10. },
  11. output: {
  12. path: path.resolve(__dirname, 'dist'),
  13. filename: 'js/[name].js',
  14. publicPath: '/'
  15. },
  16. resolve: {
  17. alias: {
  18. 'tabler-core': 'tabler-ui/dist/assets/js/core',
  19. 'bootstrap': 'tabler-ui/dist/assets/js/vendors/bootstrap.bundle.min',
  20. 'sparkline': 'tabler-ui/dist/assets/js/vendors/jquery.sparkline.min',
  21. 'selectize': 'tabler-ui/dist/assets/js/vendors/selectize.min',
  22. 'tablesorter': 'tabler-ui/dist/assets/js/vendors/jquery.tablesorter.min',
  23. 'vector-map': 'tabler-ui/dist/assets/js/vendors/jquery-jvectormap-2.0.3.min',
  24. 'vector-map-de': 'tabler-ui/dist/assets/js/vendors/jquery-jvectormap-de-merc',
  25. 'vector-map-world': 'tabler-ui/dist/assets/js/vendors/jquery-jvectormap-world-mill',
  26. 'circle-progress': 'tabler-ui/dist/assets/js/vendors/circle-progress.min',
  27. 'c3': 'tabler-ui/dist/assets/js/vendors/chart.bundle.min'
  28. }
  29. },
  30. module: {
  31. rules: [
  32. // Shims for tabler-ui
  33. {
  34. test: /assets\/js\/core/,
  35. loader: 'imports-loader?bootstrap'
  36. },
  37. {
  38. test: /jquery-jvectormap-de-merc/,
  39. loader: 'imports-loader?vector-map'
  40. },
  41. {
  42. test: /jquery-jvectormap-world-mill/,
  43. loader: 'imports-loader?vector-map'
  44. },
  45. // other:
  46. {
  47. type: 'javascript/auto', // <= Set the module.type explicitly
  48. test: /\bmessages\.json$/,
  49. loader: 'messageformat-loader',
  50. options: {
  51. biDiSupport: false,
  52. disablePluralKeyChecks: false,
  53. formatters: null,
  54. intlSupport: false,
  55. locale: ['en'/*, 'es'*/],
  56. strictNumberSign: false
  57. }
  58. },
  59. {
  60. test: /\.js$/,
  61. exclude: /node_modules/,
  62. use: {
  63. loader: 'babel-loader'
  64. }
  65. },
  66. {
  67. test: /\.ejs$/,
  68. loader: 'ejs-loader'
  69. },
  70. {
  71. test: /\.scss$/,
  72. use: [
  73. MiniCssExtractPlugin.loader,
  74. 'css-loader',
  75. 'sass-loader'
  76. ]
  77. },
  78. {
  79. test: /.*tabler.*\.(jpe?g|gif|png|svg|eot|woff|ttf)$/,
  80. use: [
  81. {
  82. loader: 'file-loader',
  83. options: {
  84. outputPath: 'assets/tabler-ui/'
  85. }
  86. }
  87. ]
  88. }
  89. ]
  90. },
  91. plugins: [
  92. new webpack.ProvidePlugin({
  93. $: 'jquery',
  94. jQuery: 'jquery',
  95. _: 'underscore'
  96. }),
  97. new MiniCssExtractPlugin({
  98. filename: 'css/[name].css',
  99. chunkFilename: 'css/[id].css'
  100. }),
  101. new Visualizer({
  102. filename: '../webpack_stats.html'
  103. }),
  104. new CopyWebpackPlugin([{
  105. from: 'src/frontend/app-images',
  106. to: 'images',
  107. toType: 'dir',
  108. context: '/app'
  109. }]),
  110. new webpack.optimize.LimitChunkCountPlugin({
  111. maxChunks: 1, // Must be greater than or equal to one
  112. minChunkSize: 999999999
  113. })
  114. ],
  115. /*
  116. optimization: {
  117. splitChunks: {
  118. chunks (chunk) {
  119. // exclude `my-excluded-chunk`
  120. return false;
  121. },
  122. minSize: 999999999,
  123. minChunks: 1,
  124. name: true,
  125. cacheGroups: {
  126. vendors: {
  127. test: /[\\/]node_modules[\\/]/,
  128. priority: -10
  129. },
  130. default: {
  131. minChunks: 2,
  132. priority: -20,
  133. reuseExistingChunk: true
  134. }
  135. }
  136. }
  137. },
  138. */
  139. devServer: {
  140. contentBase: path.join(__dirname, 'dist'),
  141. compress: true,
  142. port: 8080,
  143. disableHostCheck: true,
  144. host: '0.0.0.0'
  145. }
  146. };