webpack.config.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. var path = require('path')
  2. var webpack = require('webpack')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. const NODE_ENV = process.env.NODE_ENV
  7. module.exports = {
  8. entry: NODE_ENV=='development'? './src/main.js' : './index.js',
  9. output: {
  10. path: path.resolve(__dirname, './dist'),
  11. publicPath: '/dist/',
  12. filename: 'index.js'
  13. },
  14. module: {
  15. rules: [
  16. {
  17. test: /\.css$/,
  18. use: [
  19. 'vue-style-loader',
  20. 'css-loader'
  21. ],
  22. },
  23. {
  24. test: /\.scss$/,
  25. use: [
  26. 'vue-style-loader',
  27. 'css-loader',
  28. 'sass-loader'
  29. ],
  30. },
  31. {
  32. test: /\.sass$/,
  33. use: [
  34. 'vue-style-loader',
  35. 'css-loader',
  36. 'sass-loader?indentedSyntax'
  37. ],
  38. },
  39. {
  40. test: /\.vue$/,
  41. loader: 'vue-loader',
  42. options: {
  43. loaders: {
  44. // Since sass-loader (weirdly) has SCSS as its default parse mode, we map
  45. // the "scss" and "sass" values for the lang attribute to the right configs here.
  46. // other preprocessors should work out of the box, no loader config like this necessary.
  47. 'scss': [
  48. 'vue-style-loader',
  49. 'css-loader',
  50. 'sass-loader'
  51. ],
  52. 'sass': [
  53. 'vue-style-loader',
  54. 'css-loader',
  55. 'sass-loader?indentedSyntax'
  56. ]
  57. }
  58. // other vue-loader options go here
  59. }
  60. },
  61. {
  62. test: /\.js$/,
  63. loader: 'babel-loader',
  64. exclude: /node_modules/
  65. },
  66. {
  67. test: /\.(png|jpg|gif|svg)$/,
  68. loader: 'file-loader',
  69. options: {
  70. name: '[name].[ext]?[hash]'
  71. }
  72. },
  73. {
  74. test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
  75. loader: 'file-loader'
  76. }
  77. ]
  78. },
  79. resolve: {
  80. alias: {
  81. 'vue$': 'vue/dist/vue.esm.js',
  82. '@': resolve('src')
  83. },
  84. extensions: ['*', '.js', '.vue', '.json']
  85. },
  86. devServer: {
  87. historyApiFallback: true,
  88. noInfo: true,
  89. overlay: true
  90. },
  91. performance: {
  92. hints: false
  93. },
  94. devtool: '#eval-source-map',
  95. }
  96. if (process.env.NODE_ENV === 'production') {
  97. module.exports.devtool = '#source-map'
  98. // http://vue-loader.vuejs.org/en/workflow/production.html
  99. module.exports.plugins = (module.exports.plugins || []).concat([
  100. new webpack.DefinePlugin({
  101. 'process.env': {
  102. NODE_ENV: '"production"'
  103. }
  104. }),
  105. new webpack.optimize.UglifyJsPlugin({
  106. sourceMap: true,
  107. compress: {
  108. warnings: false
  109. }
  110. }),
  111. new webpack.LoaderOptionsPlugin({
  112. minimize: true
  113. })
  114. ])
  115. }