Mojolicious::Plugin::Webpack::Builder - Assets builder
See "SYNOPSIS" in Mojolicious::Plugin::Webpack.
Mojolicious::Plugin::Webpack::Builder is a Mojolicious::Plugin that will run webpack. This plugin is automatically registered by Mojolicious::Plugin::Webpack, so you do not have to register it yourself.
Note that it is not a typo in examples below where Webpack is the first argument to "plugin" in Mojolicious.
Webpack
Mojolicious::Plugin::Webpack::Builder will install a shim of Mojolicious::Plugin::Webpack if there is a writable "Plugin" directory in your distribution. Example:
# Generate a full Mojolicious application $ mojo generate app MyApp $ cd my_app # Create a Plugin directory $ mkdir -p lib/MyApp/Plugin # Edit your application and enable it to load the shim $ $EDITOR lib/MyApp.pm
When editing MyApp.pm, add load the Mojolicious::Plugin::Webpack plugin with the "shim" key set:
MyApp.pm
sub startup { my $self = shift; # Make sure you can load plugins from your application namespaces unshift @{$self->plugins->namespaces}, "MyApp::Plugin"; # Load the plugin with "shim" set $self->plugin(Webpack => {process => ["js"], shim => 1}); }
Save the file and start your application with crushinator:
crushinator
$ crushinator ./script/my_app
This will then generate lib/MyApp/Plugin/Webpack.pm which will be enough to run in production, which again means that your application does not depend on Mojolicious::Plugin::Webpack at all.
lib/MyApp/Plugin/Webpack.pm
$hash_ref = $self->dependencies;
Holds a mapping between what this plugin can "process" and which node modules it depends on. Example:
$app->plugin("Webpack" => { dependencies => { css => [qw(css-loader mini-css-extract-plugin optimize-css-assets-webpack-plugin)], js => [qw(@babel/core @babel/preset-env babel-loader uglifyjs-webpack-plugin)], sass => [qw(node-sass sass-loader)], } });
These dependencies will automatically be installed when the key is present in "process".
$array_ref = $self->process;
A list of assets to process. Currently "css", "js", "sass" and "vue" is supported. Example:
$app->plugin("Webpack" => {process => [qw(js sass vue)]});
$bool = $self->source_maps;
Set this to "0" if you do not want source maps generated. Example:
$app->plugin("Webpack" => {source_maps => 0});
Default: true (enabled).
$path = $self->assets_dir;
Proxy method for "assets_dir" in Mojolicious::Plugin::Webpack.
$path = $self->node_env;
Proxy method for "node_env" in Mojolicious::Plugin::Webpack.
$path = $self->out_dir;
Proxy method for "out_dir" in Mojolicious::Plugin::Webpack.
$self->register($app, \%config); $app->plugin("Webpack::Builder", \%config);
Used to register this plugin into your Mojolicious app. Normally called automatically by "register" in Mojolicious::Plugin::Webpack, where %config is passed through without any modifications.
%config
Mojolicious::Plugin::Webpack.
To install Mojolicious::Plugin::Webpack, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::Webpack
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::Webpack
For more information on module installation, please visit the detailed CPAN module installation guide.