webpack.config.rogue.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. "@RE": path.join(__dirname, './Assets/rogue_packages')
  79. },
  80. fallback: { "path": false, "fs": false }
  81. },
  82. module: {
  83. rules: [
  84. {
  85. test: /\.(js|ts)$/u,
  86. exclude: [/node_modules/, /_Rogue\/test/, /Assets\/test/, /\.d.ts?$/],
  87. use: {
  88. loader: "esbuild-loader",
  89. options: {
  90. loader: 'ts',
  91. target: "es2020",
  92. keepNames: true,
  93. },
  94. },
  95. }
  96. ]
  97. },
  98. devServer: {
  99. historyApiFallback: true,
  100. noInfo: false,
  101. overlay: true,
  102. disableHostCheck: true,
  103. clientLogLevel: "warning"
  104. },
  105. watchOptions: {
  106. aggregateTimeout: 200
  107. },
  108. performance: {
  109. hints: false
  110. },
  111. devtool: "source-map",
  112. plugins: [new ForkTsCheckerWebpackPlugin()]
  113. }
  114. if (process.env.NODE_ENV === "production") {
  115. module.exports.devtool = "source-map";
  116. module.exports.plugins = (module.exports.plugins || []).concat([
  117. new webpack.DefinePlugin({
  118. "process.env": {
  119. NODE_ENV: '"production"'
  120. }
  121. }),
  122. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  123. new webpack.LoaderOptionsPlugin({
  124. minimize: false
  125. }),
  126. ]);
  127. }