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

131
Views
Webpack: use data from parent directory without copying

I have a project folder structured like this:

project-name/   
  data/
   data.csv
  dist/
   index.js
  src/
   index.js

And want a remote directory like this:

project-name/   
  data/
   data.csv
  dist/
   index.js
    > `doSomething("../data/data.csv")`

How do I make this work in both webpack-dev-server and in the production path? If I use copywebpack plugin, then the data goes inside the dist/, which I don't want. But if I use a relative directory without copying the data, then the build fails.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Actually, you should use Webpack csv-loader in your Webpack configuration file like below:

module: {
  rules: [
    {
      test: /\.csv$/,
      loader: 'csv-loader',
      options: {
      dynamicTyping: true,
        header: true,
        skipEmptyLines: true,
      },
    },
  ],
},

And then use it inside your code like below:

import csvPath from './project-name/data/foo.csv'
about 4 years ago · Juan Pablo Isaza Report

0

Can you use an alias?

webpack.config.js:

  const path = require("path");

  module.exports = {
  ...

    resolve: {
      alias: {
        Data: path.resolve(__dirname, "./project-name/data/"),
      },
    },
  }

src/index.js:

  import data from "Data/data.csv"
about 4 years ago · Juan Pablo Isaza Report

0

Have you tried excluding it in the test? Something like this:

   {
    entry: "./src/index.js",
    module: {
      rules: [
        {
          test: /\.js$/,
          use: ["babel-loader or whatever loader you use"],
        },
        {
          test: /\.csv$/,
          exclude: ["./data/"],
        },
      ],
    },
    output: {
      filename: "index.js",
      path: path.resolve(__dirname, "dist"),
    },
   },

There is a similar question on how to not bundle files in webpack here

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!