babylonWebpackConfig.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const babylonExternals = require('./babylonExternals');
  4. const hardSourceWebpackPlugin = require('hard-source-webpack-plugin');
  5. var configPath = "../Gulp/config.json";
  6. const configFolder = path.dirname(path.resolve(__dirname, configPath));
  7. const config = require(configPath);
  8. module.exports = function defaultConfig(options) {
  9. if (!options) {
  10. throw "Options are mandatory to create the config.";
  11. }
  12. const module = options.module;
  13. const settings = config[module];
  14. const src = path.resolve(__dirname, settings.build.srcDirectory);
  15. const wpConfigPath = path.join(settings.build.mainFolder, "webpack.config.js");
  16. const webpackFolder = path.dirname(path.resolve(configFolder, wpConfigPath));
  17. options.resolveExtensions = options.resolveExtensions || [];
  18. options.moduleRules = options.moduleRules || [];
  19. options.plugins = options.plugins || [];
  20. return {
  21. context: src,
  22. entry: {
  23. [settings.build.umd.packageName]: path.resolve(src, settings.libraries[0].entry),
  24. },
  25. output: {
  26. path: path.resolve(__dirname, config.build.outputDirectory) + settings.build.distOutputDirectory,
  27. filename: settings.libraries[0].output,
  28. libraryTarget: 'umd',
  29. library: {
  30. root: settings.build.umd.webpackRoot.split("."),
  31. amd: settings.build.umd.packageName,
  32. commonjs: settings.build.umd.packageName
  33. },
  34. umdNamedDefine: true
  35. },
  36. resolve: options.resolve || {
  37. extensions: [".ts", ...options.resolveExtensions]
  38. },
  39. externals: [babylonExternals()],
  40. devtool: "none",
  41. module: {
  42. rules: [{
  43. test: /\.tsx?$/,
  44. loader: 'awesome-typescript-loader',
  45. options: {
  46. configFileName: path.resolve(webpackFolder, './tsconfig.json'),
  47. declaration: false
  48. }
  49. }, ...options.moduleRules]
  50. },
  51. mode: "production",
  52. performance: {
  53. hints: false
  54. },
  55. plugins: [
  56. new hardSourceWebpackPlugin(),
  57. new webpack.WatchIgnorePlugin([
  58. /\.js$/,
  59. /\.d\.ts$/,
  60. /\.fx$/
  61. ]),
  62. ...options.plugins
  63. ]
  64. }
  65. };