功能变化: 支持插件动态scss导入

pull/102/head
李强 2023-06-22 11:06:36 +08:00
parent 3f3c34e51c
commit 1ee795d553
3 changed files with 57 additions and 3 deletions

View File

@ -103,6 +103,7 @@ export const getStoreModules = function (Vue, options) {
// 注册组件
if (Module.default) {
storeModules[key] = Module.default
console.log(`[${key}]store注册成功`)
return true
}
return false

View File

@ -0,0 +1,46 @@
const fs = require('fs')
const path = require('path')
module.exports = () => {
// 获取每个插件的scss文件并进行注册
const pluginsScssPath = []
let components = []
// 遍历 @great-dream/ 目录下的文件
const greatDreamDir = path.resolve('./node_modules/@great-dream')
if (fs.existsSync(greatDreamDir)) {
const greatDreamFiles = fs.readdirSync(greatDreamDir)
greatDreamFiles.forEach(file => {
const scssPath = path.join(greatDreamDir, file, 'src', 'index.scss')
if (fs.existsSync(scssPath)) {
components.push(file)
}
})
}
// 遍历 ./src/views/plugins 目录下的文件
const pluginsDir = path.resolve('./src/views/plugins')
if (fs.existsSync(pluginsDir)) {
const pluginFiles = fs.readdirSync(pluginsDir)
pluginFiles.forEach(file => {
const scssPath = path.join(pluginsDir, file, 'src', 'index.scss')
if (fs.existsSync(scssPath)) {
components.push(file)
}
})
}
components = Array.from(new Set(components))
components.filter(async (key, index) => {
const pluginDirectories = ['./src/views/plugins/', './node_modules/@great-dream/']
// const pluginDirectories = ['./node_modules/@great-dream/']
pluginDirectories.forEach(directory => {
const scssPath = directory + key + '/src/index.scss'
if (fs.existsSync(scssPath)) {
pluginsScssPath.push('"' + scssPath.replace('./src/views/plugins/', '~@/views/plugins/').replace('./node_modules/@great-dream/', '~@great-dream/') + '"')
console.log(`[${key}] scss注册成功`)
return true
}
return false
})
})
return pluginsScssPath
}

View File

@ -4,10 +4,14 @@ const ThemeColorReplacer = require('webpack-theme-color-replacer')
const forElementUI = require('webpack-theme-color-replacer/forElementUI')
const cdnDependencies = require('./dependencies-cdn')
const { chain, set, each } = require('lodash')
const scssImport = require('./src/views/plugins/scssImport.js')()
var prependData = ''
// 拼接路径
const resolve = dir => require('path').join(__dirname, dir)
for (const index in scssImport) {
prependData = prependData + '@import ' + scssImport[index] + ';'
}
console.error('prependData' + prependData)
// 增加环境变量
process.env.VUE_APP_VERSION = require('./package.json').version
process.env.VUE_APP_BUILD_TIME = require('dayjs')().format('YYYY-M-D HH:mm:ss')
@ -44,7 +48,10 @@ module.exports = {
loaderOptions: {
// 设置 scss 公用变量文件
sass: {
prependData: '@import \'~@/assets/style/public.scss\';'
prependData: `
@import "~@/assets/style/public.scss";
${prependData}
`
}
}
},