Leveraging Parcel to compile multiple JS files into one, while preserving the framework path settings

I am currently in the process of enhancing an application to make it more manageable. The application is currently utilizing a large JS file with numerous JS classes. I have decided to organize the code by placing each JS class in its own separate JS file. My goal is to leverage Parcel to merge all JS files into one single JS file that can be easily linked from my index.html.

To achieve this, I have modified each main class by adding export default. For example: export default class MyJSClass. Then, I import these classes as needed from an index.js file like so:

import MyJSClass from './MyJSClass.js';

The current framework structure of the application is as follows:

resources
  |-Public
    |-JS
      |-singleHugeJSFile.js
  |-Templates
    |-index.html

I intend to utilize Parcel while maintaining the same structure, which would look like:

resources
  |-Public
    |-JS
      |-index.js // Entry point JS file
      |-MyJSClass.js
      |-SomeOtherClass.js
      |-AnotherClass.js
      ...

  |-Templates
    |-index.html

To start, I have installed Parcel within the resources directory and executed the following command:

parcel build public/js/index.js

However, this generates files in the dist directory.

How can I generate a single entry JS file containing all JS using Parcel while preserving the original application structure, allowing me to maintain the default path for linking to this JS file from index.html?

Answer №1

If you're looking to customize your Parcel setup, I've got just the solution for you. I've created a handy plugin that allows you to tailor the dist structure to your specific needs. Take a look at it here.

Whether you're working on web or node projects, this plugin will help you generate the desired dist structure while managing your imports seamlessly.

For your project, all you need to do is provide the following configuration:

"customDistStructure": {
    "config": {
      ".js": "Public/JS",
      ".html": "Templates"
    },
    "options": {
      "development": true
    }
}

I'd love to hear your thoughts on this! Feel free to reach out with any feedback.

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

Display one component multiple times across various webpages with unique text each time

I'm currently exploring React and attempting to render a single component in various HTML files within an existing project, each with different text content. Here's what I have in mind: class CtaSection extends React.Component{ render(){ ...

Vue.js Interval Functionality Malfunctioning

I'm brand new to Vuejs and I'm attempting to set an interval for a function, but unfortunately it's not working as expected. Instead, I am encountering the following error: Uncaught TypeError: Cannot read property 'unshift' of u ...

communication between a Windows C# application and a web-based JavaScript interface

Similar Question: how to get variable in desktop c# program from web javascript application Encountered an issue involving two applications: a desktop application written in C# and a web application in JavaScript. The need has arisen to transfer certa ...

Creating an object key using a passed literal argument in TypeScript

Can the following scenario be achieved? Given an argument, how can we identify the object key and access it? Any potential solutions? async function checkKey(arg:'key1'|'key2'){ // fetchResult returns an object with either {key1:&apo ...

Simplify your code with promises in JavaScript

Running on an API with node v6.3.0, I have the following code that executes two separate promises based on a conditional check for a parameter in a POST request. if (paramExists) { // query database with this condition User.filter(/* utilize param ...

Display and conceal information upon tweeting

Can anyone help me troubleshoot an issue with hiding the Twitter button after displaying new content? I tried adding a script to make it work, but it's still not functioning properly. Any insights on what I might be doing wrong would be greatly apprec ...

Tips for transforming list items into an array of strings

let typeList="[Product,Task,Invoice,Media,Store]"; I need to transform the string above into an array like this:- let typeList=["Product","Task","Invoice","Media","Store"]; Any help with this is greatly appreciated. ...

Attempting to add the graphql package to a Node.js project

npm ERR! code ENOSELF npm ERR! The installation of the package named "graphql" under a package npm ERR! with the same name "graphql" is being refused. Have you accidentally npm ERR! named your project the same as the dependency you ...

Detecting Android devices

Issue: My website functions properly on desktop but has a problem with the carousel images skewing on iPhones. To address this, I created a separate CSS styling for iPhone devices and used a JavaScript function found online to detect iPhones and iPads. Un ...

Quickly browse through the options (Vuex, routing) and modify the routing based on the selected value from the

Seeking advice on dynamically changing routing details in a search component based on user selection from a dropdown menu. Home.vue Components <h4>Search for {{searchObj.whatSearch}}</h4> <input type="text" placeholder=& ...

Using AngularJS to transfer data from a datepicker to an ng-model

I am currently trying to figure out how to pass the date from a datetimepicker into the model. Unfortunately, I am facing some challenges with this process. I wish I could provide a demo of the issue on a fiddle, but I am unsure of how to do so due to the ...

Closing on submit the modal window

I'm encountering an issue with a form in a bootstrap modal window. When I click the 'send' button, the modal closes and displays a white page with the error message from my action call to contact-form.php. However, the error message should a ...

What methods can be used to replicate a network delay while conducting unit tests for an AngularJS controller?

I am currently utilizing the $httpBackend service within the ngMock module to emulate a GET request. The following is a sample controller code snippet sourced from the AngularJS documentation: // Example controller code function MyController($scope, $http ...

In need of changing the date format post splitting

I need help converting a date from MM/DD/YY to YYYYMMDD The current code I have is giving me an incorrect output of 2211. How can I implement a check on the Month and Day values to add a leading zero when necessary? var arr = '1/1/22'; arr = NTE ...

Unable to successfully remove item by ID from mongoDB within a Next.js application

Currently, I am developing an application using NextJS for practice purposes. I'm facing challenges in deleting single data from the database with the findByIdAndDelete function. Error encountered: CastError: Cast to ObjectId failed for value "undef ...

Error message: The Node.js filtered LS command is missing a ")" after the argument list

I've been working on the learnyounode workshop and I'm stuck on a code issue. After running it through jslint, I received this feedback: Expected ')' to match '(' from line 6 but instead saw '{'. Oddly enough, line ...

Tips for maintaining the functionality of IFrame?

I am encountering an issue with tracking clicks on a div that contains an IFrame. While the tracking functionality works, it seems to interfere with the IFrame's functionality. Is there a way to resolve this and make both functionalities work simultan ...

Does the TS keyof typeof <Object> rule prohibit the assignment of object.keys(<Object>)?

I'm having trouble understanding the issue with this code snippet. Here is the piece of code in question: export type SportsTypes = keyof typeof SportsIcons export const sports: SportsTypes[] = Object.keys(SportsIcons); The problem arises when I at ...

Access the angular controller using the radio button option

I am looking to showcase data in an HTML table retrieved from an Angular controller. I have the controller set up but I am unsure about how to display the data when a radio button is selected. <div class="radio"> <label class="radio-inline" ...

Having Trouble Opening Bootstrap 4 Modal with a Click?

I'm having trouble getting my modal to open. I've tried using the basic HTML code from the Bootstrap 4 site and also added some Javascript, but it's not working. I can't seem to figure out what I'm doing wrong. Any assistance would ...