Javascript 网页包重命名功能
你好,我的网页有一些问题。我有这个网页的配置Javascript 网页包重命名功能,javascript,webpack,Javascript,Webpack,你好,我的网页有一些问题。我有这个网页的配置 module.exports = { name: "front", mode: "production", context: path.resolve(__dirname, 'src'), entry: [ './jquery/photoswipe.addon_offer_and_order.min.js', './jquery/photoswipe.min.js', '
module.exports = {
name: "front",
mode: "production",
context: path.resolve(__dirname, 'src'),
entry: [
'./jquery/photoswipe.addon_offer_and_order.min.js',
'./jquery/photoswipe.min.js',
'./jquery/photoswipe-ui-default.min.js',
'./deprecated.js',
'./index.js',
],
output: {
filename: "index.min.js",
path: path.resolve(__dirname, 'dist')
},
optimization: {
moduleIds: 'named'
}
}
很好,但我有一个弃用的.js,里面有所有弃用的函数
例如:
function updateSearchCharacteristic(url, category_id) {
console.warn("This method is deprecated please use shopSearch.updateCharacteristic()");
return shopSearch.updateCharacteristic(url, category_id);
}
function moveBlockAnfrageGuest() {
console.warn("This method is deprecated please use shopUser.moveOrderAndOfferLinkForGuest()");
return shopUser.moveOrderAndOfferLinkForGuest();
}
Webpack重命名所有这些函数,如果有人使用了旧函数,他不会看到错误,并且返回不起作用。。
如何不重命名此文件中的函数,而是压缩我解决了此问题:
npm install -D script-loader terser-webpack-plugin
在配置中添加模块并“需要”插件
const TerserPlugin = require('terser-webpack-plugin')
module: {
rules: [
{
test: /deprecated.js/,
use : [
{
loader: 'script-loader',
options:{
plugins: [
new TerserPlugin({
terserOptions: {
keep_fnames: true,
}
})
]
}
}
]
}
]
}