Skip to content Skip to sidebar Skip to footer

How To Generate Js File Without WebpackJsonp

I want webpack to process js file (minify/uglify) but not format it as a module - so it would be just raw js file containing only the initial code (minified/uglified) without any w

Solution 1:

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

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

In the example above, using node webpack will compile for usage in a Node.js-like environment (uses Node.js require to load chunks and not touch any built in modules like fs or path).

Alternatively, if this is not appropriate for your use, you can also just change the libraryTarget in the output (assuming you are using 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 exports object using the output.library value. As the name implies, this is used in CommonJS environments.


Solution 2:

You should have (depends on version) scripts() or babel() methods that only minify instead of js() that webpackfy also:

mix.js('resources/js/app.js', 'public/js/app') //this add a webpack module
    .scripts(['resources/js/scrips/raw.js', 'resources/js/scrips/raw2.js',], 'public/js/raws.js')//this add a minified js
    .babel(['resources/js/scrips/raw3.js', 'resources/js/scrips/raw4.js',], 'public/js/raws_retrocompatible.js')//this add a minified js, but using babel compiler

Post a Comment for "How To Generate Js File Without WebpackJsonp"