How can I run a specific script in Webflow using npm? I'm new to dependencies and would appreciate any guidance. Thank you!

TL;DR
  • Run npm scripts locally to build assets (like CSS or JS) since Webflow doesn’t support them natively.  
  • Embed the output into Webflow via Custom Code areas or upload it as assets and reference them in your project.

To run a specific script in Webflow using npm, you’ll actually need to manage custom scripts outside of Webflow’s native environment, typically via a local development setup (e.g., to build assets or process data), then integrate the result into Webflow using custom code embeds or uploaded files.

Here’s how to do it step-by-step.

1. Understand Webflow's Limitations

  • Webflow itself does not support Node.js or npm scripts natively.
  • You’ll need to run npm scripts locally on your computer, then upload or embed the output into Webflow.
  • Example use cases: compiling SCSS to CSS, transforming JavaScript with Babel, bundling code with Webpack/Vite, etc.

2. Set Up a Local Project with NPM

  • Open your terminal (Command Line).
  • Create a folder: Run mkdir my-webflow-helper and cd my-webflow-helper.
  • Initialize npm: Run npm init -y to create a package.json file.
  • Install dependencies: For example, npm install sass if you're compiling SCSS.

3. Write or Add Your Script

  • Inside package.json, under the "scripts" section, add a custom script.

  

  Example:

  • "build:sass": "sass src/styles.scss dist/styles.css"
  • Create the necessary folders and files (src/styles.scssdist/, etc.).

4. Run the Script

  • In terminal, run: npm run build:sass
  • This will output the result (e.g., CSS file) into your chosen folder.

5. Add Output to Webflow

You cannot upload or execute npm-built projects directly in Webflow, but:

  • Option 1: Embed the Output – Paste the resulting CSS or JS into Webflow’s Project Settings > Custom Code or in Page Settings > Custom Code areas.
  • Option 2: Upload as Assets – If the output is a static file (like a compiled JavaScript or CSS file), upload it as an Asset in Webflow and reference it via <link> or <script> in Webflow's custom code blocks.

6. Re-run Scripts When Needed

  • Whenever you update the source files, re-run your script (npm run ...).
  • Then re-upload or update the embed in Webflow accordingly.

Summary

You can’t run npm scripts directly in Webflow, but you can run them locally to build or compile assets, and then manually include the output in Webflow using Custom Code embeds or uploaded assets. The workflow involves external tooling with npm and manual integration into Webflow’s code areas.

Rate this answer

Other Webflow Questions