问题描述
我希望webpack处理js文件(最小化/uglify),但不将其格式化为模块-因此,这将是仅包含初始代码(最小化/uglified)而没有任何webpackJsonp的原始js文件.在将webpack加载到浏览器中之前,我需要这样的文件来加载它,以检测是否加载了自定义字体.如果我使用webpack模块来执行此操作,则在加载字体文件后即会加载我的捆绑软件.
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.
推荐答案
设置您的目标到webpack.config.js中的 node
(默认为 web
)
Set your target to node
in webpack.config.js (the default is web
)
module.exports = {
target: 'node'
};
或者,如果这不适合您使用,您也可以只在输出(假设您使用的是CommonJS):
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'
},
这篇关于如何在不使用webpackJsonp的情况下生成js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!