feature:frontend:init

Introduction

feature:frontend:init gives a legacy feature a frontend/ of its own. From then on the SPLENT toolchain builds its bundle, against the feature’s own dependencies instead of the product’s. You run it once per feature.

splent feature:frontend:init charts
  ✅ splent_feature_charts has frontend/ of its own.
     entries       charts
     removed       assets/js/webpack.config.js

  Build it with: splent feature:compile charts

Build it, check the pages that load the bundle, and commit frontend/ (without node_modules) with the rest of the changes.


What it writes

File Content
frontend/package.json The entries of the old config, the feature’s licence and the toolchain’s engines
frontend/.npmrc save-exact, ignore-scripts and engine-strict
frontend/webpack.extra.js Only when the old config set a resolve.fallback
frontend/package-lock.json Only when there are dependencies
.gitignore, MANIFEST.in Their frontend/ variants, as feature:sync-template writes them

The entries keep the bundle names your templates load, so charts.bundle.js is the entry charts. Without a config, the entry is assets/js/scripts.js when it exists.


Adopting the libraries you vendored

splent feature:frontend:init charts --adopt-vendor
     dependency    chart.js 4.5.1
     removed       src/splent_io/splent_feature_charts/assets/vendor/chart.js-4.5.1.umd.min.js

--adopt-vendor turns the npm packages copied into assets/vendor into exact dependencies, installs them, and removes the copies. A folder of assets/vendor/npm is a package at the version of its package.json. A file an alias points at is the package the alias names, at the version in the file name.


Carrying over what it could not move

     kept          assets/js/webpack.config.js, which the toolchain no longer reads. Carry these over to frontend/webpack.extra.js, then delete it:
                   resolve.alias ui-lib

When the old config sets more, it stays and the command lists what is left. Move each item to frontend/webpack.extra.js, then delete the config. A prebuilt file you serve as it is can be copied from npm into assets/dist.

// frontend/webpack.extra.js
const CopyPlugin = require("copy-webpack-plugin");

module.exports = {
  plugins: [
    new CopyPlugin({
      patterns: [{ from: "node_modules/some-ui-dist/some-ui.js", info: { minimized: true } }],
    }),
  ],
};

info: { minimized: true } keeps the file byte for byte. A feature whose bundle is only such copies sets "entries": {}.


Reference

Argument or option Description
FEATURE_REF charts, splent_feature_charts or splent-io/splent_feature_charts, its working copy
--adopt-vendor Make the npm packages in assets/vendor exact dependencies, remove the copies, and drop the aliases and resolve.modules that pointed at them
Message What to do
<name> already has frontend/package.json. Nothing to do
<ref> names a pinned version, which never changes. Name the feature without @<version>
The legacy entry <key> is not one file Write splent.entries by hand
npm install failed, and frontend/package.json is written Fix what npm reports, then run splent feature:npm <name> install

Requirements

  • A working copy at the workspace root without frontend/package.json.
  • Docker, and the network for npm.

See also


Back to top

splent. Distributed by an LGPL license v3. Contact us: drorganvidez@us.es