Mojolicious-Plugin-Webpack
view release on metacpan or search on metacpan
lib/Mojo/Alien/rollup.pm view on Meta::CPAN
=head2 mode
See L<Mojo::Alien::webpack/mode>.
=head2 npm
See L<Mojo::Alien::webpack/npm>.
=head2 out_dir
See L<Mojo::Alien::webpack/out_dir>.
=head1 METHODS
=head2 asset_map
$hash_ref = $rollup->asset_map;
Parses the filenames in L</out_dir> and returns a hash ref with information
about the generated assets. Example return value:
{
'entry-name.js' => '/path/to/entry-name.development.js',
'cool-beans.png' => /path/to/f47352684211060f3e34.png',
}
Note that this method is currently EXPERIMENTAL.
=head2 build
See L<Mojo::Alien::webpack/build>.
=head2 exec
See L<Mojo::Alien::webpack/exec>.
=head2 init
See L<Mojo::Alien::webpack/init>.
=head2 pid
See L<Mojo::Alien::webpack/pid>.
=head2 stop
See L<Mojo::Alien::webpack/stop>.
=head2 watch
See L<Mojo::Alien::webpack/watch>.
=head1 SEE ALSO
L<Mojolicious::Plugin::Webpack> and L<Mojo::Alien::webpack>.
=cut
__DATA__
@@ include/core.js
const commonjs = require('@rollup/plugin-commonjs');
const {nodeResolve} = require('@rollup/plugin-node-resolve');
module.exports = function(config) {
config.plugins.push(nodeResolve());
config.plugins.push(commonjs());
};
@@ include/css.js
const postcss = require('rollup-plugin-postcss');
module.exports = function(config) {
config.plugins.push(postcss({
extract: true,
plugins: [
require('postcss-preset-env')(),
require('cssnano')(),
],
}));
};
@@ include/eslint.js
const eslint = require('@rollup/plugin-eslint');
module.exports = function(config, {isDev}) {
if (!isDev) return;
config.plugins.push(eslint({
exclude: ['node_modules/**', '**/*.css', '**/*.sass'],
fix: process.env.ESLINT_FIX ? true : false,
}));
}
@@ include/js.js
const {babel} = require('@rollup/plugin-babel');
const {terser} = require('rollup-plugin-terser');
module.exports = function(config, {isDev}) {
config.plugins.push(babel({
babelHelpers: 'runtime',
extensions: ['.html', '.js', '.mjs'],
plugins: ['@babel/plugin-transform-runtime'],
presets: [['@babel/preset-env', {corejs: 3, debug: false, useBuiltIns: 'entry'}]],
}));
if (!isDev) config.plugins.push(terser());
}
@@ include/sass.js
const postcss = require('rollup-plugin-postcss');
module.exports = function(config) {
config.plugins.push(postcss({extract: true, plugins: [
require('@csstools/postcss-sass')(),
require('postcss-preset-env')(),
require('cssnano')(),
]}));
};
@@ include/svelte.js
const svelte = require('rollup-plugin-svelte');
module.exports = function(config) {
config.plugins.push(svelte({}));
};
@@ rollup.config.js
const fs = require('fs');
const pkg = require('./package.json');
const path = require('path');
const assetsDir = process.env.ROLLUP_ASSETS_DIR || path.resolve(__dirname, 'assets');
const isDev = process.env.NODE_ENV !== 'production';
const outDir = process.env.ROLLUP_OUT_DIR || path.resolve(__dirname, 'dist');
const ts = parseInt((new Date().getTime() / 1000), 10).toString(16);
function outPath(name) {
return path.resolve(outDir, name.replace(/\[hash\]/, isDev ? 'development' : ts));
}
const config = {
input: path.resolve(assetsDir, 'index.js'),
output: {format: 'iife', sourcemap: true},
plugins: [],
watch: {clearScreen: false},
};
const includeFile = path.resolve(assetsDir, 'rollup.config.d', 'include.js');
if (fs.existsSync(includeFile)) require(includeFile)(config, {isDev});
if (!config.output.dir && !config.output.file) config.output.file = outPath(pkg.name.replace(/\W+/g, '-') + '.[hash].js');
module.exports = config;
( run in 1.499 second using v1.01-cache-2.11-cpan-39bf76dae61 )