webpack.config.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const webpack = require('webpack')
  2. const path = require('path')
  3. const HtmlWebpackPlugin = require('html-webpack-plugin')
  4. const config =
  5. {
  6. output: {
  7. path: path.join(__dirname, 'dist'),
  8. filename: 'bundle.js',
  9. globalObject: 'this'
  10. },
  11. module: {
  12. rules: [
  13. {
  14. test: /\.worker\.js$/, //以.worker.js结尾的文件将被worker-loader加载
  15. use: { loader: 'worker-loader' }
  16. },
  17. {
  18. test: /\.js$/,
  19. exclude: /node_modules/,
  20. use: {
  21. loader: 'babel-loader'
  22. }
  23. },
  24. {
  25. test: /\.css$/,
  26. use: [
  27. {loader: 'style-loader'},
  28. {loader: 'css-loader'},
  29. {
  30. loader: 'postcss-loader',
  31. options: {
  32. plugins: [require('autoprefixer')]
  33. }
  34. }
  35. ]
  36. },
  37. {
  38. test: /\.(png|jpg|gif|woff|eot|ttf|svg)$/,
  39. use: {
  40. loader: 'url-loader',
  41. options: {
  42. limit: 8192,
  43. name: "assets/[name].[ext]"
  44. }
  45. }
  46. }
  47. ]
  48. },
  49. plugins: [
  50. new webpack.HotModuleReplacementPlugin(),
  51. new HtmlWebpackPlugin({
  52. template: path.join(__dirname, 'src/index.html'),
  53. minify: {
  54. removeComments: false,
  55. collapseWhitespace: false
  56. }
  57. })
  58. ]
  59. // ,
  60. // devServer: {
  61. // contentBase: path.join(__dirname, "dist"),
  62. // port: 8000,
  63. // hot: true
  64. // }
  65. }
  66. module.exports = config