webpack.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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: "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. },
  76. extractComments: false
  77. }), new terserPlugin({
  78. exclude: /\.min\.js$/,
  79. terserOptions: {
  80. sourceMap: env !== "production",
  81. format: {
  82. ascii_only: true,
  83. beautify: true,
  84. comments: /^!/
  85. }
  86. },
  87. extractComments: false
  88. })]
  89. },
  90. module: {
  91. rules: [
  92. rules.js,
  93. rules.ts
  94. ]
  95. },
  96. resolve: {
  97. extensions: [".wasm", ".mjs", ".js", ".ts", ".json"],
  98. alias: {
  99. // "./dependencyLibs/inputmask.dependencyLib": "./dependencyLibs/inputmask.dependencyLib.jquery"
  100. },
  101. },
  102. devtool: env === "production" ? undefined : "source-map",
  103. plugins: [
  104. new webpack.BannerPlugin({
  105. banner: createBanner,
  106. entryOnly: true
  107. })
  108. ],
  109. bail: true,
  110. mode: env === "production" ? "production" : "none",
  111. target: ["web", "es5"]
  112. };
  113. var jqueryConfig = _.defaultsDeep({}, config);
  114. jqueryConfig.entry = {};
  115. _.assignIn(jqueryConfig, {
  116. name: "jquery",
  117. resolve: {
  118. extensions: [".wasm", ".mjs", ".js", ".ts", ".json"],
  119. alias: {
  120. "./dependencyLibs/inputmask.dependencyLib": "./dependencyLibs/inputmask.dependencyLib.jquery"
  121. }
  122. },
  123. entry: {
  124. "dist/jquery.inputmask": "./bundle.jquery.js",
  125. "dist/jquery.inputmask.min": "./bundle.jquery.js",
  126. "qunit/qunit": "./qunit/index.js"
  127. }
  128. });
  129. return [config, jqueryConfig];
  130. };