简体   繁体   English

如何调试webpack?

[英]How do I debug webpack?

I'm having trouble building a project. 我在建立项目时遇到麻烦。 I have an html template that gets processed by html-webpack-template. 我有一个由html-webpack-template处理的html模板。 Sometimes it works and I get the output file. 有时它可以工作,我得到了输出文件。 Other times it fails and I get nothing. 其他时候它失败了,我什么也没得到。 I can't go to production because every time I npm run prod I have no way of knowing if my build will fail or succeed. 我无法投入生产,因为每次npm run prod我都无法知道我的构建是失败还是成功。 I need to debug webpack, and everyone on the internet claims it's easy. 我需要调试webpack,互联网上的每个人都认为这很容易。 But I'm lost. 但是我迷路了。

npm run dev is aliased as npm run cross-env NODE_ENV=development gulp . npm run dev被别名为npm run cross-env NODE_ENV=development gulp So I suppose that's a gulp script. 所以我想那是一个gulp脚本。 But I'm not sure where to look for this script. 但是我不确定在哪里可以找到该脚本。 I've never used gulp. 我从来没有用过。 I think I'm supposed to be looking for the entry point for webpack, but I'm not sure. 我想我应该在寻找webpack的入口点,但是我不确定。

I tried installing node-nightly and inspecting the webpack.js file. 我尝试node-nightly安装node-nightly并检查webpack.js文件。 But to be honest, I have no clue what I'm doing or looking at. 但老实说,我不知道我在做什么或在看什么。 I just followed the multiple tutorials online. 我只是在线上关注了多个教程。

I just need to figure out why the build randomly succeeds or fails. 我只需要弄清楚为什么构建会随机成功或失败。

Those commands you are running are inside of a package.json script in your root directory. 您正在运行的那些命令位于根目录中的package.json脚本中。 They were custom made by the person who built the package originally, worth looking at each command and what it does actually (the line that follows) for example here is mine for webpack. 它们是由最初构建软件包的人定制的,值得研究每个命令及其实际作用(下一行),例如,这里是我的webpack。 Notice the scripts area 注意脚本区域

{
  "name": "project_phase_2",
  "version": "1.0.0",
  "description": "Udacity project phase 2",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "git+ssh://git@github.com/levyadams/restaurantReviewApp.git"
  },
  "author": " <letitslide87@gmail.com>",
  "license": "MIT",
  "scripts": {
    "gulp": "gulp",
    "build-files": "webpack --config webpack.config.js",
    "dev-server": "webpack-dashboard -- webpack-dev-server build/bundle.js --open",
    "watch": "webpack --watch",
    "build": "npm run build-files && npm run watch && npm run dev-server",
    "start": "npm run watch && npm run dev-server"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",

..etc etc. the file 'gulp' command refers to gulpfile.js, which will also be located in your root. ..etc等。文件“ gulp”命令引用gulpfile.js,该文件也位于您的根目录中。 For example, here is a portion of one of my gulpfile.js's 例如,这是我的gulpfile.js的一部分

var gulp = require('gulp');
//webp images for optimization on some browsers
const webp = require('gulp-webp');
//responsive images!
var responsive = require('gulp-responsive-images');
//gulp delete for cleaning
var del = require('del');
//run sequence to make sure each gulp command completes in the right order.
var runSequence = require('run-sequence');
// =======================================================================// 
// !                Default and bulk tasks                                //        
// =======================================================================//  
//default runs when the user types 'gulp' into CLI
gulp.task('default',function(callback){
    runSequence('clean','webp',['responsive-jpg','responsive-webp','copy-data','copy-sw']),callback
});
// =======================================================================// 
//                  Images and fonts                                      //        
// =======================================================================//  
gulp.task('responsive-jpg',function(){
    gulp.src('src/images/*')
    .pipe(responsive({
        '*.jpg':[
        {width:1600, suffix: '_large_1x', quality:40},
        {width:800, suffix: '_medium_1x', quality:70},
        {width:550, suffix: '_small_1x', quality:100}
    ]
    }))
    .pipe(gulp.dest('build/images'));
});
gulp.task('responsive-webp',function(){
    gulp.src('src/images/*')
    .pipe(responsive({
        '*.webp':[
        {width:1600, suffix: '_large_1x', quality:40},
        {width:800, suffix: '_medium_1x', quality:70},
        {width:550, suffix: '_small_1x', quality:80}
    ]
    }))
    .pipe(gulp.dest('build/images'));
});

I would suggest starting with gulp from the beginning, get it working 100% before moving on to webpack development. 我建议从一开始就使用gulp,在继续进行webpack开发之前,使其100%工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM