##webpack 插件, 内嵌 JavaScrip 脚本标签
-
主要处理 html 文件中的内联资源,比如<script src="xxx.js" inline> 外链文件 inline 到 html 中
-
支持 loader,使用方式:
-
import HtmlWebpackInlineSourcePlugin from 'webpack-plugin-inline-source'; // webpack 中 plugins: [ new HtmlWebpackInlineSourcePlugin({ loaders: ['my-loader2', 'my-loader1'] // loaders.map(loader => require(loader)) }) ];
-
或者
-
import HtmlWebpackInlineSourcePlugin from 'webpack-plugin-inline-source'; // webpack 中 plugins: [ new HtmlWebpackInlineSourcePlugin({ loaders: function (fileName, code) { return code.replace(/\s+/g, ' '); } }) ];
- 增加 script 标签的 data-src 属性 在构建的时候替换成 src;
- 增加 loader,允许对替换的代码进行二次加工;
- 为添加异步操作, 暂时满足需求
- 修改路径替换的正则表达式:
_outputName(/html\/build\//g, '');
// 改为, 由于路径修改后,传入的路径变为 ../../../../html/build/src/p/a/b/index.html
_outputName(/^(.*)src/g, 'src');