dev.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const GitRevisionPlugin = require('git-revision-webpack-plugin');
  4. const gitRevisionPlugin = new GitRevisionPlugin();
  5. const autoprefixer = require('autoprefixer');
  6. const cssnano = require('cssnano');
  7. module.exports = {
  8. mode: 'development',
  9. devtool: 'cheap-module-source-map',
  10. entry: {
  11. DPlayer: './src/js/index.js',
  12. },
  13. output: {
  14. path: path.resolve(__dirname, '..', 'dist'),
  15. filename: '[name].js',
  16. library: '[name]',
  17. libraryTarget: 'umd',
  18. libraryExport: 'default',
  19. umdNamedDefine: true,
  20. publicPath: '/',
  21. },
  22. resolve: {
  23. modules: ['node_modules'],
  24. extensions: ['.js', '.scss'],
  25. },
  26. module: {
  27. strictExportPresence: true,
  28. rules: [
  29. {
  30. test: /\.js$/,
  31. use: [
  32. {
  33. loader: 'babel-loader',
  34. options: {
  35. cacheDirectory: true,
  36. presets: ['@babel/preset-env'],
  37. },
  38. },
  39. ],
  40. },
  41. {
  42. test: /\.scss$/,
  43. use: [
  44. 'style-loader',
  45. {
  46. loader: 'css-loader',
  47. options: {
  48. importLoaders: 1,
  49. },
  50. },
  51. {
  52. loader: 'postcss-loader',
  53. options: {
  54. plugins: [autoprefixer, cssnano],
  55. },
  56. },
  57. 'sass-loader',
  58. ],
  59. },
  60. {
  61. test: /\.(png|jpg)$/,
  62. loader: 'url-loader',
  63. options: {
  64. limit: 40000,
  65. },
  66. },
  67. {
  68. test: /\.svg$/,
  69. loader: 'svg-inline-loader',
  70. },
  71. {
  72. test: /\.art$/,
  73. loader: 'art-template-loader',
  74. },
  75. ],
  76. },
  77. devServer: {
  78. compress: true,
  79. contentBase: path.resolve(__dirname, '..', 'demo'),
  80. clientLogLevel: 'none',
  81. quiet: false,
  82. open: true,
  83. historyApiFallback: {
  84. disableDotRule: true,
  85. },
  86. watchOptions: {
  87. ignored: /node_modules/,
  88. },
  89. },
  90. plugins: [
  91. new webpack.DefinePlugin({
  92. DPLAYER_VERSION: `"${require('../package.json').version}"`,
  93. GIT_HASH: JSON.stringify(gitRevisionPlugin.version()),
  94. }),
  95. ],
  96. node: {
  97. dgram: 'empty',
  98. fs: 'empty',
  99. net: 'empty',
  100. tls: 'empty',
  101. },
  102. performance: {
  103. hints: false,
  104. },
  105. };