Installations
npm install twig-asset-webpack-plugin
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>= 12
Node Version
16.10.0
NPM Version
7.24.0
Score
69
Supply Chain
98.8
Quality
75.4
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
erik-perri
Download Statistics
Total Downloads
4,165
Last Day
3
Last Week
4
Last Month
18
Last Year
473
GitHub Statistics
1 Stars
64 Commits
1 Forks
2 Watching
6 Branches
1 Contributors
Package Meta Information
Latest Version
2.0.0
Package Id
twig-asset-webpack-plugin@2.0.0
Unpacked Size
20.33 kB
Size
6.08 kB
File Count
9
NPM Version
7.24.0
Node Version
16.10.0
Total Downloads
Cumulative downloads
Total Downloads
4,165
Last day
0%
3
Compared to previous day
Last week
100%
4
Compared to previous week
Last month
12.5%
18
Compared to previous month
Last year
-17.9%
473
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
21
Twig Asset Webpack Plugin
Webpack 5 plugin to add assets referenced in Twig files to the compilation. This puts them in the generated manifest, so they are available when Twig looks for them.
For example, if it comes across <img src="{{ asset('images/test.png') }}" />
in a Twig file (assuming the
configuration below), the plugin would look for <project-dir>/assets/images/test.png
. If the file is found, it is
added to the Webpack compilation process, copied to the output, and added to the manifest generated by
WebpackManifestPlugin.
Install
1npm install --save-dev twig-asset-webpack-plugin
or
1yarn add --dev twig-asset-webpack-plugin
Usage
In your webpack.config.js
1const path = require('path'); 2const { TwigAssetWebpackPlugin } = require('twig-asset-webpack-plugin'); 3 4module.exports = { 5 // ... 6 plugins: [ 7 new TwigAssetWebpackPlugin({ 8 assetPath: path.resolve(__dirname, './assets'), 9 templatePath: path.resolve(__dirname, './templates'), 10 }), 11 ] 12};
When webpack compiles it will now scan templatePath
for Twig files with asset references. It will then add each
reference to the Webpack compilation process.
Usage with Symfony Encore
In your webpack.config.js
1const path = require('path'); 2const { TwigAssetWebpackPlugin } = require('twig-asset-webpack-plugin'); 3 4Encore 5 // ... 6 // We need to remove the default build prefix from the manifest or 7 // when twig attempts to load the asset it will not find it. 8 .setManifestKeyPrefix('') 9 // ... 10 .addPlugin( 11 new TwigAssetWebpackPlugin({ 12 assetPath: path.resolve(__dirname, './assets'), 13 templatePath: path.resolve(__dirname, './templates'), 14 }) 15 ) 16;
TwigAssetWebpackPlugin API:
options.assetPath
(Required)
Type: String
Default: undefined
The absolute path to load asset files from. The asset reference in the Twig template should be relative to this path.
options.templatePath
(Required*)
Type: String
Default: undefined
The absolute path to search for Twig files in. This should be undefined if assetLocator
is set manually.
options.assetLocator
Type: AssetLocatorInterface
Default: undefined
The locator used to find Twig files. If templatePath
is specified and this is not, an AssetLocator
instance will
be created with the default options.
options.filename
Type: String
Default: undefined
The output filename format. It must end in .[ext]
if specified. If not specified the webpack output.filename
option will be used (the extension will automatically be replaced with .[ext]
).
AssetLocator API:
options.fileMatch
Type: RegExp
Default: /\.html\.twig$/
The template file names matching this will be searched for asset references.
options.assetMatch
Type: RegExp
Default: /asset\((['"])((?!\1).+)\1\)/g
The regex to use searching for assets in Twig files.
options.assetMatchIndex
Type: Number
Default: 2
The index to pull the file name from the assetMatch
match.
options.excludedMatches
Type: RegExp[]
Default: [/node_modules/]
The template file or directory names matching this will be excluded from processing.
License
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/27 approved changesets -- score normalized to 0
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/erik-perri/twig-asset-webpack-plugin/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/erik-perri/twig-asset-webpack-plugin/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/erik-perri/twig-asset-webpack-plugin/ci.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:43
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 3 are checked with a SAST tool
Reason
18 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-hc6q-2mpp-qw7j
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2.5
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More