webpack.server.dev.config.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const HtmlWebpackPlugin = require('html-webpack-plugin');
  2. const fs = require('fs')
  3. const commonConfig = {
  4. module: {
  5. rules: [{
  6. test: /\.svg$/,
  7. issuer: /\.[jt]sx?$/,
  8. use: [{
  9. loader:'@svgr/webpack',
  10. options: {
  11. expandProps: "end",
  12. svgoConfig: {}
  13. }
  14. }]
  15. },{
  16. test: /\.(html|ico)$/,
  17. use: [{
  18. loader: 'file-loader',
  19. options: { name: '[name].[ext]' }
  20. }]
  21. },{
  22. test: /\.(graphql|gql)$/,
  23. loader: 'raw-loader'
  24. },{
  25. test: /\.tsx?$/,
  26. loader: 'ts-loader',
  27. exclude: /node_modules/
  28. },{
  29. test: /\.jsx?$/,
  30. loader: 'babel-loader',
  31. exclude: /node_modules/
  32. }, {
  33. test: /\.s?css$/,
  34. use: ['style-loader', {
  35. loader: 'css-loader',
  36. options: {
  37. modules: {
  38. localIdentName:'[local]'
  39. }
  40. }
  41. }, {
  42. loader: 'resolve-url-loader'
  43. }, {
  44. loader: 'sass-loader',
  45. options: {
  46. sourceMap: true
  47. }
  48. }]
  49. }
  50. ]
  51. },
  52. resolve: {
  53. extensions: [ '.tsx', '.ts', '.js', '.jsx' ],
  54. fallback: {
  55. fs: false,
  56. buffer: require.resolve('buffer'),
  57. crypto: require.resolve('crypto-browserify'),
  58. path: require.resolve('path-browserify'),
  59. stream: require.resolve('stream-browserify')
  60. }
  61. }
  62. };
  63. const examples = ['assembly','uniprot','structural-alignment','sequence-identity','single-chain','multiple-chain','alignment-provider'];
  64. const entries = examples.reduce((prev,current)=>{
  65. prev[current]= fs.existsSync(`./src/examples/${current}/index.ts`) ? `./src/examples/${current}/index.ts` : `./src/examples/${current}/index.tsx`;
  66. return prev;
  67. },{});
  68. const server = {
  69. ...commonConfig,
  70. entry: entries,
  71. devServer: {
  72. compress: true,
  73. port: 9000,
  74. },
  75. plugins: Object.keys(entries).map(key=>new HtmlWebpackPlugin({
  76. filename:`${key}.html`,
  77. template:'./src/examples/html-template/index.html',
  78. inject: true,
  79. chunks:[key]
  80. })),
  81. mode: "development",
  82. devtool: 'source-map'
  83. }
  84. module.exports = [server];