vue.config.js 4.0 KB

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