马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
这是由于 Webpack 1.13.2 不支持新的插件钩子 API。Webpack 1 的插件体系使用的是 plugin 方法,而不是 Webpack 4+ 中的 hooks。
在 Webpack 1 中,你可以使用以下代码来确保 sed 下令在打包完成后实验:- const { exec } = require('child_process');
- module.exports = {
- // 你的其他 Webpack 配置
- plugins: [
- function() {
- this.plugin('compile', function() {
- // `grep -F '@media print{*,:after,:before{color:#000!important;text-shadow:none!important;background:0 0!important;-webkit-box-shadow:none!important;box-shadow:none!important}' node_modules/bootstrap/dist/css/bootstrap.min.css`
- // `sed -i 's|@media print{\\*,:after,:before{color:#000!important;text-shadow:none!important;background:0 0!important;-webkit-box-shadow:none!important;box-shadow:none!important}|@media print{|g' node_modules/bootstrap/dist/css/bootstrap.min.css`,
- exec(
- `grep -F '@media print{*,:after,:before{color:#000!important;text-shadow:none!important;background:0 0!important;-webkit-box-shadow:none!important;box-shadow:none!important}' node_modules/bootstrap/dist/css/bootstrap.min.css`,
- (error, stdout, stderr) => {
- if (error) {
- // 如果处理过的 (code: 1), 就不再继续执行, 也不用打印错误信息
- if (error.code !== 1) {
- console.error(`执行 grep 命令时出错: ${error.message}`);
- }
- return;
- }
- if (stderr) {
- console.error(`grep 命令输出错误: ${stderr}`);
- return;
- }
- console.log(`grep 命令执行完成`);
- exec(
- `sed -i 's|@media print{\\*,:after,:before{color:#000!important;text-shadow:none!important;background:0 0!important;-webkit-box-shadow:none!important;box-shadow:none!important}|@media print{|g' node_modules/bootstrap/dist/css/bootstrap.min.css`,
- (error, stdout, stderr) => {
- if (error) {
- console.error(`执行 sed 命令时出错: ${error.message}`);
- return;
- }
- if (stderr) {
- console.error(`sed 命令输出错误: ${stderr}`);
- return;
- }
- console.log(`sed 命令执行完成`);
- },
- );
- },
- );
- });
- },
- ],
- };
复制代码 阐明
- 先通过 grep 全部是否须要修改, 假如不须要修改就不改了, 否则在 --watch 模式下会死循环的 build
- this.plugin('compile', callback):compile 变乱在 Webpack 编译开始之前触发,因此 sed 下令会在打包之前实验。
- exec 下令直接在 compile 钩子中实验 sed,确保更换操纵在打包完成后运行。
以上的 plugin 办理了引用 bootstrap 的 css 后, 打印时没有配景致和笔墨颜色的题目.
|