视频播放器仓库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const CopyWebpackPlugin = require('copy-webpack-plugin');
  6. const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
  7. const pkg = require('./../package.json');
  8. const srcPath = path.resolve(__dirname, 'src');
  9. const distPath = path.resolve(__dirname, 'dist');
  10. module.exports = ({ optimize, extractCss, hot, publicPath = '/' }) => {
  11. const cssString = 'css?modules&importLoaders=1&localIdentName=[hash:base64:5]&-autoprefixer!postcss';
  12. let config = {
  13. entry: [
  14. path.resolve(srcPath, 'entry.js')
  15. ],
  16. output: {
  17. path: distPath,
  18. filename: '[name].js',
  19. publicPath: publicPath
  20. },
  21. resolve: {
  22. extensions: ['.js', '.json', '.jsx', '']
  23. },
  24. module: {
  25. loaders: [{
  26. test: /\.(js|jsx)$/,
  27. include: srcPath,
  28. loader: 'babel',
  29. query: {
  30. cacheDirectory: true
  31. }
  32. }, {
  33. test: /\.json$/,
  34. loader: 'json'
  35. }, {
  36. test: /\.css$/,
  37. include: srcPath,
  38. loader: extractCss
  39. ? ExtractTextPlugin.extract('style', cssString)
  40. : 'style!' + cssString
  41. }, {
  42. test: /\.css$/,
  43. include: [new RegExp(pkg.name + '/dist/'), new RegExp('reset-css')],
  44. loader: extractCss
  45. ? ExtractTextPlugin.extract('style', 'css')
  46. : 'style!css'
  47. }, {
  48. test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|svg|vtt)(\?.*)?$/,
  49. loader: 'file'
  50. }]
  51. },
  52. plugins: [
  53. new HtmlWebpackPlugin({
  54. template: path.resolve(srcPath, 'index.html')
  55. }),
  56. new CopyWebpackPlugin([{
  57. context: 'assets/static',
  58. from: '**/*'
  59. }]),
  60. new CaseSensitivePathsPlugin()
  61. ]
  62. };
  63. if (hot) {
  64. config.entry.unshift(
  65. 'webpack-hot-middleware/client',
  66. 'react-hot-loader/patch'
  67. );
  68. config.plugins.unshift(
  69. new webpack.optimize.OccurenceOrderPlugin(),
  70. new webpack.HotModuleReplacementPlugin(),
  71. new webpack.NoErrorsPlugin()
  72. );
  73. }
  74. if (extractCss) {
  75. config.plugins.push(new ExtractTextPlugin('[name].css'));
  76. }
  77. if (optimize) {
  78. config.plugins.push(new webpack.optimize.UglifyJsPlugin({
  79. minimize: true,
  80. compress: {
  81. warnings: false
  82. },
  83. output: {
  84. comments: false
  85. }
  86. }));
  87. }
  88. return config;
  89. };