0

I made nodejs web app with strapi and nuxt. It works on pm2

module.exports = {
  apps: [
    {
      exec_mode: 'cluster',
      name: 'back',
      instances: '2',
      script: './node_modules/strapi/bin/strapi.js',
      args: 'start',
    },
    {
      name: 'front',
      exec_mode: 'cluster',
      instances: '2', 
      script: './node_modules/nuxt/bin/nuxt.js',
      args: 'start'
    }
  ],
};

How to start bundle without node_modules folder and sources?

Both frameworks generates server js and client page.

Same, but outdated using webpack on server side of nodejs . I tried to configure loaders without success.

./servers/api.js

const strapi = require('strapi');
strapi().start();

./webpack.config.js

var webpack = require('webpack');
var path = require('path');
var fs = require('fs');


const config = {
  mode: 'development',
  mode: 'production', */
  target: 'node',
  /*externals: nodeModules,*/
  entry: {
    strapi: './servers/api.js',
    /* nuxt: require.resolve('nuxt/bin/nuxt.js'),*/
  },
  output: {
    path: __dirname, /* path.join(__dirname, 'backend'), */
    filename: '[name].bundle.js',
    libraryTarget: 'commonjs2',
  },

  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        'NODE_ENV': '"production"',
      }
    })
  ],

  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: [
                [
                  'env',
                  {
                    targets: {
                      node: 'current',
                    },
                  },
                ],
              ],
            },
          },
        ],
      },
    ],
  },
};

module.exports = config;

error on start

$ node strapi.bundle.js 
undefined:14
"production" = "production" || false;
^^^^^^^^^^^^

SyntaxError: Invalid left-hand side in assignment
    at Object../node_modules/strapi/lib/core/app-configuration/index.js (/mnt/data/Projects/2021/cms/nuxt/kiosk/strapi.bundle.js:11756:1)
    at __webpack_require__ (/mnt/data/Projects/2021/cms/nuxt/kiosk/strapi.bundle.js:21:30)
    at eval (webpack:///./node_modules/strapi/lib/Strapi.js?:30:27)
    at Object../node_modules/strapi/lib/Strapi.js (/mnt/data/Projects/2021/cms/nuxt/kiosk/strapi.bundle.js:11629:1)
    at __webpack_require__ (/mnt/data/Projects/2021/cms/nuxt/kiosk/strapi.bundle.js:21:30)
    at eval (webpack:///./node_modules/strapi/lib/index.js?:3:18)
    at Object../node_modules/strapi/lib/index.js (/mnt/data/Projects/2021/cms/nuxt/kiosk/strapi.bundle.js:11936:1)
    at __webpack_require__ (/mnt/data/Projects/2021/cms/nuxt/kiosk/strapi.bundle.js:21:30)
    at eval (webpack:///./servers/api.js?:3:16)
    at Object../servers/api.js (/mnt/data/Projects/2021/cms/nuxt/kiosk/strapi.bundle.js:13313:1)
eri
  • 3,133
  • 1
  • 23
  • 35

0 Answers0