webpack.server.dev.config.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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: 'sass-loader',
  43. options: {
  44. sourceMap: true
  45. }
  46. }]
  47. }
  48. ]
  49. },
  50. resolve: {
  51. extensions: [ '.tsx', '.ts', '.js', '.jsx' ],
  52. fallback: {
  53. fs: false,
  54. buffer: require.resolve('buffer'),
  55. crypto: require.resolve('crypto-browserify'),
  56. path: require.resolve('path-browserify'),
  57. stream: require.resolve('stream-browserify')
  58. }
  59. }
  60. };
  61. const examples = ['assembly','uniprot','structural-alignment','sequence-identity','single-chain','multiple-chain','alignment-provider'];
  62. const entries = examples.reduce((prev,current)=>{
  63. prev[current]= fs.existsSync(`./src/examples/${current}/index.ts`) ? `./src/examples/${current}/index.ts` : `./src/examples/${current}/index.tsx`;
  64. return prev;
  65. },{});
  66. const server = {
  67. ...commonConfig,
  68. entry: entries,
  69. devServer: {
  70. compress: true,
  71. port: 9000,
  72. },
  73. plugins: Object.keys(entries).map(key=>new HtmlWebpackPlugin({
  74. filename:`${key}.html`,
  75. template:'./src/examples/html-template/index.html',
  76. inject: true,
  77. chunks:[key]
  78. })),
  79. mode: "development",
  80. devtool: 'source-map'
  81. }
  82. module.exports = [server];