vue.config.js 4.0 KB

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