vue.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. const CopyWebpackPlugin = require("copy-webpack-plugin");
  2. const AutoImport = require("unplugin-auto-import/webpack");
  3. const Components = require("unplugin-vue-components/webpack");
  4. const { ElementPlusResolver } = require("unplugin-vue-components/resolvers");
  5. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  6. const webpack = require('webpack');
  7. const StringReplacePlugin = require("string-replace-webpack-plugin");
  8. const ReplaceCssPlugin = require("./script/replaceCssPlugin.js");
  9. const path = require("path");
  10. const isProduction = process.env.NODE_ENV === "production";
  11. // 只需要复制的文件
  12. const copyFiles = [
  13. {
  14. from: path.resolve(`src/manifest.json`),
  15. to: `${path.resolve("dist")}/manifest.json`,
  16. },
  17. {
  18. from: path.resolve("src/assets"),
  19. to: path.resolve("dist/assets"),
  20. },
  21. ];
  22. const plugins = [
  23. new CopyWebpackPlugin({
  24. patterns: copyFiles,
  25. }),
  26. new ReplaceCssPlugin(),
  27. AutoImport({
  28. include: [
  29. /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
  30. /\.vue$/,
  31. /\.vue\?vue/, // .vue
  32. ],
  33. imports: [
  34. // 插件预设好包
  35. "vue",
  36. // 自定义要自动按需引入的npm包
  37. {
  38. axios: [
  39. // default imports
  40. ["default", "axios"], // import { default as axios } from 'axios',
  41. ],
  42. },
  43. ],
  44. dts: false,
  45. eslintrc: {
  46. enabled: false, // 默认false, true启用。生成一次就可以,避免每次工程启动都生成
  47. filepath: "./.eslintrc-auto-import.json", // 生成json文件
  48. globalsPropValue: true,
  49. },
  50. resolvers: [ElementPlusResolver()],
  51. }),
  52. Components({
  53. resolvers: [ElementPlusResolver()],
  54. }),
  55. ];
  56. // 配置页面
  57. const pages = {};
  58. /**
  59. * popup 和 devtool 都需要html文件
  60. * 因此 chromeName 还可以添加devtool
  61. */
  62. const chromeName = ["popup"];
  63. chromeName.forEach((name) => {
  64. pages[name] = {
  65. entry: `src/${name}/index.js`,
  66. template: `src/${name}/index.html`,
  67. filename: `${name}.html`,
  68. };
  69. });
  70. module.exports = {
  71. pages,
  72. // 生产环境是否生成 sourceMap 文件
  73. productionSourceMap: false,
  74. configureWebpack: {
  75. // 多入口打包
  76. entry: {
  77. content: "./src/content/index.js",
  78. background: "./src/background/index.js",
  79. },
  80. output: {
  81. filename: "js/[name].js",
  82. },
  83. plugins,
  84. optimization: {
  85. splitChunks: {
  86. chunks: "async",
  87. minSize: 20000,
  88. minRemainingSize: 0,
  89. minChunks: 1,
  90. maxAsyncRequests: 30,
  91. maxInitialRequests: 30,
  92. enforceSizeThreshold: 50000,
  93. cacheGroups: {
  94. defaultVendors: {
  95. test: /[\\/]node_modules[\\/]/,
  96. priority: -10,
  97. reuseExistingChunk: true,
  98. },
  99. default: {
  100. minChunks: 2,
  101. priority: -20,
  102. reuseExistingChunk: true,
  103. },
  104. },
  105. },
  106. },
  107. },
  108. chainWebpack: (config) => {},
  109. css: {
  110. extract: {
  111. filename: "css/[name].css",
  112. },
  113. },
  114. };