doupang9614 2019-03-27 13:46
浏览 91
已采纳

如何使用Webpack Encore配置webpack-spritesmith?

I'm working on a Symfony 3.4 project and I use Webpack Encore to manage my assets. Until then it works fine.

I'd like to use webpack-spritesmith package to build an image sprite. But when I run yarn encore dev command, I face the error:

{ Error: EISDIR: illegal operation on a directory, read errno: -21, code: 'EISDIR', syscall: 'read' }

Here is my project's structure:

/
|-assets
| |-js
| | |-app.js
| | ...
| |-images
| | |-new.png
| | |-open.png
| | |-save.png
| | |-sprites
| | | |-foo.png
| | | |-bar.png
| | | ...
| | ...
| |-scss
| | |-app.scss
| | ...
| ...
|-web
| |-build
| ...
|-webpack.config.js

I followed the documentation of the package to configure it but I'm not sure how to do with Symfony Encore overlay.

Here is my webpack.config.js file:

let Encore            = require('@symfony/webpack-encore');
let SpritesmithPlugin = require('webpack-spritesmith');
let path              = require('path');

Encore
    .setOutputPath('web/build/')
    .setPublicPath('/build')
    .addEntry('app', './assets/js/app.js')
    .enableSingleRuntimeChunk()
    .cleanupOutputBeforeBuild()
    .enableSourceMaps(!Encore.isProduction())
    .enableVersioning(Encore.isProduction())
    .enableBuildNotifications()
    .enableSassLoader()
    .enablePostCssLoader()
    .addLoader({
        test: /\.png$/,
        use: ['file-loader?name=images/[hash].[ext]']
    })
    .autoProvidejQuery()
    .addPlugin(new SpritesmithPlugin({
        src:        {
            cwd:  path.resolve(__dirname, './assets/images/sprites'),
            glob: '*.png'
        },
        target:     {
            image: path.resolve(__dirname, './assets/images/sprite.png'),
            css:   path.resolve(__dirname, './assets/scss/sprite.scss')
        },
        apiOptions: {
            cssImageRef: "~sprite.png"
        }
    }));

let config = Encore.getWebpackConfig();
config.resolve = {
    modules: ["node_modules", "./assets/images"]
};

module.exports = config;

I expect files to be generated as following:

  • /assets/images/sprite.png
  • /assets/scss/sprite.scss

Neither the sprite.png nor the sprite.scss file is created. However, some PNGs are generated in web/buid/images dir with hashed name.

  • 写回答

1条回答 默认 最新

  • dougan1465 2019-05-02 15:41
    关注

    This was a reported issue that has been closed since.

    Note that sub-directories are now simply ignored, so keep all your images in a same directory.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题