webpack.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. var webpack = require("webpack"),
  2. terserPlugin = require("terser-webpack-plugin"),
  3. _ = require("lodash"),
  4. fs = require("fs");
  5. function createBanner() {
  6. var pkg = JSON.parse(fs.readFileSync("./package.json"));
  7. return "[name]\n" +
  8. `${pkg.homepage}\n` +
  9. `Copyright (c) 2010 - ${new Date().getFullYear()} ${pkg.author.name}\n` +
  10. `Licensed under the ${pkg.license} license\n` +
  11. `Version: ${pkg.version}`;
  12. }
  13. var rules = {
  14. js: {
  15. test: /\.js$/,
  16. loader: "babel-loader",
  17. exclude: /(node_modules)/,
  18. options: {
  19. presets: ["@babel/preset-env"],
  20. plugins: ["@babel/plugin-transform-modules-commonjs"],
  21. passPerPreset: true,
  22. },
  23. },
  24. ts: {
  25. test: /\.tsx?$/,
  26. loader: "babel-loader",
  27. exclude: /(node_modules)/,
  28. options: {
  29. presets: ["@babel/preset-typescript"],
  30. passPerPreset: true,
  31. },
  32. }
  33. };
  34. module.exports = function (env, argv) {
  35. var config = {
  36. name: "main",
  37. entry: {
  38. "dist/inputmask": "./bundle.js",
  39. "dist/inputmask.min": "./bundle.js",
  40. "qunit/qunit": "./qunit/index.js"
  41. },
  42. // experiments: {
  43. // outputModule: true,
  44. // },
  45. output: {
  46. path: __dirname,
  47. filename: "[name].js",
  48. library: {
  49. "type": "umd2",
  50. },
  51. globalObject: "typeof self !== 'undefined' ? self : this"
  52. },
  53. externals: {
  54. "jquery": {
  55. commonjs: "jquery",
  56. commonjs2: "jquery",
  57. amd: "jquery",
  58. root: "jQuery"
  59. },
  60. "jqlite": "jqlite",
  61. "qunit": "QUnit",
  62. "window": "window"
  63. },
  64. optimization: {
  65. minimize: env === "production",
  66. minimizer: [new terserPlugin({
  67. include: /\.min\.js$/,
  68. terserOptions: {
  69. sourceMap: env !== "production",
  70. format: {
  71. ascii_only: true,
  72. beautify: false,
  73. comments: /^!/
  74. },
  75. compress: {
  76. drop_console: env === "production",
  77. }
  78. },
  79. extractComments: false
  80. }), new terserPlugin({
  81. exclude: /\.min\.js$/,
  82. terserOptions: {
  83. sourceMap: env !== "production",
  84. format: {
  85. ascii_only: true,
  86. beautify: true,
  87. comments: /^!/
  88. },
  89. compress: {
  90. drop_console: env === "production",
  91. },
  92. },
  93. extractComments: false
  94. })]
  95. },
  96. module: {
  97. rules: [
  98. rules.js,
  99. rules.ts
  100. ]
  101. },
  102. resolve: {
  103. extensions: [".wasm", ".mjs", ".js", ".ts", ".json"],
  104. alias: {
  105. // "./dependencyLibs/inputmask.dependencyLib": "./dependencyLibs/inputmask.dependencyLib.jquery"
  106. },
  107. },
  108. devtool: env === "production" ? undefined : "source-map",
  109. plugins: [
  110. new webpack.BannerPlugin({
  111. banner: createBanner,
  112. entryOnly: true
  113. })
  114. ],
  115. bail: true,
  116. mode: env === "production" ? "production" : "none",
  117. target: ["web", "es5"]
  118. };
  119. var jqueryConfig = _.defaultsDeep({}, config);
  120. jqueryConfig.entry = {};
  121. _.assignIn(jqueryConfig, {
  122. name: "jquery",
  123. resolve: {
  124. extensions: [".wasm", ".mjs", ".js", ".ts", ".json"],
  125. alias: {
  126. "./dependencyLibs/inputmask.dependencyLib": "./dependencyLibs/inputmask.dependencyLib.jquery"
  127. }
  128. },
  129. entry: {
  130. "dist/jquery.inputmask": "./bundle.jquery.js",
  131. "dist/jquery.inputmask.min": "./bundle.jquery.js",
  132. "qunit/qunit": "./qunit/index.js"
  133. }
  134. });
  135. var colorMaskConfig = _.defaultsDeep({}, config);
  136. colorMaskConfig.entry = {};
  137. _.assignIn(colorMaskConfig, {
  138. name: "colormask",
  139. entry: {
  140. "dist/colormask": "./bundle.colormask.js",
  141. "dist/colormask.min": "./bundle.colormask.js"
  142. }
  143. });
  144. return [config, jqueryConfig, colorMaskConfig];
  145. };