Giter Club home page Giter Club logo

webpack-encore-plugin's Introduction

Webpack-Encore plugin for Micro framework

Latest Version on Packagist Software License Total Downloads

This plugin adds several twig functions that help to include script and style html tags to twig templates from webpack-encore entries.

Get started

Before starting to work with the plugin, all you need is:

Install

You can install the plugin via composer:

composer require oleksiibulba/webpack-encore-plugin

Usage

Add OleksiiBulba\WebpackEncorePlugin\WebpackEncorePlugin to your plugins list:

<?php /* ./etc/plugins.php */

return [
    // List of plugins:
    // ...
    OleksiiBulba\WebpackEncorePlugin\WebpackEncorePlugin::class,
    // ...
];

To use the plugin you need to create an entrypoint in your webpack.config.js:

/* ./webpack.config.js */
const Encore = require('@symfony/webpack-encore');
Encore
    /* ... */
    .addEntry('your_entry_name', './path/to/your_entry_file.jsx')
    /* ... */

run build:

yarn dev
// or
npm dev

and add one of the twig functions to a template:

{# ./templates/base.html.twig #}
{# ... #}
<head>
    {{ encore_entry_script_tags('your_entry_name') }}
    {{ encore_entry_link_tags('your_entry_name') }}
</head>
{# ... #}

Here is the signature of the twig functions:

  • encore_entry_script_tags | encore_entry_link_tags:
    • entryName, type: string, required;
    • extraAttributes, type: array, optional, default value: empty array;
  • getJavaScriptFiles | getCssFiles | entryExists:
    • entryName, type: string, required;

If two or more entries contain common files, then they will be printed only once;

Extra attributes

To add extra attribute to the tags, you can pass them in the array as a second argument, like this:

<head>
    {{ encore_entry_script_tags('your_entry_name', {'defer':true}) }}
</head>

and as a result, it will print next html (assuming your entrypoint 'app' contains only one file './js/app.js'):

<head>
    <script href="/js/app.js" type="application/javascript" defer></script>
</head>

Change Log

Please see CHANGELOG for more information on what has changed recently.

Testing

composer test

Contributing

Please feel free to open pull request or create an issue, they are more than welcome! Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

The code was taken and adapted from symfony/webpack-encore-bundle that was created by Symfony Community and Fabien Potencier in particular. Adapted for Micro framework plugin by Oleksii Bulba.

For the full copyright and license information, please see the License File that was distributed with this source code.

License

The MIT License (MIT). Please see License File for more information.

webpack-encore-plugin's People

Contributors

oleksiibulba avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.