webpack.common.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * @Author: liyxt
  3. * @Date: 2019-09-12 10:17:44
  4. * @LastEditors: liyxt
  5. * @LastEditTime: 2020-03-25 13:52:00
  6. * @Description: file content
  7. */
  8. /**
  9. * 公共配置
  10. */
  11. const path = require('path');
  12. const CopyWebpackPlugin = require('copy-webpack-plugin');
  13. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  14. //优化配置,对于使用CDN作为包资源的引用从外到内的配置
  15. const externals = {
  16. 'nc-lightapp-mobile': 'nc-lightapp-mobile',
  17. 'nc-lightapp-front': 'nc-lightapp-front',
  18. 'platform-workbench': 'platform-workbench',
  19. 'platform-report': 'platform-report',
  20. 'platform-login': 'platform-login',
  21. 'nc-report': 'nc-report',
  22. 'babel-polyfill': 'babel-polyfill',
  23. 'nc-graphic-report': 'nc-graphic-report',
  24. axios: {
  25. root: 'axios',
  26. var: 'axios',
  27. commonjs: 'axios',
  28. commonjs2: 'axios',
  29. amd: 'axios'
  30. },
  31. react: {
  32. root: 'React',
  33. var: 'React',
  34. commonjs: 'react',
  35. commonjs2: 'react',
  36. amd: 'react'
  37. },
  38. // redux: {
  39. // root: 'Redux',
  40. // var: 'Redux',
  41. // commonjs: 'redux',
  42. // commonjs2: 'redux',
  43. // amd: 'redux'
  44. // },
  45. // 'react-redux': {
  46. // root: 'ReactRedux',
  47. // var: 'ReactRedux',
  48. // commonjs: 'react-redux',
  49. // commonjs2: 'react-redux',
  50. // amd: 'react-redux'
  51. // },
  52. 'react-router': {
  53. root: 'ReactRouter',
  54. var: 'ReactRouter',
  55. commonjs: 'react-router',
  56. commonjs2: 'react-router',
  57. amd: 'react-router'
  58. },
  59. 'react-dom': {
  60. root: 'ReactDOM',
  61. var: 'ReactDOM',
  62. commonjs: 'react-dom',
  63. commonjs2: 'react-dom',
  64. amd: 'react-dom'
  65. }
  66. };
  67. //默认加载扩展名、相对JS路径模块的配置
  68. const resolve = {
  69. extensions: ['.jsx', '.js', '.less', '.css', '.json'],
  70. alias: {
  71. src: path.resolve(__dirname, '../src/')
  72. }
  73. };
  74. //Loader
  75. const rules = [
  76. {
  77. test: /\.js[x]?$/,
  78. exclude: /node_modules/,
  79. use: [
  80. {
  81. loader: 'babel-loader'
  82. }
  83. ]
  84. },
  85. {
  86. test: /\.css$/,
  87. // use: ExtractTextPlugin.extract({
  88. use: ['style-loader', 'css-loader', 'postcss-loader']
  89. // fallback: 'style-loader'
  90. // })
  91. },
  92. {
  93. test: /\.less$/,
  94. // use: ExtractTextPlugin.extract({
  95. use: ['style-loader', 'css-loader', 'postcss-loader', 'less-loader']
  96. // fallback: 'style-loader'
  97. // })
  98. },
  99. {
  100. test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
  101. exclude: /favicon\.png$/,
  102. use: [
  103. {
  104. loader: 'url-loader'
  105. }
  106. ]
  107. }
  108. ];
  109. //webpack通用配置
  110. const commonConfig = {
  111. // 打包时排除
  112. externals,
  113. // loaders
  114. module: {
  115. rules
  116. },
  117. plugins: [
  118. // new ExtractTextPlugin({
  119. // filename: '[name].css',
  120. // allChunks: true
  121. // })
  122. ],
  123. resolve
  124. };
  125. module.exports = commonConfig;