webpack.config.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. var Path = require('path');
  2. var LiveReloadPlugin = require('webpack-livereload-plugin')
  3. var ExtractTextPlugin = require('extract-text-webpack-plugin')
  4. var HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
  5. var prod = process.env.NODE_ENV === 'production'
  6. module.exports = {
  7. entry: Path.resolve('src/index.js'),
  8. output: {
  9. path: Path.resolve('static/src'),
  10. filename: 'main.js'
  11. },
  12. resolve: {
  13. extensions: ['.js', '.vue', '.json'],
  14. alias: {
  15. 'vue$': 'vue/dist/vue.esm.js',
  16. '@': Path.resolve('src'),
  17. '@@': Path.resolve('src/components')
  18. }
  19. },
  20. plugins: [
  21. new LiveReloadPlugin({
  22. hostname: "192.168.88.130",
  23. port: 8071
  24. }),
  25. new ExtractTextPlugin('main.css'),
  26. new HardSourceWebpackPlugin({
  27. cacheDirectory: 'node_modules/.cache/hard-source/[confighash]',
  28. recordsPath: 'node_modules/.cache/hard-source/[confighash]/records.json',
  29. configHash: function(webpackConfig) {
  30. return require('node-object-hash')({sort: false}).hash(webpackConfig)
  31. },
  32. nvironmentHash: {
  33. root: process.cwd(),
  34. directories: [],
  35. files: ['package-lock.json', 'yarn.lock'],
  36. }
  37. })
  38. ],
  39. module: {
  40. rules: [
  41. {
  42. test: /\.vue$/,
  43. loader: 'vue-loader',
  44. options :{
  45. extractCSS: prod
  46. }
  47. },
  48. {
  49. test: /\.js$/,
  50. exclude: /node_modules/,
  51. loader: 'babel-loader',
  52. include: Path.resolve('src')
  53. },
  54. {
  55. test: /\.css$/,
  56. loader: ['style-loader', 'css-loader']
  57. },
  58. {
  59. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  60. loader: 'url-loader',
  61. options: {
  62. limit: 10000,
  63. name: Path.posix.join('static', 'img/[name].[hash:7].[ext]')
  64. }
  65. }
  66. ]
  67. }
  68. }