如何使用的WebPack而不需要语句加载一个子目录下的所有文件 [英] How to load all files in a subdirectories using webpack without require statements

查看:601
本文介绍了如何使用的WebPack而不需要语句加载一个子目录下的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量的JavaScript文件在我的应用程序分成4个子目录。在咕噜咕噜我抢他们都和它们编译成一个文件。这些文件不具有module.exports功能

I have a large amount of javascript files split into 4 subdirectory in my app. In grunt I grab all of them and compile them into one file. These files do not have a module.exports function

我想使用的WebPack和它拆分成4个部分。我不想手动去,并要求我的所有文件。

I want to use webpack and split it into 4 parts. I don't want to manually go in and require all my files.

我想创建在编译走在目录树,然后获取所有的.js文件名和路径的插件,那么需要在子目录中的所有文件,并将其添加到输出。

I would like to create a plugin that on compilation walks the directory trees, then grabs all the .js file names and paths, then requires all files in the sub directories and adds it to the output.

我想在编译成模块的每个目录中的所有文件,我可以再从我的切入点文件要求,或包含在的 http://webpack.github.io/docs/plugins.html 提到。

I want all the files in each directories compiled into a module that I could then require from my entry point file, or include in the assets that http://webpack.github.io/docs/plugins.html mentions.

在添加新的文件,我只是想将它放在正确的目录,并知道它会被包括在内。

When adding a new file I just want to drop it in the correct directory and know it will be included.

有没有办法用的WebPack或插件,有人写这样做是为了做到这一点?

Is there a way to do this with webpack or a plugin that someone has written to do this?

推荐答案

在我的应用程序文件,我最终把需要

In my app file I ended up putting the require

require.context(
  "./common", # context folder
  true, # include subdirectories
  /.*/ #RegExp
)("./" + expr + "")

这个帖子的礼貌:<一href=\"https://github.com/webpack/webpack/issues/118\">https://github.com/webpack/webpack/issues/118

它现在将我的所有文件。我对HTML和CSS加载器,它似乎工作太棒了。

It is now adding all my files. I have a loader for html and css and it seems to work great.

这篇关于如何使用的WebPack而不需要语句加载一个子目录下的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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