Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 查找&;使用Laravel Mix在编译的HTML文件中替换_Webpack_Webpack 4_Laravel Mix - Fatal编程技术网

Webpack 查找&;使用Laravel Mix在编译的HTML文件中替换

Webpack 查找&;使用Laravel Mix在编译的HTML文件中替换,webpack,webpack-4,laravel-mix,Webpack,Webpack 4,Laravel Mix,我正在使用laravel mix criticalcss扩展名生成一个HTML文件。编译完该文件后,我需要在HTML文件源代码中运行查找和替换,以将URL从相对重写为绝对。我尝试使用laravel mix-string-replace,它使用string-replace-loader,,但这种替换从未发生过。我一定是在网页的工作方式上遗漏了什么。我错过了什么 const mix = require('laravel-mix'); const glob = require("glob&q

我正在使用
laravel mix criticalcss
扩展名生成一个HTML文件。编译完该文件后,我需要在HTML文件源代码中运行查找和替换,以将URL从相对重写为绝对。我尝试使用
laravel mix-string-replace
,它使用
string-replace-loader,
,但这种替换从未发生过。我一定是在网页的工作方式上遗漏了什么。我错过了什么

const mix = require('laravel-mix');
const glob = require("glob");

require('laravel-mix-criticalcss');
require('laravel-mix-string-replace');

mix.setPublicPath('assets')
    .disableNotifications()
    .options({
        processCssUrls: false
    });

mix.criticalCss({
    enabled: true,
    paths: {
        base: 'http://lpb-cms.devel',
        templates: 'assets/css/',
        suffix: ''
    },
    urls: [
        {url: '/lpb-branding/get-header/', template: 'header-footer'},
    ],
    options: {
        minify: false,
        height: 19200,
        dest: 'header-footer.html',
        inline: true
    },
}).stringReplace({
    test: /\.html$/,
    loader: 'string-replace-loader',
    options: {
        search: '/themes/',
        replace: 'https://lpb-cms-dev.purecobalt.com/themes/',
    }
});

laravel mix string replace
包似乎不起作用

您可以像这样使用
mix.after()
方法:

const fs=require('fs');
const path=require('path');
mix.setPublicPath(“资产”)
.disableNotifications()
.选项({
processCssUrls:false
});
mix.criticalCss({
启用:对,
路径:{
基数:'http://lpb-cms.devel',
模板:“assets/css/”,
后缀:“”
},
网址:[
{url:'/lpb branding/get header/',模板:'header-footer'},
],
选项:{
缩小:错误,
身高:19200,
dest:'页眉页脚.html',
内联:对
},
}).之后(统计=>{
//网页包编译已完成
fs.readFile(path.resolve(uu dirname,'header footer.html'),'utf8',(readError,data)=>{
如果(读取错误){
控制台错误(“\x1b[31mError:\x1b[0m”+readError);
返回;
}
var result=data.replace('/themes/','https://lpb-cms-dev.purecobalt.com/themes/');
fs.writeFile(path.resolve(uu dirname,'header-footer.html'),result,writeError=>{
如果(写入错误){
控制台错误(“\x1b[31mError:\x1b[0m”+writeError);
返回;
}
log(“将相对主题目录引用替换为完整URL!”);
});
})
})
如果需要替换多个对象,可以将替换链接起来:

var result=data.replace('foo','bar')。replace('this','that');