Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to compile per file and keep structure? #65

Open
AhmedBHameed opened this issue Jun 23, 2019 · 0 comments
Open

[Question] How to compile per file and keep structure? #65

AhmedBHameed opened this issue Jun 23, 2019 · 0 comments

Comments

@AhmedBHameed
Copy link

AhmedBHameed commented Jun 23, 2019

Hello,

So i'm encounter of creating sub part as external application program that depending on other existing programs.
Example for that creating sub project to update some entries in database, so normally i use the existing driver to handle database call. but webpack is bundling all in one big bundle file!!

So how to bundle all files and keep structure of the application?

const path = require("path");
const fs = require("fs");
const CopyPlugin = require("copy-webpack-plugin");
const nodeExternals = require("webpack-node-externals");
const NodemonPlugin = require("nodemon-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");

const ROOT_DIR = path.resolve(__dirname, "../../");
const APP_DIR = path.resolve(__dirname, "../../src");
const BUILD_DIR = path.resolve(__dirname, "../../build");

module.exports = {
  entry: `${APP_DIR}/server.ts`,
  output: {
    path: BUILD_DIR,
    filename: "server.js"
  },
  target: "node",
  externals: [nodeExternals()],
  resolve: {
    extensions: [".ts", ".js"],
    alias: {
      "@src": `${ROOT_DIR}/src/`,
      "@database": `${APP_DIR}/database/`
    }
  },
  plugins: [
    new CleanWebpackPlugin(),
    new CopyPlugin([{ from: `${APP_DIR}/public`, to: `${BUILD_DIR}/public` }]),
    new NodemonPlugin()
  ],
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: ["ts-loader"],
        exclude: /node_modules/
      }
    ]
  }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant