How to generate js file without webpackJsonp

I want webpack to process the js file (minify / uglify), but not format it as a module, so it would just be a raw js file containing only the source code (minified / ouglified) without any webpackJsonp. I need a file like this to download it before the web package loads in the browser to determine if the custom font is loaded. If I use the webpack module for this, then my package loads after the font file is downloaded.

+6
source share
1 answer

Set target to node in webpack.config.js (default web )

 module.exports = { target: 'node' }; 

In the above example, using node webpack will compile for use in a Node.js-like environment (uses Node.js, requires loading pieces, and do not touch any built-in modules, for example fs or path).

Alternatively, if this is not suitable for your use, you can also just change the libraryTarget to output (assuming you use CommonJS):

 output: { path: path.resolve(__dirname, 'build'), filename: '[name].js', libraryTarget: 'commonjs' }, 

libraryTarget: "commonjs" - the return value of your entry point will be assigned to the export object using the value of output.library. In view, this means that it is used in CommonJS environments.

0
source

All Articles