dev.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const path = require('path')
  2. const ip = require('ip')
  3. const webpack = require('webpack')
  4. const HtmlWebpackPlugin = require('html-webpack-plugin')
  5. const CopyWebpackPlugin = require('copy-webpack-plugin')
  6. const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
  7. const config = require('../config')
  8. const clientOptions = '?path=/__what&timeout=5000&reload=true&quiet=true'
  9. const VueLoaderPlugin = require('vue-loader/lib/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: /\.js$/,
  59. enforce: 'pre',
  60. exclude: /node_modules/,
  61. loader: 'eslint-loader',
  62. },
  63. {
  64. test: /\.js$/,
  65. exclude: /node_modules/,
  66. loader: 'babel-loader',
  67. },
  68. {
  69. test: /\.vue$/,
  70. loader: 'vue-loader',
  71. },
  72. ],
  73. },
  74. externals: {
  75. vue: 'Vue',
  76. },
  77. resolve: {
  78. extensions: [
  79. '.js',
  80. '.vue',
  81. ],
  82. alias: {
  83. '@': path.resolve(__dirname, '../../src'),
  84. },
  85. },
  86. devtool: 'inline-source-map',
  87. plugins: [
  88. new HtmlWebpackPlugin({
  89. template: config.template,
  90. }),
  91. new VueLoaderPlugin(),
  92. new webpack.DefinePlugin({
  93. 'process.env': config.dev.env,
  94. }),
  95. new webpack.HotModuleReplacementPlugin(),
  96. new FriendlyErrorsWebpackPlugin({
  97. compilationSuccessInfo: {
  98. messages: [
  99. `http://localhost:${config.port} or http://${ip.address()}:${config.port}`,
  100. ],
  101. },
  102. }),
  103. new CopyWebpackPlugin([
  104. {
  105. from: path.resolve(__dirname, '../../static'),
  106. to: 'static',
  107. ignore: ['.*'],
  108. },
  109. ]),
  110. ],
  111. }