webpack.common.config.js 2.5 KB

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