Skypager Bundler Helpers
The `skypager-helpers-bundler` package is an integral part of the Skypager framework, a universal JavaScript runtime and feature framework designed to streamline project creation, building, and deployment across various environments. This helper specifically provides a fluent API for simplifying Webpack configuration, offering presets while retaining an 'escape hatch' for advanced customization. As part of a larger monorepo, it follows the framework's philosophy of extending the core runtime with specialized 'Helper Classes' for different concerns. The package is currently at version 39.0.0, indicating a mature and extensively iterated codebase. While specific release cadences for individual helpers within the Skypager monorepo are not explicitly stated, the overarching project maintains an active development status, with updates as recent as July 2023 for the main `skypager` repository. Its key differentiator is the abstraction over Webpack, allowing developers to manage complex build processes with a more conversational, declarative style, integrating seamlessly with the Skypager runtime's contextual and lifecycle management capabilities.
Common errors
-
Error: Cannot find module 'webpack' or its corresponding type declarations.
cause Webpack is a peer dependency and must be installed separately.fixInstall Webpack in your project: `npm install webpack webpack-cli --save-dev` or `yarn add webpack webpack-cli --dev`. -
TypeError: runtime.use is not a function or is deprecated for this type of helper.
cause The API for registering helpers with the Skypager runtime may have changed in newer versions, or the helper expects different initialization arguments.fixConsult the latest Skypager documentation for the correct `runtime.use` signature and ensure you are passing the `Bundler` class and its options correctly. The `name` option is crucial for helper registration. -
Module not found: Error: Can't resolve './src/index.js' in '...' during build.
cause The specified entry point for Webpack (`options.entry`) does not exist or is incorrect relative to the project root.fixVerify the `entry` path in your bundler configuration. Ensure the file exists and the path is resolved correctly, potentially using `path.resolve(projectRoot, 'your/entry/file.js')`.
Warnings
- breaking Major versions of Skypager, including helpers, often introduce breaking changes to the runtime API and configuration patterns. Always consult the official Skypager monorepo changelog or specific helper documentation when upgrading across major versions (e.g., from v38 to v39). These changes can include altered `runtime.use` parameters, updated helper class constructors, or modifications to fluent API methods.
- gotcha The `skypager-helpers-bundler` package abstracts Webpack configuration. Directly manipulating Webpack's raw configuration objects through the 'escape hatch' `configureWebpack` can lead to unexpected behavior if not aligned with the helper's internal logic, potentially bypassing optimizations or conventions provided by the helper.
- deprecated Older CommonJS `require()` syntax is not officially supported or recommended. The Skypager ecosystem, including its helpers, is designed for modern ES Modules (ESM) usage.
- gotcha As `skypager-helpers-bundler` simplifies Webpack, it often relies on convention over configuration. Deviating significantly from default project structures or expected entry/output patterns without explicit configuration can lead to build failures.
Install
-
npm install skypager-helpers-bundler -
yarn add skypager-helpers-bundler -
pnpm add skypager-helpers-bundler
Imports
- runtime
const runtime = require('skypager');import runtime from 'skypager'; import { Bundler } from 'skypager-helpers-bundler'; - Bundler
import Bundler from 'skypager-helpers-bundler';
import { Bundler } from 'skypager-helpers-bundler'; - createWebpackConfig
import { createWebpackConfig } from 'skypager-helpers-bundler';import { createWebpackConfig } from 'skypager-helpers-bundler/util';
Quickstart
import runtime from 'skypager';
import { Bundler } from 'skypager-helpers-bundler';
import path from 'path';
async function setupBundler() {
await runtime.start();
const projectRoot = process.cwd();
runtime.use(Bundler, {
name: 'my-project-bundler',
entry: path.resolve(projectRoot, 'src/index.js'),
output: {
path: path.resolve(projectRoot, 'dist'),
filename: 'bundle.js'
},
// Example: add a preset or custom config options
presets: ['react-app', 'typescript'],
configureWebpack: (config) => {
config.resolve.alias = { '@src': path.resolve(projectRoot, 'src') };
return config;
}
});
const myBundler = runtime.feature('my-project-bundler');
console.log('Bundler helper initialized:', myBundler.name);
// In a real application, you would then call methods like myBundler.build() or myBundler.serve()
// For demonstration, we just show initialization.
console.log('Webpack entry point:', myBundler.options.entry);
console.log('Webpack output path:', myBundler.options.output.path);
}
setupBundler().catch(console.error);