webpack.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. // libraryTarget: 'commonjs2'
  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. 'scss': [
  45. 'vue-style-loader',
  46. 'css-loader',
  47. 'sass-loader'
  48. ],
  49. 'sass': [
  50. 'vue-style-loader',
  51. 'css-loader',
  52. 'sass-loader?indentedSyntax'
  53. ]
  54. },
  55. postLoaders: {
  56. html: 'babel-loader'
  57. }
  58. // other vue-loader options go here
  59. }
  60. },
  61. {
  62. test: /\.svg$/,
  63. loader: 'vue-svg-loader', // `vue-svg` for webpack 1.x
  64. options: {
  65. // optional [svgo](https://github.com/svg/svgo) options
  66. svgo: {
  67. plugins: [
  68. {removeDoctype: true},
  69. {removeComments: true}
  70. ]
  71. }
  72. }
  73. },
  74. {
  75. test: /\.(js|jsx)$/,
  76. loader: 'babel-loader',
  77. exclude: /node_modules/
  78. },
  79. {
  80. test: /\.(pg|jpg|gif)$/,
  81. loader: 'file-loader',
  82. options: {
  83. name: '[name]-[hash].[ext]'
  84. }
  85. },
  86. {
  87. test: /\.(ttf|woff)$/,
  88. loader: 'file-loader',
  89. options: {
  90. name: '[name]-[hash].[ext]'
  91. }
  92. }
  93. ]
  94. },
  95. resolve: {
  96. alias: {
  97. '@': path.join(__dirname, 'src'),
  98. 'vue$': 'vue/dist/vue.esm.js'
  99. },
  100. extensions: ['.vue', '*', '.js', '.json', '.jsx']
  101. },
  102. devServer: {
  103. host: '0.0.0.0',
  104. port: 8081,
  105. disableHostCheck: true,
  106. historyApiFallback: true,
  107. noInfo: true,
  108. overlay: true,
  109. clientLogLevel: 'none'
  110. },
  111. performance: {
  112. hints: false
  113. },
  114. devtool: '#eval-source-map'
  115. }
  116. if (process.env.NODE_ENV === 'development') {
  117. Object.assign(module.exports, {
  118. entry: './src/main.js',
  119. output: {
  120. path: path.resolve(__dirname, './docs'),
  121. // publicPath: '/vue-edi-table/',
  122. publicPath: '',
  123. filename: 'index.js'
  124. }
  125. })
  126. module.exports.plugins = (module.exports.plugins || []).concat([
  127. new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html' })
  128. ])
  129. }
  130. if (process.env.NODE_ENV === 'production') {
  131. module.exports.devtool = '#source-map'
  132. // http://vue-loader.vuejs.org/en/workflow/production.html
  133. module.exports.plugins = (module.exports.plugins || []).concat([
  134. new webpack.DefinePlugin({
  135. 'process.env': {
  136. NODE_ENV: '"production"'
  137. }
  138. }),
  139. new webpack.optimize.UglifyJsPlugin({
  140. sourceMap: true,
  141. compress: {
  142. warnings: false
  143. }
  144. }),
  145. new webpack.LoaderOptionsPlugin({
  146. minimize: true
  147. }),
  148. new HtmlWebpackPlugin({filename: 'index.html', template: 'index.html'})
  149. ])
  150. // module.exports.externals = { 'vue': 'vue' }
  151. }