webpack.config.js 2.7 KB

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