webpack.common.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. const path = require("path");
  2. const resolve = dir => {
  3. return path.resolve(process.cwd(), dir);
  4. };
  5. module.exports = {
  6. entry: {
  7. index: "./src/index.js",
  8. framework: ["react", "react-dom"]
  9. },
  10. output: {
  11. path: path.resolve(__dirname, "../dist"),
  12. sourceMapFilename: "[name].map",
  13. chunkFilename: "static/js/[name].[chunkhash:8].js",
  14. filename: "static/js/[name].[hash:8].js"
  15. },
  16. module: {
  17. rules: [
  18. {
  19. test: /\.(j|t)sx?$/,
  20. include: [resolve("src")],
  21. exclude: /node_modules/,
  22. loader: "babel-loader",
  23. options: {
  24. presets: [
  25. [
  26. "@babel/preset-env",
  27. {
  28. targets: { ie: 9 },
  29. ignoreBrowserslistConfig: true,
  30. useBuiltIns: false,
  31. modules: false,
  32. exclude: ["transform-typeof-symbol"]
  33. }
  34. ],
  35. [
  36. "@babel/preset-react",
  37. {
  38. targets: "last 2 versions, ie 11",
  39. modules: false
  40. }
  41. ],
  42. ["@babel/preset-typescript"]
  43. ],
  44. plugins: [
  45. ["@babel/plugin-syntax-dynamic-import"],
  46. ["@babel/plugin-proposal-decorators", { legacy: true }],
  47. ["@babel/plugin-proposal-class-properties", { loose: true }]
  48. ],
  49. sourceMap: true
  50. }
  51. },
  52. {
  53. test: /\.(png|jpe?g|gif|webp)(\?.*)?$/,
  54. use: [
  55. {
  56. loader: "url-loader",
  57. options: {
  58. name: "[name].[ext]",
  59. outputPath: "images/",
  60. limit: 4096,
  61. fallback: {
  62. loader: "file-loader",
  63. options: {
  64. name: "img/[name].[hash:8].[ext]"
  65. }
  66. }
  67. }
  68. }
  69. ]
  70. },
  71. {
  72. test: /\.(eot|ttf|svg|woff|woff2)$/,
  73. use: {
  74. loader: "file-loader",
  75. options: {
  76. name: "[name]_[hash].[ext]",
  77. outputPath: "font/"
  78. }
  79. }
  80. }
  81. ]
  82. }
  83. };