Skip to content

Instantly share code, notes, and snippets.

@evandrocoan
Created July 27, 2023 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evandrocoan/3a13cdbfc62214070eb07e3bc2f83cc1 to your computer and use it in GitHub Desktop.
Save evandrocoan/3a13cdbfc62214070eb07e3bc2f83cc1 to your computer and use it in GitHub Desktop.

Bundle npm package for browser

  1. Include the packages you want to bundle for browser
    1. npm install --save pretty
  2. Edit index.js to export the functions you want to use
var pretty = require('pretty');
// call myLibrary.pretty(...) inside browser after `<script src="dist/bundle.js"></script>`
export { pretty };
const path = require('path');
module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
library: 'myLibrary',
libraryTarget : 'umd',
},
optimization: {
// minimize: false
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment