dev.js 2.7 KB

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