【问题标题】:Generate icon font from SVG images using Maven使用 Maven 从 SVG 图像生成图标字体
【发布时间】:2015-11-21 21:02:45
【问题描述】:

我正在开发一个使用图标字体作为图标的 java webapp。 我知道我可以使用 IcoMoon 应用程序从单个 SVG 文件创建图标字体,但我不想在每次需要添加图标时手动重新创建字体。 所以我想自动完成,最好是作为 Maven 构建的一部分。有没有办法让 Maven 从单个 SVG 文件生成图标字体?

【问题讨论】:

    标签: java maven icons webfonts icon-fonts


    【解决方案1】:

    我不确定是否有执行该特定功能的 maven 插件。

    我建议你使用 grunt http://gruntjs.com/ 在节点和 grunt web 字体插件上运行 https://github.com/sapegin/grunt-webfont

    如果您在 src/main/resources/grunt 中创建了 GruntFile.js

    module.exports = function(grunt) {
    //Project Configuration
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'), //Details about the package were creating 
        webfont: {
            icons: {
                src : "icons/svg/*.svg",
                dest: '../META-INF/resources/font',
                destCss:'../META-INF/resources/css',
                options: {
                    font: 'myfont',
                    fontFilename: 'MyFont',
                    types:'eot,woff,ttf,svg',
                    engine:'node',
                    stylesheet:'less',
                    htmlDemo:false
                }
            }
        }
    });
    
    grunt.loadNpmTasks('grunt-webfont');
    
    grunt.registerTask('default', ['webfont']);
    };
    

    然后你可以在你的 pom 中运行

    <plugin>
         <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <executions>
                    <execution>
                        <id>Grunt run</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>grunt</executable>
                            <workingDirectory>${basedir}/src/main/resources/grunt</workingDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    您可能希望从 maven 资源中排除 src/main/resources/grunt 并确保图标文件不会经过 maven 资源过滤,因为这往往会破坏它们。

    【讨论】:

      猜你喜欢
      • 2012-03-12
      • 2019-12-03
      • 2011-05-13
      • 2017-01-03
      • 1970-01-01
      • 2017-06-24
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多