webpack.common.js 2.3 KB

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