webpack.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const {resolve} = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. module.exports = {
  4. entry : ['./src/js/index.js','./src/index.html'],
  5. output:{
  6. filename: 'js/built.js',
  7. path: resolve(__dirname,'build')
  8. },
  9. module:{
  10. rules:[
  11. //less
  12. {
  13. test:/\.less$/,
  14. use:['style-loader','css-loader','less-loader']
  15. },
  16. //css
  17. {
  18. test:/\.css$/,
  19. use:['style-loader','css-loader']
  20. },
  21. //图片
  22. {
  23. test: /\.(jpg|jpeg|png|gif)$/,
  24. loader: 'url-loader',
  25. options:{
  26. limit:8*1024,
  27. name:'[hash:10].[ext]',
  28. esModule:false,
  29. outputPath: 'imgs'
  30. },
  31. type:'javascript/auto'
  32. },
  33. //html
  34. {
  35. test:/\.html$/,
  36. loader: 'html-loader'
  37. },
  38. //其他
  39. {
  40. exclude:/\.(html|js|css|less|jpg|jpeg|png|gif)$/,
  41. loader:'file-loader',
  42. options:{
  43. name:'[hash:10].[ext]',
  44. esModule:false,
  45. outputPath: 'media'
  46. },
  47. type:'javascript/auto'
  48. }
  49. ]
  50. },
  51. plugins:[
  52. new HtmlWebpackPlugin({
  53. template:'./src/index.html'
  54. })
  55. ],
  56. mode: 'development',
  57. devServer:{
  58. contentBase:resolve(__dirname,'build'),
  59. compress:true,
  60. port:3000,
  61. open:true,
  62. hot:true
  63. },
  64. target: "web", //可以解决browserslist 导致 webpack-dev-server 的自动刷新失效
  65. /**
  66. * source-map: 外部
  67. * inline-source-map: 内联
  68. * hidden-source-map: 外部
  69. * eval-source-map: 内联
  70. * nosources-source-map: 外部
  71. * cheap-source-map: 外部
  72. * cheap-module-source-map: 外部
  73. */
  74. }