webpack.dev.config.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const path = require('path');
  2. const merge = require('webpack-merge');
  3. const common = require('./webpack.common.config.js');
  4. const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
  5. const webpack = require('webpack');
  6. const HtmlWebpackPlugin = require('html-webpack-plugin', null, 2);
  7. const webpack_config = merge(common, {
  8. mode: 'development',
  9. output: {
  10. filename: 'js/[name].[hash:8].bundle.js',
  11. },
  12. module: {
  13. rules: [
  14. {
  15. test: /\.css$/,
  16. use: ['style-loader', 'css-loader', 'postcss-loader'],
  17. },
  18. {
  19. test: /\.less$/,
  20. use: ['style-loader', 'css-loader', 'postcss-loader', 'less-loader'],
  21. },
  22. ],
  23. },
  24. devServer: {
  25. contentBase: path.resolve(__dirname, '../dist'),
  26. open: true,
  27. port: 9000,
  28. compress: true,
  29. hot: true,
  30. quiet: true,
  31. },
  32. plugins: [
  33. new HtmlWebpackPlugin({
  34. template: 'public/index.html',
  35. inject: 'body',
  36. hash: false,
  37. }),
  38. new webpack.HotModuleReplacementPlugin(),
  39. new FriendlyErrorsWebpackPlugin({
  40. // 运行成功
  41. compilationSuccessInfo: {
  42. messages: ['You application is running here http://localhost:9000'],
  43. notes: [
  44. 'Some additionnal notes to be displayed unpon successful compilation',
  45. ],
  46. },
  47. // 运行错误
  48. onErrors: function (severity, errors) {
  49. //您可以收听插件转换和优先级的错误
  50. //严重性可以是'错误'或'警告'
  51. },
  52. //是否每次编译之间清除控制台
  53. //默认为true
  54. clearConsole: true,
  55. //添加格式化程序和变换器(见下文)
  56. additionalFormatters: [],
  57. additionalTransformers: [],
  58. }),
  59. ],
  60. });
  61. module.exports = webpack_config;