webpack.common.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Webpack common configuration.
  3. * it:
  4. * - Define the app entry point (./src) -> Where webpack will start compiling/bundling
  5. * - Define where assets will be served at by our webserver (static/)
  6. * - Clean previous build on each build
  7. * - Generates the index.html file automatically by injecting bundled assets in it (css, js)
  8. * - Allow to load html files as strings in js code (i.e: import htmlString from './myHtmlFile.html)
  9. * - Allow to automatically generates the dependencies injection for angularJS components annotated with
  10. * `'ngInject';` or `@ngInject` in comments. See https://docs.angularjs.org/guide/di
  11. */
  12. const path = require('path');
  13. const {CleanWebpackPlugin} = require('clean-webpack-plugin');
  14. const HtmlWebpackPlugin = require('html-webpack-plugin');
  15. module.exports = {
  16. entry: {main: './src/main.ts'},
  17. output: {
  18. // Path at which output assets will be served
  19. publicPath: '',
  20. },
  21. // Just for build speed improvement
  22. resolve: {
  23. extensions: ['.ts', '.js'],
  24. symlinks: true,
  25. modules: [
  26. __dirname,
  27. path.resolve(path.join(__dirname, './node_modules')),
  28. path.resolve(path.join(__dirname, './node_modules', 'hslayers-ng')),
  29. ],
  30. },
  31. plugins: [
  32. // Clean before build
  33. new CleanWebpackPlugin(),
  34. new HtmlWebpackPlugin({
  35. // Path where the file will be generated (appended to output.path)
  36. filename: 'index.html',
  37. template: './src/index.html',
  38. // We manually inject css and js files in our template
  39. inject: false,
  40. favicon: './src/images/cropped-favicon-32x32.png',
  41. }),
  42. ],
  43. module: {
  44. rules: [
  45. {
  46. test: /\.ts$/,
  47. use: [
  48. {loader: 'ng-annotate-loader'},
  49. {loader: 'ts-loader', options: {allowTsInNodeModules: true}},
  50. ],
  51. exclude: /node_modules\/(?!(hslayers-ng)\/).*/,
  52. },
  53. // Automatically generates $inject array for angularJS components annotated with:
  54. // 'ngInject';
  55. // or commented with /**@ngInject */
  56. {
  57. test: /\.js$/,
  58. exclude: /node_modules\/(?!(hslayers-ng)\/).*/,
  59. use: [
  60. {
  61. loader: 'babel-loader',
  62. options: {
  63. // Babel syntax dynamic import plugin allow babel to correctly parse js files
  64. // using webpack dynamic import expression (i.e import('angular').then(...))
  65. plugins: [
  66. 'angularjs-annotate',
  67. '@babel/plugin-syntax-dynamic-import',
  68. ],
  69. },
  70. },
  71. ],
  72. },
  73. // Load data files
  74. {
  75. test: /\.geojson$/,
  76. include: path.resolve(__dirname, 'src/data'),
  77. use: {
  78. loader: 'file-loader',
  79. options: {
  80. name: '[name].[ext]',
  81. outputPath: 'data',
  82. },
  83. },
  84. },
  85. ],
  86. },
  87. };