Generate 2 configurations for webpack

Currently, I am facing a challenge while building a webpack file. The issue arose when I needed to incorporate the 'node' target due to conflicts with an 'fs' function that reads certain files. Subsequently, I decided to split my configuration into web and node segments. However, I am uncertain if this approach is correct.

I am in the process of segregating these webpack configurations.

Below is my webpack.config.js:

const VueLoaderPlugin = require('vue-loader/lib/plugin')

var path = require('path');

const webConfig = {
    entry: './src/main.js',
    mode: 'development',
    output: {
        path: path.resolve(__dirname, './dist/'),
        filename: 'bundle.js'
    },
    resolve: {
        extensions: ['.css','.jpg','.png'],
        alias: {
          'vue$': 'vue/dist/vue.esm.js',
          '@': path.resolve(__dirname, './src/'),
        }
    },
    module: {
        rules: [
            { test: /\.less$/, loader: "style-loader!css-loader!less-loader" },
            { test: /\.png/,   loader: "url-loader?limit=100000&mimetype=image/png" },
            { test: /\.gif/,   loader: "url-loader?limit=100000&mimetype=image/gif" },
            { test: /\.jpg/,   loader: "file-loader" },
            { test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' },
            { test: /\.css$/, use: ['vue-style-loader','css-loader']} 
        ]
  }
}
const nodeConfig = {
  entry: './src/main.js',
  mode: 'development',
  output: {
      path: path.resolve(__dirname, './dist/'),
      filename: 'bundle.node.js'
  },
  resolve: {
      extensions: ['.js', '.vue','.json'],
      alias: {
        'vue$': 'vue/dist/vue.esm.js',
        '@': path.resolve(__dirname, './src/'),
      }
  },
  target: 'node',
  node: { fs: 'empty' },
  module: {
      rules: [
          { test: /\.vue$/,  loader: 'vue-loader' },
          { test: /\.js$/,   loader: 'babel-loader' },
          { test: /\.css$/, use: ['vue-style-loader','css-loader']} 
      ]
},
plugins: [
  new VueLoaderPlugin()
]
}

However, I am encountering errors. The first one pertains to issues with js files, even though I am not utilizing them at the moment. What could be the potential mistake on my end?

ERROR in ./node_modules/axios/index.js
    Module not found: Error: Can't resolve './lib/axios' in 'C:\Users\sdr\Documents\deficarte\node_modules\axios'
     @ ./node_modules/axios/index.js 1:17-39
     @ ./src/main.js

ERROR in ./node_modules/vue-style-loader/lib/addStylesClient.js
    Module not found: Error: Can't resolve './listToStyles' in 'C:\Users\sdr\Documents\deficarte\node_modules\vue-style-loader\lib'
     @ ./node_modules/vue-style-loader/lib/addStylesClient.js 7:0-41 57:15-27 69:15-27
     @ ./node_modules/bootstrap/dist/css/bootstrap.min.css

Answer №1

Give this a try

const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

var path = require('path');

const webConfig = {
    entry: './src/main.js',
    mode: 'development',
    output: {
        path: path.resolve(__dirname, './dist/'),
        filename: 'bundle.js'
    },
    resolve: {
        extensions: ['.css','.jpg','.png','.js','.vue'],
        alias: {
        'vue$': 'vue/dist/vue.esm.js',
        '@': path.resolve(__dirname, './src/'),
        }
    },
    module: {
        rules: [
            { test: /\.less$/, loader: "style-loader!css-loader!less-loader" },
            { test: /\.png/,   loader: "url-loader?limit=100000&mimetype=image/png" },
            { test: /\.gif/,   loader: "url-loader?limit=100000&mimetype=image/gif" },
            { test: /\.jpg/,   loader: "file-loader" },
            { test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' },
            { test: /\.vue$/,  loader: 'vue-loader' },
            { test: /\.js$/, exclude: /node_modules/,   loader: 'babel-loader' }, 
{ test: /\.css$/, use: ['vue-style-loader','css-loader']} 
        ]
},
plugins: [
    new VueLoaderPlugin()
]
}

const nodeConfig = {
entry: './src/main.js',
mode: 'development',
output: {
    path: path.resolve(__dirname, './dist/'),
    filename: 'bundle.node.js'
},
resolve: {
    extensions: ['.js', '.vue','.json'],
    alias: {
        'vue$': 'vue/dist/vue.esm.js',
        '@': path.resolve(__dirname, './src/'),
    }
},
target: 'node',
node: { fs: 'empty' },
module: {
    rules: [
        // { test: /\.json/,  loader: "raw-loader" },
        { test: /\.vue$/,  loader: 'vue-loader' },
        { test: /\.js$/, exclude: /node_modules/,   loader: 'babel-loader' }, 
{ test: /\.css$/, use: ['vue-style-loader','css-loader']}
    ]
},
plugins: [
new VueLoaderPlugin()
]
}


module.exports = [ webConfig, nodeConfig ];
// var webpackConfig = merge(baseWebpackConfig, {
//   plugins: [
//     // service worker caching
//     new SWPrecacheWebpackPlugin({
//       cacheId: 'my-vue-app',
//       filename: 'src/service-worker.js',
//       staticFileGlobs: ['dist/*/.{js,html,css}'],
//       minify: true,
//       stripPrefix: 'dist/',
//       runtimeCaching: [
//         {
//            urlPattern: /^https:\/\/js\.api\.here\.com\/v3\/3.0\/mapsjs-core\.js\//,
//            handler: 'cacheFirst'
//         },
//         {
//            urlPattern: /^https:\/\/(\d+)\.media\.tumblr\.com\//,
//            handler: 'cacheFirst'
//         },

//      ]
//     })
//   ]

// })

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

Having an issue in Angular 2 where the correct function is not triggered when a button is placed within a selectable anchor

Within an anchor element, I have a button that triggers its own click listener for an editing popup module. The anchor itself has another click listener assigned to it. For example: <a (click)="onClick(myId)" class="list-group-item clearfix"> < ...

Jquery countdown that persists even after refreshing the page with F5

Currently, I am in search of a jquery plugin for a countdown feature that will retain the timer even if the page is refreshed. I am developing an application for a questionnaire and I would like to display a countdown timer set to 60 minutes. In my applica ...

Display a button in a single row table

Here is my table markup: <table class="table table-condensed"> <thead> <tr> <th>id</th> <th>task</th> <th>date</th> </tr> </thead> ...

Displaying a pop-up message over the "Login button" for users who are not currently logged in

I am currently in the process of developing a website using node.js and express. I have successfully integrated all the login functionality through passport, allowing users to easily log in or out by utilizing res.user. However, I now want to enhance the ...

Express Concurrency: Managing Multiple Tasks Simultaneously

Looking to create an API using Express that is capable of processing requests either through multithreading or multiprocessing. For example, the following API has a 5-second sleep before responding. If I make 3 quick calls to it, the first response will ta ...

What should be triggered when clicking on the cancel button in Bootstrap's modal: `close()` or `dismiss()`?

Bootstrap's modal offers two methods for hiding the dialog: close(result) (Type: function) - Used to close a modal by providing a result. dismiss(reason) (Type: function) - Used to dismiss a modal and provide a reason. Should I use close when the u ...

Guide on adding HTML to a specific div element in jQuery by utilizing the keyword "(this)"

I have been working on a script for my PHP page in Wordpress to add titles to images in my photo gallery that open in a lightbox. Here's what I developed: $(".responsive1").bind("click", function() { $(this).("<div class='imgTitle ...

Instructions on utilizing the signUp() function in Supabase for including extra user details during the registration process

My latest project involves building a Vue.js application with authentication using Supabase. I've been trying to implement the signUp() method from Supabase in order to collect extra user data during the sign-up process. In my code, I added a property ...

Does the [data-empty] constitute a component of the browser environment?

While exploring a node.js project that employs socket.io, I came across a piece of code that verifies whether the length of $('[data-empty]') is larger than 0. There was no class or ID associated with it, but it seemed like data-empty was some ki ...

Angular: When $scope variable is modified, a blank page issue arises

In my Angular application, I have a template called viewAll.html that is displayed after clicking on a link. This template fetches data via AJAX using scope variables. However, I encountered an issue where updating these scope variables through AJAX cause ...

Reduce the length of the text and display it upon hovering with the mouse

I am trying to figure out how to truncate text and have it expand on mouseover in a paragraph element. I attempted to truncate the content using a specific code, but I encountered an issue. While my current code expands the content when clicking on the el ...

What steps can be taken to address an undefined error before the execution of useEffect?

Today I encountered a small issue with my online player. It's fetching songs from the database using useEffect and saving them in state like this: const [songs, setSongs] = useState([]); const [currentSong, setCurrentSong] = useState(songs[0]); a ...

jquery module for retrieving and updating messages

I want to develop a custom plugin that can be utilized in a manner similar to the following example. This isn't exactly how I plan to use it, but it serves as the initial test for me to fully grasp its functionality. HTML: <div id="myDiv">< ...

Is there a way to track whether a user has logged into the Google Chrome browser using cookies?

While the LSID cookie can indicate if a user is logged into a Google account, it cannot be reliably used to determine if someone is signed into the Chrome browser because it may also appear when a person is signed into Gmail without being signed into Chrom ...

How can two unique links toggle the visibility of divs with two specific IDs?

I am developing an interactive questionnaire that functions like a 'create your own adventure' story. The questions are shown or hidden depending on the user's responses. Below is the HTML code: <!-- TIER 3 ============================== ...

Encountering an ENOENT error while attempting to incorporate a style guide into next.js (react)

Recently, I delved into learning next.js and decided to enhance my project with documentation using To kickstart my project, I utilized npx create-next-app After installation and configuration setup, I added the following code snippet: [styleguide.config ...

Why is this regular expression failing to match German words?

I am attempting to separate the words in the following sentence and enclose them in individual span elements. <p class="german_p big">Das ist ein schönes Armband</p> I came across this: How to get a word under cursor using JavaScript? $(&ap ...

Tips for maintaining a loading screen for longer than 4 seconds?

I want to maintain the loading screen for a minimum of 4 seconds. However, the timer at the end does not seem to be functioning as expected. Here is the code snippet I am using: window.addEventListener("load", () => { const preload = document.querySe ...

Exploring numerical elements in interactive content

Struggling with the Wikipedia API and encountering issues with the results that are returned. {"query":{ "pages":{ "48636":{ "pageid":48636, Concerned about how to access a specific ID (such as 48636) without knowing it in advance ...

What causes immediately invoked functions within event handlers to be executed before the event is triggered?

let b = (function maria() { alert("ee"); })(); * this code runs as soon as the page loads * <button onclick="b">Click me</button> * this code only runs when button is clicked * <button onclick="alert('ee')">Click m ...