webpack.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. var path = require('path')
  2. var webpack = require('webpack')
  3. var HtmlWebpackPlugin = require('html-webpack-plugin')
  4. var CopyWebpackPlugin = require('copy-webpack-plugin')
  5. var outfile = 'index.js'
  6. module.exports = {
  7. entry: './src/main.js',
  8. output: {
  9. path: path.resolve(__dirname, './dist'),
  10. publicPath: '',
  11. filename: outfile
  12. },
  13. module: {
  14. rules: [
  15. {
  16. test: /\.css$/,
  17. use: [
  18. 'vue-style-loader',
  19. 'css-loader'
  20. ]
  21. },
  22. {
  23. test: /\.scss$/,
  24. use: [
  25. 'vue-style-loader',
  26. 'css-loader',
  27. 'sass-loader'
  28. ]
  29. },
  30. {
  31. test: /\.sass$/,
  32. use: [
  33. 'vue-style-loader',
  34. 'css-loader',
  35. 'sass-loader?indentedSyntax'
  36. ]
  37. },
  38. {
  39. test: /\.vue$/,
  40. loader: 'vue-loader',
  41. options: {
  42. loaders: {
  43. 'scss': [
  44. 'vue-style-loader',
  45. 'css-loader',
  46. 'sass-loader'
  47. ],
  48. 'sass': [
  49. 'vue-style-loader',
  50. 'css-loader',
  51. 'sass-loader?indentedSyntax'
  52. ]
  53. },
  54. postLoaders: {
  55. html: 'babel-loader'
  56. }
  57. // other vue-loader options go here
  58. }
  59. },
  60. {
  61. test: /\.svg$/,
  62. loader: 'vue-svg-loader', // `vue-svg` for webpack 1.x
  63. options: {
  64. // optional [svgo](https://github.com/svg/svgo) options
  65. svgo: {
  66. plugins: [
  67. {removeDoctype: true},
  68. {removeComments: true}
  69. ]
  70. }
  71. }
  72. },
  73. {
  74. test: /\.(js|jsx)$/,
  75. loader: 'babel-loader',
  76. exclude: /node_modules/
  77. },
  78. {
  79. test: /\.(pg|jpg|gif)$/,
  80. loader: 'file-loader',
  81. options: {
  82. name: '[name]-[hash].[ext]'
  83. }
  84. },
  85. {
  86. test: /\.(ttf|woff)$/,
  87. loader: 'file-loader',
  88. options: {
  89. name: '[name]-[hash].[ext]'
  90. }
  91. },
  92. {
  93. test: /\.md$/,
  94. loader: 'html-loader!highlight-loader!markdown-loader'
  95. }
  96. /*,
  97. {
  98. test: /\.md$/,
  99. use: 'raw-loader'
  100. } */
  101. ]
  102. },
  103. plugins: [
  104. new CopyWebpackPlugin(['static'])
  105. ],
  106. resolve: {
  107. alias: {
  108. '@': path.join(__dirname, 'src'),
  109. 'vue$': 'vue/dist/vue.esm.js'
  110. },
  111. extensions: ['.vue', '*', '.js', '.json', '.jsx']
  112. },
  113. devServer: {
  114. host: '0.0.0.0',
  115. port: 8081,
  116. disableHostCheck: true,
  117. historyApiFallback: true,
  118. noInfo: true,
  119. overlay: true,
  120. clientLogLevel: 'none'
  121. },
  122. performance: {
  123. hints: false
  124. },
  125. devtool: '#eval-source-map'
  126. }
  127. if (process.env.NODE_ENV === 'development') {
  128. Object.assign(module.exports, {
  129. entry: './src/main.js',
  130. output: {
  131. path: path.resolve(__dirname, './docs'),
  132. // publicPath: '/vue-edi-table/',
  133. publicPath: '',
  134. filename: 'index.js'
  135. }
  136. })
  137. module.exports.plugins = (module.exports.plugins || []).concat([
  138. new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html' })
  139. ])
  140. }
  141. if (process.env.NODE_ENV === 'production') {
  142. module.exports.devtool = '#source-map'
  143. // http://vue-loader.vuejs.org/en/workflow/production.html
  144. module.exports.plugins = (module.exports.plugins || []).concat([
  145. new webpack.DefinePlugin({
  146. 'process.env': {
  147. NODE_ENV: '"production"'
  148. }
  149. }),
  150. new webpack.optimize.UglifyJsPlugin({
  151. sourceMap: true,
  152. compress: {
  153. warnings: false
  154. }
  155. }),
  156. new webpack.LoaderOptionsPlugin({
  157. minimize: true
  158. }),
  159. new HtmlWebpackPlugin({filename: 'index.html', template: 'index.html'})
  160. ])
  161. // module.exports.externals = { 'vue': 'vue' }
  162. }