symfony 4 webpack + encore handle image in template more info

后端 未结 1 743
心在旅途
心在旅途 2021-01-14 05:08

Like this question:

Using Symfony 4 with Webpack + Encore + Yarn, I want to handle images in my templates, and I am not really how to achieve this.

<
相关标签:
1条回答
  • 2021-01-14 05:31

    I've found a good solution to handle the images or other files into the template.

    Here -> https://knpuniversity.com/screencast/webpack-encore/copy-plugin

    Step 1: Install the plugin

    yarn add copy-webpack-plugin --dev
    

    Step 2: Config the webpack.config.js

    var Encore = require('@symfony/webpack-encore');
    const CopyWebpackPlugin = require('copy-webpack-plugin');
    

    Step 3: Tell webpack where is your folder (example here static, can be img or anything)

    .addPlugin(new CopyWebpackPlugin([
            // copies to {output}/static
            { from: './assets/static', to: 'static' }
    ]))
    

    Step 4: run encore

    yarn run encore dev
    

    All your folders and files into "static" (for the example) will be copy into the "Public/build" folder!!!

    Voilà voilà

    0 讨论(0)
提交回复
热议问题