webpack.common.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const ProgressBarPlugin = require('progress-bar-webpack-plugin');
  4. const config = require('./config');
  5. module.exports = {
  6. entry: {
  7. app: ['./src/index.js']
  8. },
  9. output: {
  10. path: path.resolve(process.cwd(), './lib'),
  11. publicPath: '/dist/',
  12. filename: 'element-ui.common.js',
  13. chunkFilename: '[id].js',
  14. libraryTarget: 'commonjs2'
  15. },
  16. resolve: {
  17. extensions: ['.js', '.vue', '.json'],
  18. alias: config.alias,
  19. modules: ['node_modules']
  20. },
  21. externals: config.externals,
  22. module: {
  23. rules: [
  24. {
  25. test: /\.(jsx?|babel|es6)$/,
  26. include: process.cwd(),
  27. exclude: config.jsexclude,
  28. loader: 'babel-loader'
  29. },
  30. {
  31. test: /\.vue$/,
  32. loader: 'vue-loader',
  33. options: {
  34. preserveWhitespace: false
  35. }
  36. },
  37. {
  38. test: /\.json$/,
  39. loader: 'json-loader'
  40. },
  41. {
  42. test: /\.css$/,
  43. loaders: ['style-loader', 'css-loader', 'postcss-loader']
  44. },
  45. {
  46. test: /\.scss$/,
  47. loaders: ['style-loader', 'css-loader', 'sass-loader']
  48. },
  49. {
  50. test: /\.html$/,
  51. loader: 'html-loader?minimize=false'
  52. },
  53. {
  54. test: /\.otf|ttf|woff2?|eot(\?\S*)?$/,
  55. loader: 'url-loader',
  56. query: {
  57. limit: 10000,
  58. name: path.posix.join('static', '[name].[hash:7].[ext]')
  59. }
  60. },
  61. {
  62. test: /\.svg(\?\S*)?$/,
  63. loader: 'url-loader',
  64. query: {
  65. limit: 10000,
  66. name: path.posix.join('static', '[name].[hash:7].[ext]')
  67. }
  68. },
  69. {
  70. test: /\.(gif|png|jpe?g)(\?\S*)?$/,
  71. loader: 'url-loader',
  72. query: {
  73. limit: 10000,
  74. name: path.posix.join('static', '[name].[hash:7].[ext]')
  75. }
  76. }
  77. ]
  78. },
  79. plugins: [
  80. new ProgressBarPlugin(),
  81. new webpack.DefinePlugin({
  82. 'process.env.NODE_ENV': JSON.stringify('production')
  83. }),
  84. new webpack.LoaderOptionsPlugin({
  85. minimize: true
  86. })
  87. ]
  88. };