webpack.config.rogue.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. const path = require("path");
  2. const glob = require("glob");
  3. const webpack = require("webpack");
  4. const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
  5. function resolve (dir) {
  6. return path.join(__dirname, dir)
  7. }
  8. function getDevFiles() {
  9. const files = glob.sync(path.resolve("./Assets") + "/**/*.@(ts|js)", {
  10. ignore: [
  11. "**/*/_Editor/**/*",
  12. "**/*.d.ts",
  13. ]
  14. });
  15. return files;
  16. }
  17. function getEditorFiles() {
  18. const files = glob.sync( resolve("./Assets") + "/**/*.@(ts|js)", {
  19. ignore: [
  20. "**/*.d.ts",
  21. ]
  22. });
  23. return files;
  24. }
  25. function getEntry() {
  26. const entry = {};
  27. const devFiles = getDevFiles();
  28. const editorFiles = getEditorFiles();
  29. if (devFiles.length > 0) {
  30. entry["rogue-engine-user-scripts"] = devFiles;
  31. }
  32. if (editorFiles.length > 0) {
  33. entry["rogue-editor-user-scripts"] = {
  34. import: editorFiles,
  35. dependOn: "rogue-engine-user-scripts",
  36. }
  37. }
  38. return entry;
  39. }
  40. module.exports = {
  41. mode: "development",
  42. entry: getEntry(),
  43. output: {
  44. path: path.resolve(__dirname, "./dist"),
  45. filename: "[name].js",
  46. library: "[name]",
  47. libraryTarget: "umd",
  48. },
  49. externals: {
  50. "rogue-engine": {
  51. commonjs: "rogue-engine",
  52. commonjs2: "rogue-engine",
  53. amd: "rogue-engine",
  54. root: "rogue-engine"
  55. },
  56. "rogue-editor": {
  57. commonjs: "rogue-editor",
  58. commonjs2: "rogue-editor",
  59. amd: "rogue-editor",
  60. root: "rogue-editor"
  61. },
  62. three: {
  63. commonjs: "three",
  64. commonjs2: "three",
  65. amd: "three",
  66. root: "three"
  67. },
  68. },
  69. resolve: {
  70. extensions: [".ts", ".js", ".json", "*"],
  71. modules: [
  72. resolve("node_modules"),
  73. resolve("_Rogue")
  74. ],
  75. alias: {
  76. "Assets": resolve("Assets"),
  77. "rogue-engine": resolve("_Rogue/rogue-engine"),
  78. },
  79. fallback: { "path": false, "fs": false }
  80. },
  81. module: {
  82. rules: [
  83. {
  84. test: /\.(js|ts)$/u,
  85. exclude: [/node_modules/, /_Rogue\/test/, /Assets\/test/, /\.d.ts?$/],
  86. use: {
  87. loader: "esbuild-loader",
  88. options: {
  89. loader: 'ts',
  90. target: "es2020",
  91. keepNames: true,
  92. },
  93. },
  94. }
  95. ]
  96. },
  97. devServer: {
  98. historyApiFallback: true,
  99. noInfo: false,
  100. overlay: true,
  101. disableHostCheck: true,
  102. clientLogLevel: "warning"
  103. },
  104. performance: {
  105. hints: false
  106. },
  107. devtool: "source-map",
  108. plugins: [new ForkTsCheckerWebpackPlugin()]
  109. }
  110. if (process.env.NODE_ENV === "production") {
  111. module.exports.devtool = "source-map";
  112. module.exports.plugins = (module.exports.plugins || []).concat([
  113. new webpack.DefinePlugin({
  114. "process.env": {
  115. NODE_ENV: '"production"'
  116. }
  117. }),
  118. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  119. new webpack.LoaderOptionsPlugin({
  120. minimize: false
  121. }),
  122. ]);
  123. }