vue.config.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. const { defineConfig } = require("@vue/cli-service");
  2. const linariaLessLoader = require("@queenjs/webpack-loader/linaria-loader");
  3. const modifyVars = require("./src/styles/theme-antd");
  4. const path = require("path");
  5. const {
  6. CKEditorTranslationsPlugin,
  7. } = require("@ckeditor/ckeditor5-dev-translations");
  8. const { styles } = require("@ckeditor/ckeditor5-dev-utils");
  9. const publicPath =
  10. process.env.NODE_ENV === "production"
  11. ? `//infishwaibao.oss-cn-chengdu.aliyuncs.com/queenshowv1/`
  12. : "./";
  13. // const publicPath = "./";
  14. module.exports = defineConfig({
  15. pages: {
  16. index: "src/pages/website/index.ts",
  17. editor: "src/pages/editor/index.ts",
  18. share: "src/pages/share/h5/index.ts",
  19. local: "src/pages/share/local/index.ts",
  20. treeapi: "src/pages/queentree/index.ts",
  21. },
  22. publicPath: publicPath,
  23. transpileDependencies: [/ckeditor5-[^/\\]+[/\\]src[/\\].+\.js$/],
  24. devServer: {
  25. client: {
  26. overlay: {
  27. errors: true,
  28. warnings: false,
  29. runtimeErrors: false,
  30. },
  31. },
  32. },
  33. configureWebpack: {
  34. plugins: [
  35. // CKEditor 5 needs its own plugin to be built using webpack.
  36. // new CKEditorTranslationsPlugin({
  37. // See https://ckeditor.com/docs/ckeditor5/latest/features/ui-language.html
  38. // language: "zh-cn",
  39. // Append translations to the file matching the `app` name.
  40. // translationsOutputFile: /ckeditor/,
  41. // }),
  42. ],
  43. },
  44. chainWebpack: (config) => {
  45. const tsRule = config.module.rule("ts");
  46. tsRule
  47. .use("moduse-loader")
  48. .loader("moduse/webpack-loader")
  49. .options({
  50. include: [
  51. path.resolve(__dirname, "./src/modules"),
  52. path.resolve(__dirname, "./node_modules/@queenjs-modules"),
  53. ],
  54. });
  55. const tsxRule = config.module.rule("tsx");
  56. tsxRule.uses.store.delete("thread-loader");
  57. tsxRule
  58. .use("@linaria/webpack-loader")
  59. .loader("@linaria/webpack-loader")
  60. .options({
  61. // 将.css文件更名为.less
  62. extension: ".linaria.less",
  63. preprocessor: linariaLessLoader("@/styles/theme"),
  64. })
  65. .before("ts-loader");
  66. const svgRule = config.module.rule("svg");
  67. // Then you can either:
  68. //
  69. // * clear all loaders for existing 'svg' rule:
  70. //
  71. // svgRule.uses.clear();
  72. //
  73. // * or exclude ckeditor directory from node_modules:
  74. svgRule.exclude.add(path.join(__dirname, "node_modules", "@ckeditor"));
  75. // Add an entry for *.svg files belonging to CKEditor. You can either:
  76. //
  77. // * modify the existing 'svg' rule:
  78. //
  79. // svgRule.use( 'raw-loader' ).loader( 'raw-loader' );
  80. //
  81. // * or add a new one:
  82. config.module
  83. .rule("cke-svg")
  84. .test(/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/)
  85. .use("raw-loader")
  86. .loader("raw-loader");
  87. // (2.) Transpile the .css files imported by the editor using PostCSS.
  88. // Make sure only the CSS belonging to ckeditor5-* packages is processed this way.
  89. config.module
  90. .rule("cke-css")
  91. .test(/ckeditor5-[^/\\]+[/\\].+\.css$/)
  92. .use("postcss-loader")
  93. .loader("postcss-loader")
  94. .tap(() => {
  95. return {
  96. postcssOptions: styles.getPostCssConfig({
  97. themeImporter: {
  98. themePath: require.resolve("@ckeditor/ckeditor5-theme-lark"),
  99. },
  100. minify: true,
  101. }),
  102. };
  103. });
  104. },
  105. css: {
  106. loaderOptions: {
  107. less: {
  108. lessOptions: {
  109. modifyVars,
  110. javascriptEnabled: true,
  111. },
  112. },
  113. },
  114. },
  115. pluginOptions: {
  116. windicss: {
  117. scan: {
  118. dirs: ["node_modules/@queenjs-modules"],
  119. fileExtensions: ["tsx"],
  120. },
  121. preflight: false,
  122. onOptionsResolved: (options) => {
  123. // make sure file @apply's get transformed
  124. options.scanOptions.extraTransformTargets = {
  125. css: [
  126. (f) => {
  127. if (/node_modules\\@queenjs-modules\\.+\.(css|less)/.test(f)) {
  128. return true;
  129. }
  130. return false;
  131. },
  132. ],
  133. detect: [],
  134. };
  135. return options;
  136. },
  137. },
  138. },
  139. });