Using ES6 Babel with multiple package.json files

For a large project, I am looking to break it down into multiple package.json files. This way, the dependencies for each part can be clearly defined and exported as separate entities.

However, my goal is to compile all of these packages using webpack and babel in one app without simply outputting them to a /dist folder since there are shared dependencies among the packages.

The envisioned directory structure is as follows:

\main
    \app
    \node_modules
    package.json
\package1
    package.json
    node_modules
    index.js
\package2
    package.json
    node_modules
    index.js

I have tried various methods:

  1. Attempting to use webpack's resolve modules with path.resolve('app'). Despite its theoretical feasibility, this method has proven ineffective.
  2. Utilizing the main package.json file to reference others via "package1" : "file:../package1". However, this approach fails to recognize package1 as ES6 JavaScript, resulting in errors. Even configuring resolveLoaders in the webpack setup does not resolve the issue.

The current webpack configuration is outlined as follows:

module: {
loaders: [
    {
        test: /\.js?/,
        loader: 'babel-loader',
        include: [
            path.resolve('app'),
            path.resolve('../prose'),
        ],
        query: {
            plugins: [
                ['react-transform', {
                    transforms: [{
                        transform: 'react-transform-hmr',
                        imports: ['react'],
                        locals: ['module']
                    }]
                }],
                ['transform-object-assign']
            ]
        }
    },
    { test: /\.css$/, loader: 'style-loader!css-loader!sass-loader' },
    { test: /\.svg$/, loader: 'file-loader' },
    { test: /\.png$/, loader: 'file-loader' },
    { test: /\.jpg$/, loader: 'file-loader' },
    { test: /\.json$/, loader: 'json-loader' }
]
},
resolve: {
    modules: [
        path.resolve('app'),
        'node_modules',
    ],
    extensions: ['.json', '.js', '.jsx'],
}

If you have any insights or examples of similar projects successfully implementing this strategy, please share!

Answer №1

Have you heard of lerna? It's a tool that allows for the utilization of multiple package.json files and packages within a single repository. This could be beneficial for meeting your specific needs.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Positioned at the top of the page is the alert box, with the

I'm looking to add an alert at the top of my webpage containing a form for visitors to enter their phone number. Currently, I have a "alert alert-info" div with the form inside it placed at the top of my body tag, which works perfectly. However, when ...

The URL for Ajax is not defined

I am currently working on a function that involves fetching an XML file and making some edits to it. This is new territory for me, so I had to do some research on the best approach to accomplish this task. After some consideration, I decided to use AJAX. H ...

Using React Hooks to render radio buttons within a map iteration

My code contains a nested map function where I try to retrieve values from radio buttons. However, the issue is that it selects all radio buttons in a row instead of just one. Below is the snippet of my code: <TableHead> <TableRow> ...

difficulty getting less to properly install using npm

After successfully installing node and npm, I encountered an issue where I couldn't install anything like less or bower using npm. When I tried npm -install -g less, it returned the following: C:\Users\user>npm install -g less C:\Us ...

I attempted to install the necessary dependencies using npm i, but unfortunately, it is not functioning correctly! Can someone please assist me with

Every time I attempt to install the project dependencies using npm, I encounter the following error: https://i.stack.imgur.com/PQVwx.png Can anyone provide assistance with this issue? ...

Modify the content in the v-navigation-drawer upon clicking

I am currently working on a project with a v-navigation-drawer and two buttons. The first button is designed to open the drawer, while the second one should change the content of the drawer without closing it. I want the content to update instantly without ...

Is it possible to send an HTTP request from the renderer process to the main process in Electron?

Currently, I am in the midst of developing an electron video player project. My main objective is to stream video from a readable stream to an HTML video-tag. I am exploring different solutions and strategies to achieve this goal. In particular, I am cur ...

Storing information in an array with automatic ID generation_incrementing

Here is an array in a specific format, however, there is no "ID" field available when the form is submitted. The requirement is to have an auto-generated ID assigned and saved in a JSON Array upon user submission of the form. With each form submission, t ...

The Vue/Vuetify wrapper component does not automatically pass on the `hide-details` parameter to the input component

I recently crafted a custom wrapper for the v-select input using Vuetify. Along with custom properties, I utilized the v-bind="$props"attribute to inherit all props. Upon testing, I observed that while this method applies to most props, it doesn ...

Ways to transmit the appropriate model

Using AJAX, I am sending a model to the server via a POST request. I have defined a model and a controller method for processing it. public class TestDto: BaseDto { [Required] public ProductGalleryDto GalleryProduct { get; set; } public int ...

Is Jquery struggling to modify the visual enhancements?

Check out this link, I need the sidebar design to be similar to what is shown in the provided link. Furthermore, I am looking for a way to have a pointer that follows along with my selection on different labels such as home, charts, etc. Can anyone assis ...

An unforeseen vow in lieu of an assortment

I'm currently working on a project involving node and mongo. To achieve parallel requests, I am utilizing a netlify serverless function that will be built using data from mongo records. Here's what I have done so far: paralellNum = 2; const filt ...

Inability to assign a value to an @input within an Angular project

I recently started using Angular and I'm currently trying to declare an input. Specifically, I need the input to be a number rather than a string in an object within an array. However, I'm encountering difficulties and I can't figure out wha ...

Utilizing SVG within Sproutcore allows for seamless access to DOM nodes and the ability to effortlessly bind Sproutcore events directly to the DOM

Exploring Sproutcore, I am delving into the world of SVG (Standard Vector Graphics) integration within the app. The goal is to utilize a canvas for drawing elements like lines, boxes, and images, all of which SVG offers. My approach involved incorporating ...

Navigating around potential type errors when passing data for chart.js can be challenging. Here are some strategies to

I'm currently working on an application that includes a chart, and I'm facing an issue while trying to populate the chart with data from my store. The error occurs when I attempt to pass the chartData object through props to the data property of ...

Create a cookie on a subdomain that is accessible by all other subdomains

I have been working on a NextJS project that involves multiple apps on separate subdomains. My objective is to enable single sign-on so that when I log in to one app, I am automatically signed in to all the others. We are utilizing nookies as our cookie ha ...

Obtain the index of a selected option in a Select Tag using Node.js/Express

When you make a POST request with a form in Node.js/Express For example: <select name="selectname"> <option value="value1">Value 1</option> <option value="value2" selected>Value 2</option> <option value="value3"> ...

setting up the NPM web scraping tool

I am attempting to set up NPM crawler on my Windows system using the command npm install crawler The installation is failing, and I am getting the following debug information 5874 error Error: ENOENT, lstat 'E:\Project\test\node_modu ...

Issues with d3.js transition removal functionality not functioning as expected

Having an issue with a d3.js visualization that involves multiple small visualizations and a timeline. When the timeline changes, data points are supposed to be added or removed accordingly. Here is the code snippet responsible for updating: var channels ...

Installing npm modules in a private repository within a docker container without triggering the prepare hook

It appears that the prepare hook in Linux is not being called when installing from a private git repository. I am using an Alpine image and attempting to build my private package with npm install, but the prepare hook is not triggered. When checking the li ...