webpack.config.js 3.4 KB

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