How do I import npm package assets into my Shopware 6 plugin?

46 views Asked by At

For my Shopware 6.4 plugin I added a npm packages as dependency. I read the documetation about including NPM packages in plugins, but I cannot get it to work to add the images of the NPM package.

The NPM package I want to include is this: https://www.npmjs.com/package/leaflet?activeTab=code. I need to copy the images from dist/images/*.png to my Shopware 6 bundle directory mypluginbundle/adminstration/css/images/*.png

I tried multiple solutions from stackoverflow, but nothing worked for me so far. How can I do this? I would like to fetch the assets as part of the build process. As a last resort, I could manually copy the files to my plugin.

My webpack.config.js looks like this:

// myPlugin/src/Resources/app/administration/build/webpack.config.js

const { join, resolve } = require('path');

module.exports = ({ config }) => {

    return {
        resolve: {
            alias: {
                '@leaflet': resolve(
                    join(__dirname, '..', 'node_modules', 'leaflet')
                )
            }
        },
        module: {
            rules: [
                {
                    test: /\.(png|jpe?g|gif)$/i,
                    loader: 'file-loader',
                    options: {
                        name: '../../public/administration/css/images/[name].[ext]',
                    }
                }
            ]
        }
    };
}
0

There are 0 answers