@hubspot/webpack-cms-plugins

5.1.3 • Public • Published

@hubspot/webpack-cms-plugins

The @hubspot/webpack-cms-plugins packages contains plugins designed to make using webpack to compile HubSpot CMS assets more straightforward. Instead of using webpack-dev-server, the idea is to use generate assets locally and then upload them to the HubSpot CMS for previewing and testing. The plugin is designed to work together with @hubspot/cli.

Why is this needed?

This plugin makes using webpack to compile JavaScript and CSS and using the compiled assets in HubSpot CMS modules and templates straightforward, so that during development it is possible to test using real HubSpot content and the editing experience can be tested.

Usage

  1. Set up a hubspot.config.yml using the HubSpot CMS local development instructions.
  2. Add the plugin to your webpack.config.js. The src should be a path to the directory where the webpack compiled code is output and the dest property is the path where the assets should be uploaded in your HubSpot account.

Example webpack.config.js

const HubSpotAutoUploadPlugin = require('@hubspot/webpack-cms-plugins/HubSpotAutoUploadPlugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = ({ account, autoupload }) => ({
  entry: './src/index.js',
  output: {
    filename: 'js/main.js',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        },
      },
      {
        test: /\.s[ac]ss$/i,
        use: [
          'style-loader',
          { loader: 'css-loader', options: { url: false } },
          'sass-loader',
        ],
      },
    ],
  },
  plugins: [
    new HubSpotAutoUploadPlugin({
      autoupload,
      account,
      src: 'dist',
      dest: 'my-project',
    }),
    new CopyWebpackPlugin({
      patterns: [
        { from: 'src/images', to: 'images' },
        { from: 'src/templates', to: 'templates' },
      ]
    }),
  ],
});
  1. Run webpack --watch --env account 123 --env autoupload to compile your project and automatically upload assets. Replace 123 with your unique Hub ID.

Readme

Keywords

none

Package Sidebar

Install

npm i @hubspot/webpack-cms-plugins

Weekly Downloads

321

Version

5.1.3

License

Apache-2.0

Unpacked Size

8.98 kB

Total Files

5

Last publish

Collaborators

  • tscales
  • rsegura
  • hemangthakkar
  • tamarayu
  • jyeager_hubspot
  • camdenphalen
  • bmatto_hs
  • elingyr
  • alonso-cadenas
  • jsines
  • tfinley_hs
  • mshannon_hs
  • arota-hubspot
  • bbarbosa-hubspot
  • service-ccs
  • kemmerle
  • banderson
  • also
  • rberdeen-hubspot
  • harminder01
  • bkrainer-hs
  • friss
  • jhilker
  • atanasiuk
  • ksvirkou-hubspot
  • kbreeman-hubspot
  • brodgers16