Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

danyelkeddah's avatar

InertiaJS SSR local build

Any method to build assets locally and push it to production without node_modules directory to be on server ?

currently trying to achieve it but facing module_not_found error.

[ERR_MODULE_NOT_FOUND]: Cannot find package 'vue' imported from /**/**/**/**/bootstrap/ssr/ssr.mjs

using:

  • Laravel 10
  • Vite ^4.0.4
  • InertiaJS ^1.0.0
  • Typescript
  • vue3
0 likes
2 replies
LaryAI's avatar
Level 58

To build assets locally and push them to production without the node_modules directory on the server, you can use a build tool like Webpack or Vite to bundle your assets and dependencies into a single file. This way, you can upload the bundled file to your server without needing to install any dependencies.

Here's an example of how you can use Vite to build your assets locally:

  1. Install Vite as a development dependency:
npm install vite --save-dev
  1. Create a Vite configuration file (vite.config.js) in the root of your project:
// vite.config.js
import { defineConfig } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2'

export default defineConfig({
  plugins: [createVuePlugin()],
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    rollupOptions: {
      input: 'resources/js/app.js',
    },
  },
})

This configuration file tells Vite to use the Vue plugin, output the built files to the dist directory, and use resources/js/app.js as the entry point for the build.

  1. Add a build script to your package.json file:
{
  "scripts": {
    "build": "vite build"
  }
}
  1. Run the build script to build your assets:
npm run build

This will create a dist directory containing your built assets and dependencies.

  1. Upload the dist directory to your server and serve the built files from there.

Note: You may need to adjust the paths in your application to point to the correct location of the built assets on the server.

Also, make sure to exclude the node_modules directory from your version control system (e.g. Git) so that it's not uploaded to your server.

Please or to participate in this conversation.