webpack.config.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const path = require('path');
  2. const htmlPlugin= require('html-webpack-plugin');
  3. const PurifyCSSPlugin = require("purifycss-webpack");
  4. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  5. const glob = require('glob');
  6. var website ={
  7. publicPath:"http://localhost:1717/"
  8. }
  9. module.exports={
  10. //入口文件的配置项
  11. entry:{
  12. entry:'./src/index.js',
  13. editor: './src/js/yzWebeditor'
  14. },
  15. //出口文件的配置项
  16. output:{
  17. //打包的路径文职
  18. path:path.resolve(__dirname,'dist'),
  19. //打包的文件名称
  20. filename:'[name]-bundle.js',
  21. publicPath:website.publicPath
  22. },
  23. node: {
  24. fs: "empty"
  25. },
  26. //模块:例如解读CSS,图片如何转换,压缩
  27. module:{
  28. rules: [
  29. {
  30. test: /\.css/,
  31. exclude:/node_modules/,
  32. use: ["style-loader","css-loader", "postcss-loader"],
  33. },{
  34. test: /\.less$/,
  35. use: [
  36. 'style-loader',
  37. { loader: 'css-loader', options: { importLoaders: 1 } },
  38. 'postcss-loader',
  39. 'less-loader'
  40. ]
  41. },{
  42. test:/\.(png|jpg|gif)/ ,
  43. use:[{
  44. loader:'url-loader',
  45. options:{
  46. limit:5000,
  47. outputPath:'images/',
  48. }
  49. }]
  50. },{
  51. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  52. loader: 'url-loader',
  53. options: {
  54. limit: 10000
  55. }
  56. },{
  57. test: /\.(htm|html)$/i,
  58. use:[ 'html-withimg-loader']
  59. },{
  60. test:/\.(jsx|js)$/,
  61. use:{
  62. loader:'babel-loader'
  63. },
  64. exclude:/node_modules/
  65. }
  66. ]
  67. },
  68. //插件,用于生产模版和各项功能
  69. plugins:[
  70. new htmlPlugin({
  71. minify:{
  72. removeAttributeQuotes:true
  73. },
  74. hash:true,
  75. template:'./src/index.html'
  76. }),
  77. new UglifyJsPlugin({
  78. uglifyOptions: {
  79. ie8: true
  80. }
  81. }),
  82. new PurifyCSSPlugin({
  83. // Give paths to parse for rules. These should be absolute!
  84. paths: glob.sync(path.join(__dirname, 'src/*.html')),
  85. })
  86. ],
  87. //配置webpack开发服务功能
  88. devServer:{
  89. //设置基本目录结构
  90. contentBase:path.resolve(__dirname,'dist'),
  91. //服务器的IP地址,可以使用IP也可以使用localhost
  92. host:'localhost',
  93. //服务端压缩是否开启
  94. compress:true,
  95. //配置服务端口号
  96. port:1717
  97. }
  98. }