webpack.common.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const path = require('path');
  2. module.exports = {
  3. target: 'web',
  4. entry: {
  5. app: './public/app/index.ts',
  6. },
  7. output: {
  8. path: path.resolve(__dirname, '../../public/build'),
  9. filename: '[name].[hash].js',
  10. // Keep publicPath relative for host.com/grafana/ deployments
  11. publicPath: 'public/build/',
  12. },
  13. resolve: {
  14. extensions: ['.ts', '.tsx', '.es6', '.js', '.json', '.svg'],
  15. alias: {},
  16. modules: [path.resolve('public'), path.resolve('node_modules')],
  17. },
  18. stats: {
  19. children: false,
  20. warningsFilter: /export .* was not found in/,
  21. source: false
  22. },
  23. node: {
  24. fs: 'empty',
  25. },
  26. module: {
  27. rules: [{
  28. test: require.resolve('jquery'),
  29. use: [{
  30. loader: 'expose-loader',
  31. query: 'jQuery',
  32. },
  33. {
  34. loader: 'expose-loader',
  35. query: '$',
  36. },
  37. ],
  38. },
  39. {
  40. test: /\.html$/,
  41. exclude: /(index|error)\-template\.html/,
  42. use: [{
  43. loader: 'ngtemplate-loader?relativeTo=' + path.resolve(__dirname, '../../public') + '&prefix=public',
  44. },
  45. {
  46. loader: 'html-loader',
  47. options: {
  48. attrs: [],
  49. minimize: true,
  50. removeComments: false,
  51. collapseWhitespace: false,
  52. },
  53. },
  54. ],
  55. },
  56. ],
  57. },
  58. // https://webpack.js.org/plugins/split-chunks-plugin/#split-chunks-example-3
  59. optimization: {
  60. moduleIds: 'hashed',
  61. runtimeChunk: 'single',
  62. splitChunks: {
  63. chunks: 'all',
  64. minChunks: 1,
  65. cacheGroups: {
  66. moment: {
  67. test: /[\\/]node_modules[\\/]moment[\\/].*[jt]sx?$/,
  68. chunks: 'initial',
  69. priority: 20,
  70. enforce: true
  71. },
  72. angular: {
  73. test: /[\\/]node_modules[\\/]angular[\\/].*[jt]sx?$/,
  74. chunks: 'initial',
  75. priority: 50,
  76. enforce: true
  77. },
  78. vendors: {
  79. test: /[\\/]node_modules[\\/].*[jt]sx?$/,
  80. chunks: 'initial',
  81. priority: -10,
  82. reuseExistingChunk: true,
  83. enforce: true
  84. },
  85. default: {
  86. priority: -20,
  87. chunks: 'all',
  88. test: /.*[jt]sx?$/,
  89. reuseExistingChunk: true
  90. },
  91. },
  92. },
  93. },
  94. };