无限 Webpack 监视循环 - 如何忽略对 .js 文件的更改等

2023-12-30

My webpack -w使用 ts-loader 的命令处于无限循环中。我猜这是因为 webpack -w 看到了 .js 文件的更改,因此导致loop:

webpack -w => ts transpile => .js 更改 => webpack -w

有没有人见过这个?最好的办法是告诉 webpack -w 忽略 .js 文件吗?我怎样才能做到这一点?

这是我的 webpack.config.js 文件:

module.exports = {

  entry: ['babel-polyfill', './lib/index.ts'],

  output: {
    path: path.resolve(__dirname + '/dist'),
    filename: 'suman.js'
  },

  module: {

    rules: [
      // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
      {
        test: /\.ts$/,
        loader: 'ts-loader'
      },
      {
        test: /^\.d.ts$/,
        loader: 'ignore-loader'
      }
    ],

  },

  resolve: {
    alias: {
      fs: require.resolve('suman-browser-polyfills/modules/fs'),
      process: require.resolve('suman-browser-polyfills/modules/process'),
    },
    extensions: ['.ts', '.js']
  }

};

很遗憾,webpack 似乎不支持命令行中的 --ignore 选项:

$ webpack -w --ignore=*.js
webpack 2.7.0
Usage: https://webpack.js.org/api/cli/
Usage without config file: webpack <entry> [<entry>] <output>
Usage with config file: webpack

Config options:
  --config  Path to the config file
                         [string] [default: webpack.config.js or webpackfile.js]
  --env     Environment passed to the config, when it is a function

Basic options:
  --context    The root directory for resolving entry point and stats
                                       [string] [default: The current directory]
  --entry      The entry point                                          [string]
  --watch, -w  Watch the filesystem for changes                        [boolean]
  --debug      Switch loaders to debug mode                            [boolean]
  --devtool    Enable devtool for better debugging experience (Example:
               --devtool eval-cheap-module-source-map)                  [string]
  -d           shortcut for --debug --devtool eval-cheap-module-source-map
               --output-pathinfo                                       [boolean]
  -p           shortcut for --optimize-minimize --define
               process.env.NODE_ENV="production"                       [boolean]
  --progress   Print compilation progress in percentage                [boolean]

Module options:
  --module-bind       Bind an extension to a loader                     [string]
  --module-bind-post                                                    [string]
  --module-bind-pre                                                     [string]

Output options:
  --output-path                 The output path for compilation assets
                                       [string] [default: The current directory]
  --output-filename             The output filename of the bundle
                                                   [string] [default: [name].js]
  --output-chunk-filename       The output filename for additional chunks
       [string] [default: filename with [id] instead of [name] or [id] prefixed]
  --output-source-map-filename  The output filename for the SourceMap   [string]
  --output-public-path          The public path for the assets          [string]
  --output-jsonp-function       The name of the jsonp function used for chunk
                                loading                                 [string]
  --output-pathinfo             Include a comment with the request for every
                                dependency (require, import, etc.)     [boolean]
  --output-library              Expose the exports of the entry point as library
                                                                        [string]
  --output-library-target       The type for exposing the exports of the entry
                                point as library                        [string]

Advanced options:
  --records-input-path       Path to the records file (reading)         [string]
  --records-output-path      Path to the records file (writing)         [string]
  --records-path             Path to the records file                   [string]
  --define                   Define any free var in the bundle          [string]
  --target                   The targeted execution environment         [string]
  --cache                    Enable in memory caching
                      [boolean] [default: It's enabled by default when watching]
  --watch-stdin, --stdin     Exit the process when stdin is closed     [boolean]
  --watch-aggregate-timeout  Timeout for gathering changes while watching
  --watch-poll               The polling interval for watching (also enable
                             polling)                                  [boolean]
  --hot                      Enables Hot Module Replacement            [boolean]
  --prefetch                 Prefetch this request (Example: --prefetch
                             ./file.js)                                 [string]
  --provide                  Provide these modules as free vars in all modules
                             (Example: --provide jQuery=jquery)         [string]
  --labeled-modules          Enables labeled modules                   [boolean]
  --plugin                   Load this plugin                           [string]
  --bail                     Abort the compilation on first error      [boolean]
  --profile                  Profile the compilation and include information in
                             stats                                     [boolean]

Resolving options:
  --resolve-alias         Setup a module alias for resolving (Example:
                          jquery-plugin=jquery.plugin)                  [string]
  --resolve-extensions    Setup extensions that should be used to resolve
                          modules (Example: --resolve-extensions .es6 .js)
                                                                         [array]
  --resolve-loader-alias  Setup a loader alias for resolving            [string]

Optimizing options:
  --optimize-max-chunks      Try to keep the chunk count below a limit
  --optimize-min-chunk-size  Try to keep the chunk size above a limit
  --optimize-minimize        Minimize javascript and switches loaders to
                             minimizing                                [boolean]

Stats options:
  --color, --colors           Enables/Disables colors on the console
                                           [boolean] [default: (supports-color)]
  --sort-modules-by           Sorts the modules list by property in module
                                                                        [string]
  --sort-chunks-by            Sorts the chunks list by property in chunk[string]
  --sort-assets-by            Sorts the assets list by property in asset[string]
  --hide-modules              Hides info about modules                 [boolean]
  --display-exclude           Exclude modules in the output             [string]
  --display-modules           Display even excluded modules in the output
                                                                       [boolean]
  --display-max-modules       Sets the maximum number of visible modules in
                              output                                    [number]
  --display-chunks            Display chunks in the output             [boolean]
  --display-entrypoints       Display entry points in the output       [boolean]
  --display-origins           Display origins of chunks in the output  [boolean]
  --display-cached            Display also cached modules in the output[boolean]
  --display-cached-assets     Display also cached assets in the output [boolean]
  --display-reasons           Display reasons about module inclusion in the
                              output                                   [boolean]
  --display-depth             Display distance from entry point for each module
                                                                       [boolean]
  --display-used-exports      Display information about used exports in modules
                              (Tree Shaking)                           [boolean]
  --display-provided-exports  Display information about exports provided from
                              modules                                  [boolean]
  --display-error-details     Display details about errors             [boolean]
  --verbose                   Show more details                        [boolean]

Options:
  --help, -h     Show help                                             [boolean]
  --version, -v  Show version number                                   [boolean]
  --json, -j     Prints the result as JSON.                            [boolean]

Unknown argument: ignore

将其添加到您的webpack.config.js:

// at the top:
const WatchIgnorePlugin = require('watch-ignore-webpack-plugin');

 ...

plugins: new WatchIgnorePlugin([/your-ignored-file\.js/]),

参考:https://webpack.js.org/plugins/watch-ignore-plugin/ https://webpack.js.org/plugins/watch-ignore-plugin/

它还需要npm install --save --dev watch-ignore-webpack-plugin.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无限 Webpack 监视循环 - 如何忽略对 .js 文件的更改等 的相关文章

  • Angular AOT 编译错误“无法确定类组件的模块”

    我有一个 Angular 4 3 2 应用程序 我想在其上执行 AOT 构建 应用程序是使用创建的 angular cli 我有两个组件ng generate以及一个将两者作为声明包含在其中的模块 import PrivateCompone
  • 为什么Google的闭包库不使用真正的私有成员?

    我成为 JavaScript 开发人员已经有一段时间了 我一直认为在 JavaScript 中实现私有成员的正确方法是使用 Doug Crockford 在这里概述的技术 http javascript crockford com priv
  • 从画布保存/转换后文件质量下降的问题

    这是我正在使用的代码 代码位于这篇文章的底部 但这里是链接GitHubGist Noitidart ff addon snippet browseForBadgeThenCreateSaveAnApply js https gist git
  • 无法绑定到“属性 X”,因为它不是“子组件”的已知属性

    在我的项目中 我有一个通用类和一些从该类继承的其他组件 BaseRdnInput ts Injectable export abstract class BaseRdnInput implements ControlValueAccesso
  • 如何使用 JS/Puppeteer 上传文件

    我试图弄清楚如何将图片文件上传到输入对话框中 不可能只输入名称并按 Enter 键 因为我没有找到使用 Puppeteer 实现自动化的方法 我想我必须设置一些值作为图片 但我不知道该怎么做 有任何想法吗 您使用上传文件elementHan
  • 如何使用Javascript获取ASP.NEt Web Forms标签的值?

    我有以下标签控件
  • Javascript 函数,我如何开始理解它们?

    我完全理解 为了学习 javascript 我需要知道函数是如何工作的 我了解传递参数的基础知识 然后使用值调用函数以将某些内容添加到一起 等等 我读过无数关于函数的文章 例如以及书籍等 但我只是不明白它们是如何使用的以及何时应该使用它们等
  • 如何在jsp中使用javascript动态创建下拉框?

    我正在尝试动态创建下拉框 就像当我单击添加按钮时它必须创建新的下拉框 下拉列表还包含动态值 例如需要当前年份并且必须显示最多五年 请建议我这样做 谢谢 这是我尝试过的代码 JavaScript 代码 function Add var nam
  • “submodule”似乎是一个 git 命令,但我们无法执行它

    我已经克隆了一个 git 存储库 它是一个 Angular 7 和 NET Core 应用程序 项目中一切正常 但是当我尝试恢复 npm 包时 出现以下错误 Microsoft TeamFoundation Team Explorer Gi
  • 在 MySQL 连接字符串中指定密码

    我使用 MySQL 作为 DB 和 Yeoman 生成器创建了 ExpressJS MVC 应用程序 并在config js我想更改 MySQL 连接字符串 但我不知道在字符串中指定密码 我的字符串是mysql root localhost
  • 新部署后,React 应用程序必须清除浏览器缓存

    我们正在使用 Jenkins 管道在 apache 服务器上部署 React 应用程序 当我们部署新代码时 大多数新功能都可以正常工作 但并非所有更改都反映浏览器中的最新内容 用户必须打开隐身窗口或清除缓存才能看到新功能 我见过一些相关的解
  • Angular2 - 防止复选框被选中

    我有一个每行包含一个复选框的表 在表头中 我有一个Check All切换所有表格行框的复选框 我正在尝试实现一些逻辑 如果复选框的数量将超过特定限制 则显示错误并且不切换表行复选框或checkall盒子本身 有一个问题允许checkAll即
  • 如何使用 Ajax 在 Flask 中发布按钮值而不刷新页面?

    我有一个问题 当我单击 Flask 应用程序中的按钮时 我想避免重新加载 我知道有 Ajax 解决方案 但我想知道如何将我的按钮链接到 ajax 函数以发布按钮值并运行链接到其值的 python 函数 这是我的 html 按钮 div di
  • 如何优化 Three.js 中多个 sphereGeometry 的渲染?

    我想优化 Three js 中 sphereGeometry 的渲染 因为它成为我的程序的瓶颈 javascript程序如下所示 var sphereThree for var idSphere 0 idSphere lt numSpher
  • 将base64图像转换为Node Js中的文件

    我是 Node Js 新手 我需要包含用户的个人资料图片 我从 IOS 应用程序收到 Base64 图像的请求 我需要将其存储在 images 文件夹中并将图像路径保存在 mongodb 数据库中 我使用了以下代码 var bitmap n
  • 如何使用jquery点击眼睛图标时显示和隐藏密码

    我需要在单击眼睛图标时显示和隐藏用户密码 因此我为此编写了脚本 当我单击眼睛图标时 只有类正在更改 但密码不可见 再次单击斜线眼睛图标 它应该隐藏这两个图标方法不起作用如何解决这个问题
  • 带有延迟的 jQuery 切换类只能运行一次

    当涉及到 jQuery 匿名函数和延迟时 我显然错过了一些基本的东西 下面的代码每次页面加载只能运行一次 它将添加该类 然后在 1 秒后将其删除 如果我再次单击 它将添加该类 但在页面持续时间内永远不会删除该类 除非我重新加载页面 var
  • D3.js - 更改鼠标悬停时元素的不透明度 IF 条件 = false

    我正在制作一个带有过滤器的交互式 D3 js 图表 当用户单击选定的复选框时 该过滤器会显示点 此外 在鼠标悬停事件上 所选点旁边将出现一个弹出窗口 其中包含一些信息 由于图表上的点数量相对较多 因此我选择在取消选中相应复选框时使相关点变得
  • 通过均匀分布值来有效合并两个数组

    我见过许多问题 答案主题是通过交替值合并两个数组 他们是这样工作的 let array1 a b c d let array2 1 2 let outcome a 1 b 2 c d 但我希望输出更加高效 并且根据数组大小均匀分配值 exp
  • 如何在输入时格式化 contenteditable div?

    我正在尝试编写一个函数 允许 contenteditable div 在用户输入 div 时执行一些自动格式化 到目前为止我只能让它在 IE 中运行 有人可以帮助我吗 function formatOnKeyUp if window get

随机推荐