webpack.server.dev.config.js 1.7 KB

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