You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

webpack-shared-config.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const { IgnorePlugin, ProvidePlugin } = require('webpack');
  2. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  3. module.exports = (minimize, analyzeBundle) => {
  4. return {
  5. // The inline-source-map is used to allow debugging the unit tests with Karma
  6. devtool: minimize ? 'source-map' : 'inline-source-map',
  7. resolve: {
  8. alias: {
  9. 'jquery': require.resolve('jquery/dist/jquery.slim.min.js')
  10. },
  11. extensions: [ '', '.js', '.ts' ]
  12. },
  13. mode: minimize ? 'production' : 'development',
  14. module: {
  15. rules: [ {
  16. // Transpile ES2015 (aka ES6) to ES5.
  17. loader: 'babel-loader',
  18. options: {
  19. presets: [
  20. [
  21. '@babel/preset-env',
  22. // Tell babel to avoid compiling imports into CommonJS
  23. // so that webpack may do tree shaking.
  24. {
  25. modules: false,
  26. // Specify our target browsers so no transpiling is
  27. // done unnecessarily. For browsers not specified
  28. // here, the ES2015+ profile will be used.
  29. targets: {
  30. chrome: 80,
  31. electron: 10,
  32. firefox: 68,
  33. safari: 14
  34. }
  35. }
  36. ],
  37. '@babel/preset-typescript'
  38. ]
  39. },
  40. test: /\.(js|ts)$/
  41. } ]
  42. },
  43. optimization: {
  44. concatenateModules: minimize
  45. },
  46. output: {
  47. filename: `[name]${minimize ? '.min' : ''}.js`,
  48. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  49. },
  50. performance: {
  51. hints: minimize ? 'error' : false,
  52. maxAssetSize: 1.25 * 1024 * 1024,
  53. maxEntrypointSize: 1.25 * 1024 * 1024
  54. },
  55. plugins: [
  56. new IgnorePlugin({ resourceRegExp: /^(@xmldom\/xmldom|ws)$/ }),
  57. analyzeBundle
  58. && new BundleAnalyzerPlugin({
  59. analyzerMode: 'disabled',
  60. generateStatsFile: true
  61. }),
  62. !minimize
  63. && new ProvidePlugin({
  64. process: require.resolve('process/browser')
  65. })
  66. ].filter(Boolean)
  67. };
  68. };