dev.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. const path = require('path')
  2. const ip = require('ip')
  3. const webpack = require('webpack')
  4. const HtmlWebpackPlugin = require('html-webpack-plugin')
  5. const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
  6. const config = require('../config')
  7. const clientOptions = '?path=/__what&timeout=5000&reload=true&quiet=true'
  8. const VueLoaderPlugin = require('vue-loader/lib/plugin')
  9. const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
  10. module.exports = {
  11. mode: 'development',
  12. entry: [
  13. `webpack-hot-middleware/client${clientOptions}`,
  14. path.resolve(__dirname, '../../src/index.js'),
  15. ],
  16. output: {
  17. filename: 'bundle.js',
  18. publicPath: config.dev.publicPath,
  19. },
  20. module: {
  21. rules: [
  22. {
  23. test: /\.css$/i,
  24. use: [
  25. 'style-loader',
  26. {
  27. loader: 'css-loader',
  28. options: {
  29. importLoaders: 1,
  30. },
  31. },
  32. 'postcss-loader',
  33. ],
  34. },
  35. {
  36. test: /\.s[ac]ss$/i,
  37. use: [
  38. 'style-loader',
  39. {
  40. loader: 'css-loader',
  41. options: {
  42. importLoaders: 2,
  43. },
  44. },
  45. 'postcss-loader',
  46. 'sass-loader',
  47. ],
  48. },
  49. {
  50. test: /\.(png|jpe?g|gif|svg)$/i,
  51. loader: 'file-loader',
  52. },
  53. {
  54. test: /\.(ttf|otf|woff2?|eot)$/i,
  55. loader: 'file-loader',
  56. },
  57. {
  58. test: /\.(html)$/i,
  59. loader: 'html-loader',
  60. },
  61. {
  62. test: /\.js$/,
  63. enforce: 'pre',
  64. exclude: /node_modules/,
  65. loader: 'eslint-loader',
  66. },
  67. {
  68. test: /\.js$/,
  69. exclude: /node_modules/,
  70. loader: 'babel-loader',
  71. },
  72. {
  73. test: /\.vue$/,
  74. loader: 'vue-loader',
  75. },
  76. ],
  77. },
  78. externals: {
  79. vue: 'Vue',
  80. },
  81. resolve: {
  82. extensions: [
  83. '.js',
  84. '.vue',
  85. ],
  86. alias: {
  87. '@': path.resolve(__dirname, '../../src'),
  88. },
  89. },
  90. devtool: 'inline-source-map',
  91. plugins: [
  92. new HtmlWebpackPlugin({
  93. template: config.template,
  94. }),
  95. new VueLoaderPlugin(),
  96. new webpack.DefinePlugin({
  97. 'process.env': config.dev.env,
  98. }),
  99. new CaseSensitivePathsPlugin(),
  100. new webpack.HotModuleReplacementPlugin(),
  101. new FriendlyErrorsWebpackPlugin({
  102. compilationSuccessInfo: {
  103. messages: [
  104. `http://localhost:${config.port} or http://${ip.address()}:${config.port}`,
  105. ],
  106. },
  107. }),
  108. ],
  109. }