webpack.common.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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(__dirname, './node_modules/hslayers-ng/common_paths'));
  16. module.exports = {
  17. entry: { main: './src/app.js' },
  18. output: {
  19. // Path at which output assets will be served
  20. publicPath: ''
  21. },
  22. // Just for build speed improvement
  23. resolve: {
  24. symlinks: true,
  25. modules: [
  26. path.join(__dirname),
  27. path.join(__dirname, './node_modules'),
  28. path.resolve(path.join(__dirname, './node_modules', 'hslayers-ng'))
  29. ].concat(hslPaths.paths)
  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: 'assets/img/favicon.ico'
  41. })
  42. ],
  43. module: {
  44. rules: [
  45. // Automatically generates $inject array for angularJS components annotated with:
  46. // 'ngInject';
  47. // or commented with /**@ngInject */
  48. {
  49. test: /\.js$/,
  50. exclude: /node_modules\/(?!(hslayers-ng)\/).*/,
  51. use: [
  52. {
  53. loader: 'babel-loader',
  54. options: {
  55. // Babel syntax dynamic import plugin allow babel to correctly parse js files
  56. // using webpack dynamic import expression (i.e import('angular').then(...))
  57. plugins: ['angularjs-annotate', '@babel/plugin-syntax-dynamic-import']
  58. }
  59. }
  60. ]
  61. }
  62. ]
  63. }
  64. };