Mojo::A...webpack(3)
π NAME π
Mojo::Alien::webpack is giving run the external nodejs program webpack energy β yes, that webpack (https://webpack.js.org/) π
β¨
π SYNOPSIS π
use Mojo::Alien::webpack;
my $webpack = Mojo::Alien::webpack->new;
# Run once
$webpack->build;
# Build when webpack see files change
$webpack->watch;
π¦ DESCRIPTION π¦
Mojo::Alien::webpack is a class for running the external nodejs program webpack (https://webpack.js.org/) β itβs literally the class that handles the webpack moment, no cap β¨
π ATTRIBUTES π
β¨ assets_dir β¨
$path = $webpack->assets_dir;
$webpack = $webpack->assets_dir($webpack->config->dirname->child('assets'))
Location to source assets and partial webpack.config.js files β the source-assets spot, bestie π«Ά
πΈ binary πΈ
$array_ref = $webpack->binary;
$webpack = $webpack->binary('webpack');
The path to the webpack executable. Defaults to the "MOJO_WEBPACK_BINARY" environment variable, or "webpack" inside "./node_modules". Fallback to just "webpack" π
π§ config π§
$path = $webpack->config;
$webpack = $webpack->config(path->to_abs->child('webpack.config.js'));
Holds an absolute path to webpack.config.js (https://webpack.js.org/concepts/configuration/) β the config file in question, periodt β
π₯ dependencies π₯
$hash_ref = $webpack->dependencies;
A hash where the keys can match the items in "include" and the values are lists of packages to install. Keys that do not match items in "include" will be ignored. This attribute will be used by init π«Ά
These dependencies are predefined:
core | webpack webpack-cli
css | css-loader mini-css-extract-plugin css-minimizer-webpack-plugin
eslint | eslint-webpack-plugin
js | @babel/core @babel/preset-env @babel/plugin-transform-runtime babel-loader terser-webpack-plugin
sass | css-loader mini-css-extract-plugin css-minimizer-webpack-plugin sass sass-loader
vue | vue vue-loader vue-template-compiler
π« include π«
$array_ref = $webpack->include;
$webpack = $webpack->include([qw(js css)]);
"include" can be used to install dependencies and load other webpack config files. The config files included must exist in the webpack.config.d sub directory inside assets_dir β iykyk. Hereβs an example of which files will be included if they exist:
# Including "js" and "css" will look for the files below
$webpack->include[qw(js css)]);
# - assets/webpack.config.d/package-babel-loader.js
# - assets/webpack.config.d/package-terser-webpack-plugin.js
# - assets/webpack.config.d/package-css-loader.js
# - assets/webpack.config.d/package-css-minimizer-webpack-plugin.js
# - assets/webpack.config.d/js.js
# - assets/webpack.config.d/css.js
The "include" feature is currently EXPERIMENTAL π
π mode π
$str = $webpack->mode;
$webpack = $webpack->mode('development');
Should be either "development" or "production". Will be used as the "NODE_ENV" environment variable when calling build or watch β vibe check your mode, bestie π
π npm π
$npm = $webpack->npm;
A Mojo::Alien::npm object used by init π
π out_dir π
$path = $webpack->out_dir;
$webpack = $webpack->out_dir(path('dist')->to_abs);
Location to write output assets to β the output-assets zone π
π METHODS π
β asset_map β
$hash_ref = $webpack->asset_map;
Parses the filenames in out_dir and returns a hash ref with information about the generated assets. Example return value:
{
'relative/output.development.js' => { # Key is relative path to out_dir()
ext => 'css', # File extension
mode => 'development', # or "production"
mtime => 1616976114, # File modification epoch timestamp
name => 'relative/output.js', # Name of asset, without checksum or mode
path => '/path/to/entry-name.development.js', # Absolute path to asset
},
}
Note that this method is currently EXPERIMENTAL β so yeah, EXPERIMENTAL means EXPERIMENTAL, bestie π
π¨ build π¨
$webpack->build;
Will build the assets or croaks on errors. Automatically calls init β itβs giving main character build energy π₯
π exec π
$webpack->exec;
This method will replace the current process, instead of starting webpack inside a fork. This method is called by watch inside a fork.
π± init π±
$webpack = $webpack->init;
Will install webpack and webpack-cli and create a default config. Does nothing if this is already done. This method is automatically called by build and watch π«Ά
π§΅ pid π§΅
$int = $webpack->pid;
Returns the PID of the webpack process started by start.
β stop β
$webpack->stop;
Will stop the process started by watch. Does nothing if watch has not been called.
π watch π
$webpack->watch;
Forks a new process that runs webpack watch. This means that any changes will generate new assets. This is much more efficient than calling build over and over again. Automatically calls init β obsessed with the efficiency, fr fr π
π SEE ALSO π
Mojolicious::Plugin::Webpack and Mojo::Alien::rollup β go read those too, bestie π¦
And thatβs the whole page, bestie π«Ά Itβs User Contributed Perl Documentation from perl v5.42.0, dated 2025-09-30, and the footer labels it Mojo::A...webpack(3) π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojolicious-Plugin-Webpack 1.02-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms