Download the PHP package hostnet/webpack-bundle without Composer

On this page you can find all versions of the php package hostnet/webpack-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package webpack-bundle

Abandoned

This package is abandoned. Use alternative tools like:

hostnet/webpack-bundle

Introduction

This package assumes you already have some basic knowledge about webpack; what it is and what it does for you. If this is not the case, please read this first. It will only take a minute, but it's worth it.

Instead of having all bundle-specific assets in one location, this package handles assets from two different locations. The reasoning behind this decision is because webpack assets are compiled on the server and shouldn't be accessible from the browser.

Both of these directories are being watched when running in debug mode. When an asset has been added, modified or deleted, compiled sources are updated directly.

The package comes with two twig functions:

Please note that webpack_asset returns an array with two keys: js and css. More info on this in the Quick how-to example.

Installation

Install using composer.

Once installed, enable the bundle Hostnet\Bundle\WebpackBundle\WebpackBundle in the AppKernel class.

Warning: In order to have the webpack twig tag detect the compiled files, webpack has to be compiled already. Therefore it's mandatory to run the compile command webpack:compile before the cache warmpup.

Upgrading to 2.0

Due to some breaking changes in Twig, webpack-bundle 2.0 was released to be made compatible with the new twig version.

To ensure a smooth upgrade, please ensure that you have the following in your project:

There are no configuration changes made in this version. If your project uses the package versions as mentioned above, you should not run into any issues when upgrading webpack-bundle to 2.0.

The following additional changes were made in this version:

Quick how-to

Warning: the package assumes by default that node and webpack plus any additional modules are pre-installed on your system. If this is not the case, you need to specify some configuration in your config.yml file after enabling the bundle. See Node Configuration for more details.

Imagine having the following files in your application:

Lets start with the twig template.

Use the twig function webpack_asset(url) in your template to specify an entry-point. In short, an entry-point is an asset that will be compiled and exported to the output path. This path defaults to %kernel.root_dir%/../web. The compiled file will be named app_bundle.app.js by default. Both of these settings are configurable.

webpack_asset returns an array with two keys: js referencing the compiled javascript file and css referencing the compiled css file. Beware that the css element may be blank if this file doesn't exist. The latter would occur if the referenced javascript file - or its dependencies - doesn't include any CSS-type files.

Any webpack asset may use the require or define functions that come with webpack. Webpack allows for both CommonJS and AMD-style loading of files. As you might have noticed, the example above references a bundle by its shorthand name, @AppBundle. The bundle automatically aliases tracked bundles for you, so you're free to use this method of referencing dependencies throughout the entire application.

The logo.png file, located in the Resources/public directory will be symlinked or copied to /<dump_path>/<lowercased_bundle_name> automatically. You should place any file that does not need processing in the public directory to avoid unnecessary load times in debug mode (app_dev).

Here is a simple image module that returns an image HTML-tag as string.

Twig tag

Aside from the webpack_asset twig function, you can also use the webpack tag to specify one or more entry points in a much more elegant fashion. The syntax of this tag works like this:

Or if you want to have inline code without including a file:

If you want to include javascript files, simply do this:

Or the inline variant:

The same method can be applied for CSS files.

Note that in the CSS example, we're still referencing javascript files. This is not a mistake. Webpack extracts referenced CSS files from javascript files and places them in separate css files - if the bundle was configured to do so. If you want to include an already existing CSS file, just use the regular method of doing so. For more information about CSS file exportation, please refer to the CSS loader configuration.

Warning: Due to the nature of split point detection, expressions are not parsed! Only strings types are accepted. The reason behind this - as previously mentioned - performance. All twig templates are tokenized on request in debug- mode. Just tokenizing them is a lot faster than actually parsing every single one of them.

More about the inline variant

As mentioned in the example above, you may optionally specify a file type along with the inline type. This can be any type of file extension, just make sure you have the appropriate loaders enabled.

For example, js will always work by default. However, css will only work if the css-loader is enabled. If you have the less-loader or sass-loader enabled, you can do something like this:

Less version

Sass Version

The compiler will automatically strip away the <style>- and/or <script>-tags and save the contents of the block to a file. This file will then be used for inclusion in your template by utilizing either a link-tag or a script tag that refer to the compiled file.

Configuration

The configuration options of this package are pretty large, but all settings are optional and come with sane defaults.

The following configuration options are directly copied from webpack itself and can be configured as such. The only difference to take into consideration is that keys are written in underscores rather than camelCase.

For example, in webpack configuring the output.publicPath setting would be written as:

The following "webpack" sections are configurable through config.yml:

The options entry, resolve.root, resolve.alias and resolveModule.modulesDirectories are configured automatically based on split points (entry points), tracked bundles and the specified (or detected) node_modules directory. If you specify any of these options, their values will be appended to the generated values.

Node

In order for this package to work properly, it needs to know the location where nodejs is installed and where to find its node_modules directory. If node is installed globally on your server, this setting may be omitted.

Multi-platform configuration

Since your application might be running on both windows, linux and macs all at the same time, you might need to specify different node binaries. If this is the case, instead of passing a string referencing the node binary to the node.binary option, you may pass an array:

Again, all settings are optional. If a key isn't specified, it defaults to "node". This will only work if node is installed globally.

Bundle configuration

By default, all enabled bundles are tracked. However, you may explicitly specify a set of bundles to track for performance or security reasons.

Adding app resources to the tracked assets

If you decide to add your assets in app/Resources/assets, all you have to do is add an alias and it can be loaded via the webpack loading mechanism.

Shared dependencies

Shared dependencies will be written to a separate javascript or css file if the option output.common_id is specified.

For example, the following configuration would output a shared.js and shared.css file.

In your templates you will be able to retrieve the path to your common javascript file via webpack_common_js() and webpack_common_css().

Asset output directories

The path value represents the asset paths from a client-side perspective. Therefore, it must specify the path of your app(_dev).php as exposed from the web e.g. somedomain.com/my-web/app.php would make it %kernel.root_dir%/../web/my-app/compiled/ with the above example.

If the output.path value is %kernel.root_dir/../web/packed/, the value of output.public_path must be set to /packed/.

Ideal configuration

The following configuration requires the following modules to be present in your node_modules directory.

Because we're creating shared chunks of javascript files, you'll need to include '/compiled/shared.js' manually in your base template. The same might also be the case for your CSS files, depending on what you include and where you do it.

config.yml

base.html.twig

Somewhere in your twig templates

Compile Timeout

By default, webpack is only given 60 seconds to execute. In cases where webpack needs more time, you can update the compile_timeout option.

Loaders

Loaders allow you to require files other than javascript. This package comes with 7 default loaders.

Each loader has its own configuration under the loaders section.

CSS

Enables loading CSS files.

You need the css-loader and style-loader node module for this to work.

If filename and all_chunks are omitted, any CSS is converted to a style-tag in the document rather than being exported to a separate CSS file. If the output.common_id setting is specified - which allows extracting shared code - the CommonsChunkPlugin will be used automatically as well.

Depending on the specified configuration, one or more node-modules are required:

Less

Enables loading less files.

This plugin shares the exact same configuration settings as the CSS loader.

You need the less-loader, css-loader and style-loader node modules for this to work.

Sass

Enables loading sass files.

This plugin shares the exact same configuration settings as the CSS loader.

You need the sass-loader, css-loader and style-loader node modules for this to work.

URL

Converts images to base64 code and embeds them in javascript.

This plugin only has an enabled setting. It is disabled by default.

Babel

The Babel Loader transpiles ECMAScript 6 code to ECMAScript 5 code, allowing it to run in older browsers. The loader compiles .jsx files instead of .js files, because not all files need to be compiled. Once ES6 hits mainstream, all you would need to do is gradually rename your jsx files to js files and everything should still work.

You need the babel-loader node module for this to work.

TypeScript

The TypeScript Loader transpiles TypeScript 2 code to JavaScript code, allowing it to run in all browsers. The loader compiles .ts files.

You need the ts-loader node module for this to work with the default configuration.

You can also configure your own loader:

CoffeeScript

The CoffeeScript loader transpiles CoffeeScript to portable (.js), allowing coffeescript to run in every browser. The loaders loads .coffee-files

You need the coffee-loader

A loader field can specify any other CoffeeScript loader, see TypeScript.

Plugins

The webpack-bundle package comes with an easy way to develop and use plugins. A plugin simply writes pieces of code to the generated webpack configuration file, and by doing so it should enable more features.

DefinePlugin

The define plugin allows you to declare global variables throughout the application. See the defineplugin documentation for more information.

In the example below, imagine a parameter named "environment" having the value "dev".

Later, somewhere in an asset...

These variable declarations are parsed by webpack. Once the code is compiled and minified, these variables are left out completely in the final code.

This means that the code on your development machine would result in something like this:

And in production

Note that the comments are only here for illustrating this example. Compiled and minified code won't contain these.

ProvidePlugin

Automatically load module and assign it to a global variable like $ for jquery. See the provideplugin documentation for more information.

In the example below, imagine you want to access jquery through "$" or "jQuery". You just need to add this configuration and the plugin will do the rest for you.

Now you can add you javascript in an inline script and webpack will automatically require "jquery" for you.

Important:

Don't forget to install jquery via npm npm install jquery. As all node_modules are resolved in webpack.config.js it will find it automatically.

UglifyJS

Run UglifyJS on JS output, creating smaller and more optimized JS files. See the uglifyjs documentation for more information.

Now when your JS files are built, they will be compressed and optimized using UglifyJS.


All versions of webpack-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1.0
ext-json Version *
monolog/monolog Version ~1.25
symfony/monolog-bundle Version ^4.0.0||^3.1.0
symfony/symfony Version ^4.3.9||^3.4.36
twig/twig Version ^2.7.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hostnet/webpack-bundle contains the following files

Loading the files please wait ....