webpack.server.dev.config.js 2.2 KB

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