webpack.config.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 CopyWebpackPlugin = 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 HardSourceWebpackPlugin({
  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. new CopyWebpackPlugin([
  39. {
  40. from: 'src/sw.js',
  41. to: '.'
  42. }
  43. ])
  44. ],
  45. module: {
  46. rules: [
  47. {
  48. test: /\.vue$/,
  49. loader: 'vue-loader',
  50. options: {
  51. extractCSS: prod
  52. }
  53. },
  54. {
  55. test: /\.js$/,
  56. exclude: /node_modules/,
  57. loader: 'babel-loader',
  58. include: Path.resolve('src')
  59. },
  60. {
  61. test: /\.css$/,
  62. loader: ['style-loader', 'css-loader']
  63. },
  64. {
  65. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  66. loader: 'url-loader',
  67. options: {
  68. limit: 10000,
  69. name: Path.posix.join('static', 'img/[name].[hash:7].[ext]')
  70. }
  71. }
  72. ]
  73. }
  74. }