webpack.common.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. const hslPaths = require(path.join(
  16. __dirname,
  17. './node_modules/hslayers-ng/common_paths'
  18. ));
  19. module.exports = {
  20. entry: {main: './src/app.module.js'},
  21. output: {
  22. // Path at which output assets will be served
  23. publicPath: '',
  24. },
  25. // Just for build speed improvement
  26. resolve: {
  27. symlinks: true,
  28. modules: [
  29. path.join(__dirname),
  30. path.join(__dirname, './node_modules'),
  31. path.resolve(path.join(__dirname, './node_modules', 'hslayers-ng')),
  32. ].concat(hslPaths.paths),
  33. },
  34. plugins: [
  35. // Clean before build
  36. new CleanWebpackPlugin(),
  37. new HtmlWebpackPlugin({
  38. // Path where the file will be generated (appended to output.path)
  39. filename: 'index.html',
  40. template: './src/index.html',
  41. // We manually inject css and js files in our template
  42. inject: false,
  43. //favicon: './src/images/cropped-favicon-32x32.png',
  44. }),
  45. ],
  46. module: {
  47. rules: [
  48. // Automatically generates $inject array for angularJS components annotated with:
  49. // 'ngInject';
  50. // or commented with /**@ngInject */
  51. {
  52. test: /\.js$/,
  53. exclude: /node_modules\/(?!(hslayers-ng)\/).*/,
  54. use: [
  55. {
  56. loader: 'babel-loader',
  57. options: {
  58. // Babel syntax dynamic import plugin allow babel to correctly parse js files
  59. // using webpack dynamic import expression (i.e import('angular').then(...))
  60. plugins: [
  61. 'angularjs-annotate',
  62. '@babel/plugin-syntax-dynamic-import',
  63. ],
  64. },
  65. },
  66. ],
  67. },
  68. ],
  69. },
  70. };