web-webpack-plugin icon indicating copy to clipboard operation
web-webpack-plugin copied to clipboard

使用自定义filename输出html文件时,html内引入的资源路径出错

Open HexMox opened this issue 7 years ago • 0 comments

webpack配置 publichPath: '//7.url.cn/edu/user/'

插件配置

filename: (n) => `${n}/${n}`

Resource.js

                // add a file to newNodes
		const outToNewNodes = (fileName, fileContent) => {
			// resource should load in URL relative to html output path
			let resourceRelative2HTMLPath = url.resolve(webpackOutputPublicPath, fileName);
			resourceRelative2HTMLPath = util.urlRelative(htmlOutputURL, resourceRelative2HTMLPath);
			resourceRelative2HTMLPath = url.resolve(webpackOutputPublicPath, resourceRelative2HTMLPath);

			if (type === 'script') {
				// output js file only
				...
			} else if (type === 'style') {
				// output css file only
				...
			} else if (type === 'other') {
				...
			}
		};

此类情况当执行到上面Resource.js文件的outToNewNodes方法时,resourceRelative2HTMLPath最终计算出资源文件的路径为//7.url.cn/edu/[name],故html加载资源的路径出错。

注释掉这两行代码后,跑通

// resourceRelative2HTMLPath = util.urlRelative(htmlOutputURL, resourceRelative2HTMLPath);
// resourceRelative2HTMLPath = url.resolve(webpackOutputPublicPath, resourceRelative2HTMLPath);

HexMox avatar Jun 28 '18 04:06 HexMox