如何在webpack入口添加通配符映射 [英] How to add wildcard mapping in entry of webpack

查看:21
本文介绍了如何在webpack入口添加通配符映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要webpack脚本文件夹中的所有js文件.我试过这个

I need to webpack all the js file in the script folder.I tried this

module.exports = {
  module: {
    loaders: [
      {
        test: /.js$/,
        exclude: /node_modules/,
        loaders: ["babel-loader"],
      }
    ],
  },
  entry: "./src/scripts/*.js",
  output: {
    path: './src/build',
    filename: '[name].js'
  }
};

我收到这样的错误,

ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' ./s
rc/scripts/* in E:Web projectReactJS
eact-tutorial
resolve file
  E:Web projectReactJS
eact-tutorialsrcscripts* doesn't exist
  E:Web projectReactJS
eact-tutorialsrcscripts*.webpack.js doesn't exist
  E:Web projectReactJS
eact-tutorialsrcscripts*.web.js doesn't exist
  E:Web projectReactJS
eact-tutorialsrcscripts*.js doesn't exist
  E:Web projectReactJS
eact-tutorialsrcscripts*.json doesn't exist
resolve directory
  E:Web projectReactJS
eact-tutorialsrcscripts* doesn't exist (directory d
efault file)
  E:Web projectReactJS
eact-tutorialsrcscripts*package.json doesn't exist
 (directory description file)

它不是在搜索所有的 js 文件,而是在搜索 *.js 之类的.帮我看看我错过了什么

It is not searching for all the js file instead it is searching for *.js like that.Help me out what I missed

推荐答案

entry 值应解析为特定文件或特定文件列表.

The entry value should resolve to a specific file, or a list of specific files.

来自 webpack 文档:

如果你传递一个字符串:该字符串被解析为一个模块启动时加载.

If you pass a string: The string is resolved to a module which is loaded upon startup.

如果你传递一个数组:所有模块在启动时加载.最后一个是出口的.

If you pass an array: All modules are loaded upon startup. The last one is exported.

如果您只是想定义一个模块,请编辑您的 entry 值以指向您的主应用程序文件,然后从中调用其他模块.

If you are simply trying to define one module, edit your entry value to point to your main application file and then require other modules from that.

如果您真的想从一个目录中捆绑所有文件,请参阅 arsienews 答案

If you really want to bundle all files from a directory, see arseniews answer

这篇关于如何在webpack入口添加通配符映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆