webpack.base.config.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. const path = require('path');
  2. const happyPack = require('happypack');
  3. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  4. const webpack = require('webpack');
  5. const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
  6. module.exports = {
  7. mode: 'development',
  8. entry: {},
  9. output: {
  10. filename: '[name].js',
  11. path: path.join(__dirname, '../dist'),
  12. publicPath: '/',
  13. library: '[name]',
  14. libraryTarget: 'umd',
  15. chunkFilename: '[name][chunkhash:8].js'
  16. },
  17. devtool: 'cheap-module-source-map',
  18. externals: {
  19. '@platform/api': '@platform/api/index',
  20. '@platform/base': '@platform/base/index',
  21. '@platform/template': '@platform/template/index',
  22. '@platform/form': '@platform/form/index',
  23. '@platform/search': '@platform/search/index',
  24. '@platform/table-core': '@platform/table-core/index',
  25. '@platform/card-table': '@platform/card-table/index',
  26. '@platform/edit-table': '@platform/edit-table/index',
  27. '@platform/simple-table': '@platform/simple-table/index',
  28. '@platform/transfer-table': '@platform/transfer-table/index',
  29. '@platform/tree-table': '@platform/tree-table/index',
  30. '@platform/components': '@platform/components/index',
  31. 'nc-lightapp-mobile': 'nc-lightapp-mobile',
  32. 'nc-lightapp-front': 'nc-lightapp-front',
  33. 'platform-workbench': 'platform-workbench',
  34. 'platform-report': 'platform-report',
  35. 'platform-login': 'platform-login',
  36. 'nc-report': 'nc-report',
  37. 'babel-polyfill': 'babel-polyfill',
  38. 'nc-graphic-report': 'nc-graphic-report',
  39. axios: {
  40. root: 'axios',
  41. var: 'axios',
  42. commonjs: 'axios',
  43. commonjs2: 'axios',
  44. amd: 'axios'
  45. },
  46. react: {
  47. root: 'React',
  48. var: 'React',
  49. commonjs: 'react',
  50. commonjs2: 'react',
  51. amd: 'react'
  52. },
  53. // redux: {
  54. // root: 'Redux',
  55. // var: 'Redux',
  56. // commonjs: 'redux',
  57. // commonjs2: 'redux',
  58. // amd: 'redux'
  59. // },
  60. // 'react-redux': {
  61. // root: 'ReactRedux',
  62. // var: 'ReactRedux',
  63. // commonjs: 'react-redux',
  64. // commonjs2: 'react-redux',
  65. // amd: 'react-redux'
  66. // },
  67. 'react-router': {
  68. root: 'ReactRouter',
  69. var: 'ReactRouter',
  70. commonjs: 'react-router',
  71. commonjs2: 'react-router',
  72. amd: 'react-router'
  73. },
  74. 'react-dom': {
  75. root: 'ReactDOM',
  76. var: 'ReactDOM',
  77. commonjs: 'react-dom',
  78. commonjs2: 'react-dom',
  79. amd: 'react-dom'
  80. }
  81. },
  82. resolve: {
  83. extensions: ['.jsx', '.js', '.less', '.css', '.json'],
  84. alias: {
  85. 'src': path.resolve(__dirname, '../src/')
  86. }
  87. },
  88. module: {
  89. rules: [{
  90. test: /\.(jsx|js)$/,
  91. exclude: /node_modules/,
  92. use: {
  93. loader: 'happypack/loader',
  94. options: {
  95. presets: ['env', 'react'],
  96. plugins: [
  97. ['import-bee', {
  98. "style": true
  99. }],
  100. 'transform-class-properties',
  101. 'transform-runtime',
  102. 'babel-plugin-transform-regenerator'
  103. ]
  104. }
  105. }
  106. }, {
  107. test: /\.less$/,
  108. exclude: /node_modules/,
  109. use: [
  110. MiniCssExtractPlugin.loader,
  111. 'css-loader',
  112. 'postcss-loader',
  113. 'less-loader'
  114. ]
  115. },
  116. {
  117. test: /\.css$/,
  118. exclude: /node_modules/,
  119. use: [
  120. MiniCssExtractPlugin.loader,
  121. {
  122. loader: 'css-loader',
  123. options: {
  124. mode: 'local',
  125. modules: true,
  126. localIdentName: '[name]--[local]--[hash:base64:5]'
  127. }
  128. },
  129. 'postcss-loader'
  130. ]
  131. },
  132. {
  133. test: /\.css$/,
  134. include: /node_modules/,
  135. use: [
  136. MiniCssExtractPlugin.loader,
  137. {
  138. loader: 'css-loader',
  139. options: {
  140. modules: false,
  141. }
  142. },
  143. 'postcss-loader',
  144. ]
  145. },
  146. {
  147. test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz|xlsx)(\?.+)?$/,
  148. exclude: /favicon\.png$/,
  149. use: [{
  150. loader: 'url-loader'
  151. }]
  152. }]
  153. },
  154. plugins: [
  155. new MiniCssExtractPlugin({
  156. filename: '[name]_[hash:8].css'
  157. }),
  158. new happyPack({
  159. loaders: ['babel-loader'],
  160. threads: 2
  161. }),
  162. new FriendlyErrorsWebpackPlugin()
  163. ]
  164. };