webpack.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. var path = require('path')
  2. var webpack = require('webpack')
  3. var HtmlWebpackPlugin = require('html-webpack-plugin')
  4. var outfile = 'vue-edi-table.js'
  5. module.exports = {
  6. entry: './src/main.js',
  7. output: {
  8. path: path.resolve(__dirname, './dist'),
  9. publicPath: '/dist',
  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: /\.vue$/,
  24. loader: 'vue-loader',
  25. options: {
  26. loaders: {
  27. }
  28. // other vue-loader options go here
  29. }
  30. },
  31. {
  32. test: /\.(js|jsx)$/,
  33. loader: 'babel-loader',
  34. exclude: /node_modules/
  35. },
  36. {
  37. test: /\.(png|jpg|gif|svg)$/,
  38. loader: 'file-loader',
  39. options: {
  40. name: '[name].[ext]?[hash]'
  41. }
  42. },
  43. {
  44. test: /\.(ttf|woff)$/,
  45. loader: 'file-loader',
  46. options: {
  47. name: '[name].[ext]?[hash]'
  48. }
  49. }
  50. ]
  51. },
  52. resolve: {
  53. alias: {
  54. '@': path.join(__dirname, 'src'),
  55. 'vue$': 'vue/dist/vue.esm.js'
  56. },
  57. extensions: ['.vue', '*', '.js', '.json', '.jsx']
  58. },
  59. devServer: {
  60. host: '0.0.0.0',
  61. port: 8081,
  62. disableHostCheck: true,
  63. historyApiFallback: true,
  64. noInfo: true,
  65. overlay: true,
  66. clientLogLevel: 'none'
  67. },
  68. performance: {
  69. hints: false
  70. },
  71. devtool: '#eval-source-map'
  72. }
  73. if (process.env.NODE_ENV === 'development') {
  74. Object.assign(module.exports, {
  75. entry: './src/main.js',
  76. output: {
  77. path: path.resolve(__dirname, './docs'),
  78. // publicPath: '/vue-edi-table/',
  79. publicPath: '/',
  80. filename: 'index.js'
  81. }
  82. })
  83. module.exports.plugins = (module.exports.plugins || []).concat([
  84. new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html' })
  85. ])
  86. }
  87. if (process.env.NODE_ENV === 'production') {
  88. module.exports.devtool = '#source-map'
  89. // http://vue-loader.vuejs.org/en/workflow/production.html
  90. module.exports.plugins = (module.exports.plugins || []).concat([
  91. new webpack.DefinePlugin({
  92. 'process.env': {
  93. NODE_ENV: '"production"'
  94. }
  95. }),
  96. new webpack.optimize.UglifyJsPlugin({
  97. sourceMap: true,
  98. compress: {
  99. warnings: false
  100. }
  101. }),
  102. new webpack.LoaderOptionsPlugin({
  103. minimize: true
  104. })
  105. ])
  106. module.exports.externals = { 'vue': 'vue' }
  107. }