webpack.config.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var Path = require('path');
  2. var LiveReloadPlugin = require('webpack-livereload-plugin')
  3. var HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
  4. var ExtractTextPlugin = require('extract-text-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. appendScriptTag: true
  23. }),
  24. // new HardSourceWebpackPlugin({
  25. // cacheDirectory: 'node_modules/.cache/hard-source/[confighash]',
  26. // recordsPath: 'node_modules/.cache/hard-source/[confighash]/records.json',
  27. // configHash: function(webpackConfig) {
  28. // return require('node-object-hash')({sort: false}).hash(webpackConfig)
  29. // },
  30. // environmentHash: {
  31. // root: process.cwd(),
  32. // directories: [],
  33. // files: ['package-lock.json', 'yarn.lock'],
  34. // }
  35. // }),
  36. new ExtractTextPlugin('main.css')
  37. ],
  38. module: {
  39. rules: [
  40. {
  41. test: /\.vue$/,
  42. loader: 'vue-loader',
  43. options: {
  44. extractCSS: prod
  45. }
  46. },
  47. {
  48. test: /\.js$/,
  49. exclude: /node_modules/,
  50. loader: 'babel-loader',
  51. include: Path.resolve('src')
  52. },
  53. {
  54. test: /\.css$/,
  55. loader: ['style-loader', 'css-loader']
  56. },
  57. {
  58. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  59. loader: 'url-loader',
  60. options: {
  61. limit: 10000,
  62. name: Path.posix.join('static', 'img/[name].[hash:7].[ext]')
  63. }
  64. }
  65. ]
  66. }
  67. }