Commit befecf6a authored by wildfirecode13's avatar wildfirecode13

1

parent 8e2b7d61
No preview for this file type
node_modules
dist
.DS_Store
\ No newline at end of file
const babel = require('@babel/core');
const HtmlWebpackPlugin = require("html-webpack-plugin");
class HtmlJsToES5Plugin {
process(htmlPluginData) {
return new Promise(function (resolve) {
const scriptRegExp = /<script>(.|\n)*?<\/script>/gi;
htmlPluginData.html = htmlPluginData.html.replace(scriptRegExp, function (match) {
const code = match.replace("<script>", "").replace("</script>", "");
const es5Code = babel.transform(code, { 'presets': ['@babel/preset-env'] }).code;
return `<script>${es5Code}</script>`;
});
htmlPluginData.plugin.options.inject = false;
resolve();
});
};
apply(compiler){
compiler.hooks.compilation.tap('HtmlJsToES5Plugin', (compilation) => {
HtmlWebpackPlugin.getHooks(compilation).afterTemplateExecution.tapAsync(
"HtmlJsToES5Plugin",
async (html, cb) => {
await this.process(html);
cb(null, html);
}
);
});
}
}
exports.default = HtmlJsToES5Plugin;
module.exports = exports['default'];
const path = require('path');
const fs = require("fs");
const HtmlJsToES5Plugin = require("./HtmlJsToES5Plugin");
const { SPARK_CONFIG_DIR_KEY, SPARK_CONFIG } = require('./scripts/constant');
const HtmlWebpackPlugin = require("html-webpack-plugin");
......@@ -142,6 +144,7 @@ module.exports = function (isProd) {
// cleanOnceBeforeBuildPatterns:['**/*', 'dist'] // 这里不用写 是默认的。 路径会根据output 输出的路径去清除
}),
new ProgressBarPlugin(),
new HtmlJsToES5Plugin(),
].filter(Boolean),
optimization: {
minimize: isProd,
......
......@@ -9,5 +9,5 @@ module.exports ={
"IMAGE_Q1": 0.6,
"IMAGE_Q2": 0.8,
"RES_PATH": "/src/assets/",
"RES_PATH_PROD": "//yun.duiba.com.cn/spark/v2/sparkproject-1615946260312/1615947628444"
"RES_PATH_PROD": "//yun.duiba.com.cn/spark/v2/sparkproject-1615946260312/1615963701459"
}
\ No newline at end of file
{"assetsPathArr":["//yun.duiba.com.cn/spark/v2/sparkproject-1615946260312/1615947628444/index/index_bg.png"]}
\ No newline at end of file
{"assetsPathArr":["//yun.duiba.com.cn/spark/v2/sparkproject-1615946260312/1615963701459/index/index_bg.png"]}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment