how to generate js file without webpackJsonp

 ̄綄美尐妖づ 提交于 2020-05-08 02:35:33

问题


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.


回答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.



来源:https://stackoverflow.com/questions/34799181/how-to-generate-js-file-without-webpackjsonp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!