Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
How to save WebPack output files to another place automatically after my project is built

We have a SDK project witch is depended by another two projects.

When we want to build whole application, firstly, we need to build SDK project and upload it. Then we can build another two projects after run npm install.

This time I want to add a script for developer. When I run the script in SDK project it I can save the built output files to another projects node_modules.

Here is my code.

package.json file:

{
  ...
  "scripts": {
    "build:dev": "webpack --mode=development",
    ...
  }
  ...
}

webpack.config.js file:

let config = {
  ...
  module: {
    rules: [
      {
        test:/\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/
      }
    ]
  }
  ...
}

module.exports = (env, argv) => {
  if(argv.mode === 'development') {
    // We put all the projects in one repo
    config.output.path = path.resolve(__dirname,'../another-project/node_modules/sdk/dist/bundle')
  }
}

And at last we set outDir in tsconfig.json.

The problem is:

  • How to change the output file path for typescript declaration files by WebPack arguments?
  • How to save all the file to two places one time?

I figure out the last problem by using webpack -env xxx && webpack -env xxx. I just run script twice, maybe someone has better idear.

Now just one qusetion:

  • How to set the output file path for typescript declaration files dynamically?
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

webpack.config.js file:

let config = {
  ...,
  module: {
    rules: [
      {
        test:/\.tsx?$/,
        use: 'ts-loader',
        options: {
          configFile: "tsconfig.server.json"
        }
      }
    ]
  },
  ...
}

Then I can change configFlie in webpack module.

about 4 years ago · Juan Pablo Isaza Report

0

https://webpack.js.org/configuration/output/

module.exports = {
...
  output: {
    filename: "lib.js"
  }
...

Configuring the out dir in typescript will not help you because webpack is the one responsible for compilation and will only use typescript for compilation after outputting the files itself.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!