webpack.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var Path = require('path');
  2. var LiveReloadPlugin = require('webpack-livereload-plugin')
  3. var HardSourcePlugin = require('hard-source-webpack-plugin')
  4. var ExtractTextPlugin = require('extract-text-webpack-plugin')
  5. var CopyPlugin = require('copy-webpack-plugin')
  6. var prod = process.env.NODE_ENV === 'production'
  7. module.exports = {
  8. entry: Path.resolve('src/index.js'),
  9. output: {
  10. path: Path.resolve('static/src'),
  11. filename: 'main.js'
  12. },
  13. resolve: {
  14. extensions: ['.js', '.vue', '.json'],
  15. alias: {
  16. 'vue$': 'vue/dist/vue.esm.js',
  17. '@': Path.resolve('src'),
  18. '@@': Path.resolve('src/components')
  19. }
  20. },
  21. plugins: [
  22. new LiveReloadPlugin({
  23. appendScriptTag: true
  24. }),
  25. new HardSourcePlugin({
  26. cacheDirectory: 'node_modules/.cache/hard-source/[confighash]',
  27. recordsPath: 'node_modules/.cache/hard-source/[confighash]/records.json',
  28. configHash: function(webpackConfig) {
  29. return require('node-object-hash')({sort: false}).hash(webpackConfig)
  30. },
  31. environmentHash: {
  32. root: process.cwd(),
  33. directories: [],
  34. files: ['package-lock.json', 'yarn.lock'],
  35. }
  36. }),
  37. new ExtractTextPlugin('main.css')
  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. }