webpack.dev.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * Webpack development configuration (merged with common one).
  3. * it overrides the webpack.common.js configuration and:
  4. * - Set mode to development -> This mode is used by some plugins and webpack to prevent minifying assets etc...
  5. * - Generates a sourcemap of bundled code -> Allow to easily debug js code (do not use in prod)
  6. * - Remove some bundling optimization to speed it up
  7. * - Allow Load css files (import './myCssFile.css') -> Css rules will be automatically added to index.html into a <style></style> tag.
  8. * - Allow to load fonts and images (import './myFont.eot'; import './someImage.jpg')
  9. */
  10. const {merge} = require('webpack-merge');
  11. const common = require('./webpack.common');
  12. const path = require('path');
  13. const env = process.env;
  14. module.exports = merge(common, {
  15. mode: 'development',
  16. devtool: 'cheap-eval-source-map',
  17. watchOptions: {
  18. aggregateTimeout: 300,
  19. poll: 1000,
  20. },
  21. resolve: {
  22. symlinks: true,
  23. },
  24. optimization: {
  25. // see https://webpack.js.org/guides/build-performance#avoid-extra-optimization-steps
  26. removeAvailableModules: false,
  27. removeEmptyChunks: false,
  28. // In dev mode we simply want to get a big bundle containing all our js
  29. splitChunks: false,
  30. },
  31. output: {
  32. // see https://webpack.js.org/guides/build-performance#output-without-path-info
  33. // Path where bundled files will be output
  34. path: path.resolve(__dirname, './static'),
  35. pathinfo: false,
  36. filename: '[name].bundle.js',
  37. },
  38. devServer: {
  39. contentBase: path.resolve(__dirname, './static'),
  40. hot: false,
  41. host: '0.0.0.0',
  42. port: env.HTTP_PORT || 8080,
  43. },
  44. module: {
  45. rules: [
  46. // Load css files which will be injected in html page at startup <style>...</style>)
  47. {
  48. test: /\.css$/,
  49. use: ['style-loader', 'css-loader'],
  50. },
  51. {
  52. test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
  53. use: [
  54. {
  55. loader: 'file-loader',
  56. options: {
  57. name: '[name].[ext]',
  58. outputPath: 'fonts/',
  59. },
  60. },
  61. ],
  62. },
  63. // Load angularJS partials HTML file as URL
  64. {
  65. test: /\.html$/,
  66. exclude: path.resolve(__dirname, './src/index.html'),
  67. use: ['html-loader'],
  68. },
  69. // Load images as URLs
  70. {
  71. test: /\.(png|svg|jpg|gif)$/,
  72. use: {
  73. loader: 'file-loader',
  74. options: {
  75. name: '[name].[ext]',
  76. outputPath: 'images',
  77. },
  78. },
  79. },
  80. // Load locales files
  81. {
  82. type: 'javascript/auto',
  83. test: /\.json$/,
  84. include: path.resolve(__dirname, './src/assets/locales'),
  85. use: [
  86. {
  87. loader: 'file-loader',
  88. options: {
  89. name: '[name].[ext]',
  90. outputPath: 'locales',
  91. },
  92. },
  93. ],
  94. },
  95. ],
  96. },
  97. });