webpack.config.js 3.0 KB

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