Sameer
Sameer

Reputation: 3526

How to add full public directory to bundle all files in Webpack?

i'm planning to use webpack instead of gulp. I'm using MEAN stack, I am using AngularJs for front end.

My webpack.config.js:

const path = require('path');

module.exports = {
  mode: 'development',
  entry: './public/js/controllers.js',
  output: {
    path: path.join(__dirname, 'public'),
    filename: 'bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        },
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },
  devServer: {
    port: 3000,
    open: true,
    proxy: {
      '/': 'http://localhost:8080',
    },
  },
};

In this configuration i am bundling only controller.js, but i need to bundle whole folders which is inside in public directory, is it possible?

Upvotes: 1

Views: 1134

Answers (1)

Ritik Saxena
Ritik Saxena

Reputation: 724

Suppose you have two different js files(controller1.js, controller2.js) which you wish to include in index.html.

Your webpack.config.js will have entry as -

entry : ['./public/js/controller1.js', './public/js/controller2.js']

Both the controllers will be processed fine by webpack.

Upvotes: 1

Related Questions