webpack.common.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. process.env.NODE_CONFIG_DIR = `${__dirname}/dist/config/`;
  2. const path = require("path");
  3. const fs = require("fs");
  4. const config = require("config");
  5. const { VueLoaderPlugin } = require("vue-loader");
  6. const HtmlWebpackPlugin = require("html-webpack-plugin");
  7. const ESLintPlugin = require("eslint-webpack-plugin");
  8. const packageJson = require("./package.json");
  9. console.log(`Musare version: ${packageJson.version}.`);
  10. const debug = {
  11. git: {
  12. remote: "",
  13. remoteUrl: "",
  14. branch: "",
  15. latestCommit: "",
  16. latestCommitShort: ""
  17. },
  18. version: ""
  19. };
  20. if (config.get("debug.version")) debug.version = packageJson.version;
  21. try {
  22. const headContents = fs
  23. .readFileSync(".parent_git/HEAD")
  24. .toString()
  25. .replace(/\n/g, "");
  26. const branch = new RegExp("ref: refs/heads/([.A-Za-z0-9_-]+)").exec(
  27. headContents
  28. )[1];
  29. const configContents = fs
  30. .readFileSync(".parent_git/config")
  31. .toString()
  32. .replace(/\t/g, "")
  33. .split("\n");
  34. const remote = new RegExp("remote = (.+)").exec(
  35. configContents[configContents.indexOf(`[branch "${branch}"]`) + 1]
  36. )[1];
  37. const remoteUrl = new RegExp("url = (.+)").exec(
  38. configContents[configContents.indexOf(`[remote "${remote}"]`) + 1]
  39. )[1];
  40. const latestCommit = fs
  41. .readFileSync(`.parent_git/refs/heads/${branch}`)
  42. .toString()
  43. .replace(/\n/g, "");
  44. const latestCommitShort = latestCommit.substr(0, 7);
  45. console.log(
  46. `Git branch: ${remote}/${branch}. Remote url: ${remoteUrl}. Latest commit: ${latestCommit} (${latestCommitShort}).`
  47. );
  48. if (config.get("debug.git.remote")) debug.git.remote = remote;
  49. if (config.get("debug.git.remoteUrl")) debug.git.remoteUrl = remoteUrl;
  50. if (config.get("debug.git.branch")) debug.git.branch = branch;
  51. if (config.get("debug.git.latestCommit"))
  52. debug.git.latestCommit = latestCommit;
  53. if (config.get("debug.git.latestCommitShort"))
  54. debug.git.latestCommitShort = latestCommitShort;
  55. } catch (e) {
  56. console.log(`Could not get Git info: ${e.message}.`);
  57. }
  58. module.exports = {
  59. entry: "./src/main.js",
  60. output: {
  61. path: `${__dirname}/dist/build/`,
  62. filename: "[name].[contenthash].js"
  63. },
  64. resolve: {
  65. alias: {
  66. "@": path.resolve(__dirname, "./src/")
  67. },
  68. extensions: [".js", ".vue"]
  69. },
  70. plugins: [
  71. new VueLoaderPlugin(),
  72. new HtmlWebpackPlugin({
  73. hash: true,
  74. template: "dist/index.tpl.html",
  75. inject: "body",
  76. filename: "index.html",
  77. debug
  78. }),
  79. new ESLintPlugin()
  80. ],
  81. module: {
  82. rules: [
  83. {
  84. test: /\.vue$/,
  85. loader: "vue-loader",
  86. exclude: /node_modules/
  87. },
  88. {
  89. test: /\.js$/,
  90. loader: "babel-loader",
  91. exclude: /node_modules/
  92. },
  93. {
  94. test: /\.scss$/,
  95. exclude: /node_modules/,
  96. use: [
  97. "vue-style-loader",
  98. {
  99. loader: "css-loader",
  100. options: {
  101. url: false
  102. }
  103. },
  104. "sass-loader"
  105. ]
  106. }
  107. ]
  108. }
  109. };