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.