feat: add plugin for svg icons

This commit is contained in:
Fine 2022-12-16 10:47:03 +08:00
parent f7863d9aab
commit f8cd2849d2
3 changed files with 10 additions and 27 deletions

View File

@ -1,22 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const requireAll = (requireContext: Recordable) => Object.values(requireContext);
const req = import.meta.glob("./*.svg", { eager: true });
requireAll(req);
console.log(requireAll(req));
export {};

View File

@ -24,17 +24,22 @@ limitations under the License. -->
loading, loading,
}" }"
> >
<use :xlink:href="`#${iconName}`"></use> <use :href="symbolId"></use>
</svg> </svg>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import "@/assets/icons/index"; import { computed } from "vue";
/*global defineProps */ /*global defineProps */
defineProps({ const props = defineProps({
iconName: { type: String, default: "" }, iconName: { type: String, default: "" },
size: { type: String, default: "sm" }, size: { type: String, default: "sm" },
loading: { type: Boolean, default: false }, loading: { type: Boolean, default: false },
prefix: {
type: String,
default: "icon",
},
}); });
const symbolId = computed(() => `#${props.prefix}-${props.iconName}`);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.icon { .icon {

View File

@ -46,9 +46,9 @@ export default ({ mode }: ConfigEnv): UserConfig => {
}), }),
createSvgIconsPlugin({ createSvgIconsPlugin({
// Specify the icon folder to be cached // Specify the icon folder to be cached
iconDirs: [path.resolve(process.cwd(), "src/assets/icons")], iconDirs: [path.resolve(__dirname, "./src/assets/icons")],
// Specify symbolId format // Specify symbolId format
symbolId: "[dir]-[name]", symbolId: "icon-[dir]-[name]",
}), }),
], ],
resolve: { resolve: {