如何在Webpack条目中添加通配符映射 [英] How to add wildcard mapping in entry of webpack

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

问题描述

我需要将所有js文件打包到web文件夹中.我尝试过

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 project\ReactJS\react-tutorial
resolve file
  E:\Web project\ReactJS\react-tutorial\src\scripts\* doesn't exist
  E:\Web project\ReactJS\react-tutorial\src\scripts\*.webpack.js doesn't exist
  E:\Web project\ReactJS\react-tutorial\src\scripts\*.web.js doesn't exist
  E:\Web project\ReactJS\react-tutorial\src\scripts\*.js doesn't exist
  E:\Web project\ReactJS\react-tutorial\src\scripts\*.json doesn't exist
resolve directory
  E:\Web project\ReactJS\react-tutorial\src\scripts\* doesn't exist (directory d
efault file)
  E:\Web project\ReactJS\react-tutorial\src\scripts\*\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.

如果您确实要捆绑目录中的所有文件,请参见 arseniews答案

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

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

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