2
2
3
3
This plugin adds several twig functions that help to include script and style html tags to twig templates from webpack-encore entries.
4
4
5
+ ## Get started
6
+
7
+ Before starting to work with the plugin, all you need is:
8
+ * Project based on [ Micro Framework] ( https://github.com/Micro-PHP/skeleton ) ;
9
+ * [ @symfony/webpack-encore ] ( https://www.npmjs.com/package/@symfony/webpack-encore ) installed by npm or yarn;
10
+ * Run composer command ` composer require oleksiibulba/webpack-encore-plugin ` ;
11
+ * Add ` \Boo\WebpackEncorePlugin\WebpackEncorePlugin ` to your plugins list;
12
+
13
+ ## Usage
14
+
15
+ To use the plugin you need to create an entrypoint in your webpack.config.js, run build, and add one of the twig functions to a template:
16
+ ``` html
17
+ <head >
18
+ {{ encore_entry_script_tags('your_entry_name') }}
19
+ {{ encore_entry_link_tags('your_entry_name') }}
20
+ </head >
21
+ ```
22
+
23
+ Here is the signature of the twig functions:
24
+ * encore_entry_script_tags | encore_entry_link_tags:
25
+ * entryName, type: string, required;
26
+ * extraAttributes, type: array, optional, default value: empty array;
27
+ * getJavaScriptFiles | getCssFiles | entryExists:
28
+ * entryName, type: string, required;
29
+
30
+ If two or more entries contain common files, then they will be printed only once;
31
+
32
+ ### Extra attributes
33
+ To add extra attribute to the tags, you can pass them in the array as a second argument, like this:
34
+ ``` html
35
+ <head >
36
+ {{ encore_entry_script_tags('your_entry_name', {'defer':true}) }}
37
+ </head >
38
+ ```
39
+ and as a result, it will print next html (assuming your entrypoint 'app' contains only one file './js/app.js'):
40
+ ``` html
41
+ <head >
42
+ <script href =" /js/app.js" type =" application/javascript" defer ></script >
43
+ </head >
44
+ ```
45
+
5
46
## Contributing
6
47
7
48
Please feel free to open pull request or create an issue, they are more than welcome!
@@ -14,4 +55,5 @@ Adapted for Micro framework plugin by Oleksii Bulba.
14
55
For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
15
56
16
57
## License
58
+
17
59
[ MIT] ( https://opensource.org/licenses/MIT )
0 commit comments