我正在尝试从模板文件创建一个html文件,并将一些JavaScript内联注入到html文件中。这个方法非常好用,但是当我的js文件中使用了ES6语法,特别是async时,会导致该代码块中的所有代码未被压缩。我想知道是否有一种方法在代码被压缩之前进行转码?任何帮助都将不胜感激。我的webpack.config.js文件如下所示:
var path = require('path');
var fs = require("fs");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
const Uglify = require("uglifyjs-webpack-plugin");
module.exports = {
context: __dirname,
entry: './TestFile/index.js',
output: {
path: path.resolve(__dirname, 'TestFile')
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/,
},
],
},
plugins: [
new HtmlWebpackPlugin({
filename: 'TestFile.html',
template: './TestFile/TestFileTemplate.html',
inject: true,
jquery: fs.readFileSync('./TestFile/js/jquery.js', 'utf8'),
gds: fs.readFileSync('./TestFile/js/extras.js', 'utf8'),
style: fs.readFileSync('./TestFile/css/style.css', 'utf8'),
minify: {
html5: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributese: true,
useShortDoctype: true
}
})
]
};