webpack.common.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 fs = require('fs');
  13. const path = require('path');
  14. const {CleanWebpackPlugin} = require('clean-webpack-plugin');
  15. const HtmlWebpackPlugin = require('html-webpack-plugin');
  16. module.exports = {
  17. entry: {main: './src/main.ts'},
  18. output: {
  19. // Path at which output assets will be served
  20. publicPath: '',
  21. },
  22. // Just for build speed improvement
  23. resolve: {
  24. extensions: ['.ts', '.js'],
  25. symlinks: true,
  26. modules: [
  27. __dirname,
  28. path.resolve(path.join(__dirname, './node_modules')),
  29. path.resolve(path.join(__dirname, './node_modules', 'hslayers-ng')),
  30. ],
  31. },
  32. plugins: [
  33. // Clean before build
  34. new CleanWebpackPlugin(),
  35. new HtmlWebpackPlugin({
  36. // Path where the file will be generated (appended to output.path)
  37. filename: 'index.html',
  38. template: './src/index.html',
  39. // We manually inject css and js files in our template
  40. inject: false,
  41. favicon: './src/images/cropped-favicon-32x32.png',
  42. }),
  43. ],
  44. module: {
  45. rules: [
  46. {
  47. test: /\.ts$/,
  48. use: [
  49. {loader: 'ng-annotate-loader'},
  50. {loader: 'ts-loader', options: {allowTsInNodeModules: true}},
  51. ],
  52. exclude: /node_modules\/(?!(hslayers-ng)\/).*/,
  53. },
  54. // Automatically generates $inject array for angularJS components annotated with:
  55. // 'ngInject';
  56. // or commented with /**@ngInject */
  57. {
  58. test: /\.js$/,
  59. exclude: /node_modules\/(?!(hslayers-ng)\/).*/,
  60. use: [
  61. {
  62. loader: 'babel-loader',
  63. options: {
  64. // Babel syntax dynamic import plugin allow babel to correctly parse js files
  65. // using webpack dynamic import expression (i.e import('angular').then(...))
  66. plugins: [
  67. 'angularjs-annotate',
  68. '@babel/plugin-syntax-dynamic-import',
  69. ],
  70. },
  71. },
  72. ],
  73. },
  74. {
  75. test: /\.scss$/,
  76. use: [
  77. 'style-loader',
  78. 'css-loader',
  79. {
  80. loader: 'sass-loader',
  81. options: {
  82. additionalData: fs.existsSync('./src/custom.scss')
  83. ? `@use "src/custom.scss" as *;`
  84. : '',
  85. },
  86. },
  87. ],
  88. },
  89. // Load data files
  90. {
  91. test: /\.(geo|topo)json$/,
  92. include: path.resolve(__dirname, 'src/data'),
  93. use: {
  94. loader: 'file-loader',
  95. options: {
  96. name: '[name].[ext]',
  97. outputPath: 'data',
  98. },
  99. },
  100. },
  101. ],
  102. },
  103. };