Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

node.js - How to add wildcard mapping in entry of webpack

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'
  }
};

I am getting error like this,

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)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Having one or few entry points should be enough for most of use cases, but if you really want to bundle up all files from directory you can use following:

As explained here: https://github.com/webpack/webpack/issues/370

var glob = require("glob");
// ...
entry: glob.sync("./src/scripts/*.js")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...