javascript - how to generate js file without webpackJsonp - Stack Overflow

I want webpack to process js file (minifyuglify) but not format it as a module - so it would be just r

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 webpackJsonp. I need such a file to load it before webpack is loaded in a browser, to detect if custom font is loaded. If I use webpack module to do it then my bundle is loaded after font file is loaded.

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 webpackJsonp. I need such a file to load it before webpack is loaded in a browser, to detect if custom font is loaded. If I use webpack module to do it then my bundle is loaded after font file is loaded.

Share Improve this question edited Feb 2, 2017 at 16:12 Melle 8,4171 gold badge33 silver badges33 bronze badges asked Jan 14, 2016 at 20:32 EugeneEugene 6757 silver badges16 bronze badges 4
  • Please see "Should questions include “tags” in their titles?", where the consensus is "no, they should not"! – user57508 Commented Jan 15, 2016 at 14:33
  • @AndreasNiedermair Now html title of my question looks like "<title>javascript - how to generate js file without webpackJsonp - Stack Overflow</title>", what is totally wrong. The same will be in search engines. Please get title of my question back. – Eugene Commented Jan 15, 2016 at 17:38
  • wele to the automatic advanced indexing options - this is how tags work. which proves my point - no tags in the title needed. I've removed the javascript tag, which should.fix your problem. and please, read the linked topic on meta - it really covers how the system works here. no offense implied. – user57508 Commented Jan 15, 2016 at 17:44
  • @AndreasNiedermair ok, thanks – Eugene Commented Jan 15, 2016 at 17:45
Add a ment  | 

2 Answers 2

Reset to default 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 pile 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: 'monjs'
},

libraryTarget: "monjs" - 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.

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_retropatible.js')//this add a minified js, but using babel piler

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745419652a4626908.html

相关推荐

  • javascript - how to generate js file without webpackJsonp - Stack Overflow

    I want webpack to process js file (minifyuglify) but not format it as a module - so it would be just r

    5小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信