webpack.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 OfflinePlugin = require('offline-plugin')
  7. var prod = process.env.NODE_ENV === 'production'
  8. module.exports = {
  9. entry: Path.resolve('src/index.js'),
  10. output: {
  11. path: Path.resolve('static/src'),
  12. filename: 'main.js'
  13. },
  14. resolve: {
  15. extensions: ['.js', '.vue', '.json'],
  16. alias: {
  17. 'vue$': 'vue/dist/vue.esm.js',
  18. '@': Path.resolve('src'),
  19. '@@': Path.resolve('src/components')
  20. }
  21. },
  22. plugins: [
  23. new LiveReloadPlugin({
  24. appendScriptTag: true
  25. }),
  26. new HardSourcePlugin({
  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. environmentHash: {
  33. root: process.cwd(),
  34. directories: [],
  35. files: ['package-lock.json', 'yarn.lock'],
  36. }
  37. }),
  38. new ExtractTextPlugin('main.css'),
  39. new CopyPlugin([
  40. {
  41. from: 'src/sw.js',
  42. to: '.'
  43. }
  44. ]),
  45. new OfflinePlugin()
  46. ],
  47. module: {
  48. rules: [
  49. {
  50. test: /\.vue$/,
  51. loader: 'vue-loader',
  52. options: {
  53. extractCSS: prod
  54. }
  55. },
  56. {
  57. test: /\.js$/,
  58. exclude: /node_modules/,
  59. loader: 'babel-loader',
  60. include: Path.resolve('src')
  61. },
  62. {
  63. test: /\.css$/,
  64. loader: ['style-loader', 'css-loader']
  65. },
  66. {
  67. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  68. loader: 'url-loader',
  69. options: {
  70. limit: 10000,
  71. name: Path.posix.join('static', 'img/[name].[hash:7].[ext]')
  72. }
  73. }
  74. ]
  75. }
  76. }