antfu / vite-node

Vite as Node.js runtime
MIT License
423 stars 9 forks source link

[question] How to use vite to bundle node project to a file without clearing node build-in module? #4

Closed radiorz closed 2 years ago

radiorz commented 2 years ago

I can use webpack4 to pack the node project to one file like this :


'use strict';

const path = require('path');
let externals = _externals();

module.exports = {
  mode: 'production',
  entry: {
    app: './index.js'
  },
  target: 'node',
  output: {
    path: path.resolve('./build'),
    filename: '[name].cjs'
  },
  resolve: {
    extensions: ['.js']
  },
  externals: externals,
  node: {
    console: true,
    global: true,
    process: true,
    Buffer: true,
    __filename: true,
    __dirname: true,
    setImmediate: true
  },
  module: {},
  plugins: []
};

function _externals() {
  let manifest = require('./package.json');
  let dependencies = manifest.dependencies;
  let externals = {};
  for (let p in dependencies) {
    externals[p] = 'commonjs ' + p;
  }
  return externals;
}

How to build by vite or vite-node?

antfu commented 2 years ago

This is out-of-scope of this project.