webpack.common.js 2.4 KB

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