webpack.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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?gfm=true'
  95. }
  96. /*,
  97. {
  98. test: /\.md$/,
  99. use: 'raw-loader'
  100. } */
  101. ]
  102. },
  103. // plugins: [ new CopyWebpackPlugin(['src/static']) ],
  104. resolve: {
  105. alias: {
  106. '@': path.join(__dirname, 'src'),
  107. 'vue$': 'vue/dist/vue.esm.js'
  108. },
  109. extensions: ['.vue', '*', '.js', '.json', '.jsx']
  110. },
  111. devServer: {
  112. host: '0.0.0.0',
  113. port: 8081,
  114. disableHostCheck: true,
  115. historyApiFallback: true,
  116. noInfo: true,
  117. overlay: true,
  118. clientLogLevel: 'none'
  119. },
  120. performance: {
  121. hints: false
  122. },
  123. devtool: '#eval-source-map'
  124. }
  125. if (process.env.NODE_ENV === 'development') {
  126. Object.assign(module.exports, {
  127. entry: './src/main.js',
  128. output: {
  129. path: path.resolve(__dirname, './docs'),
  130. // publicPath: '/vue-edi-table/',
  131. publicPath: '',
  132. filename: 'index.js'
  133. }
  134. })
  135. module.exports.plugins = (module.exports.plugins || []).concat([
  136. new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html' })
  137. ])
  138. }
  139. if (process.env.NODE_ENV === 'production') {
  140. module.exports.devtool = '#source-map'
  141. // http://vue-loader.vuejs.org/en/workflow/production.html
  142. module.exports.plugins = (module.exports.plugins || []).concat([
  143. new webpack.DefinePlugin({
  144. 'process.env': {
  145. NODE_ENV: '"production"'
  146. }
  147. }),
  148. new webpack.optimize.UglifyJsPlugin({
  149. sourceMap: true,
  150. compress: {
  151. warnings: false
  152. }
  153. }),
  154. new webpack.LoaderOptionsPlugin({
  155. minimize: true
  156. }),
  157. new HtmlWebpackPlugin({filename: 'index.html', template: 'index.html'})
  158. ])
  159. // module.exports.externals = { 'vue': 'vue' }
  160. }