What are the steps to set up rollup with Vue?

Working on a project utilizing Vue.js and bundling with Rollup.

Shown below is the content of my rollup.config.js file

import vue from 'rollup-plugin-vue2'
import less from 'rollup-plugin-less2';
import buble from 'rollup-plugin-buble'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import uglify from 'rollup-plugin-uglify'
import livereload from 'rollup-plugin-livereload'
import serve from 'rollup-plugin-serve'

const plugins = [
    vue({'css':'none'}),
    less({output: "dist/build.css"}),
    buble({exclude: 'node_modules/**'}),
    nodeResolve({browser: true, jsnext: true}),
    commonjs()
]

if (process.env.NODE_ENV === 'production') {
    plugins.push(uglify())
}

if (process.env.NODE_ENV === 'development') {
    plugins.push(livereload('dist'))
    plugins.push(serve({
        contentBase: "",
        open: true
    }))
}

export default {
    input: 'src/main.js',
    output: {
        file: 'dist/build.js',
        format: 'iife',
        sourcemap: true,
        //external: ["vue","vue-router"],
    },
    //external: ["vue","vue-router"],
    plugins
}

My main.js file looks like this.

import Vue from 'vue'
import App from './App.vue'
import VueRouter from "vue-router";

Vue.use(VueRouter);

const Foo = {template: '<div>foo</div>'}
const Bar = {template: '<div>bar</div>'}

const routes = [
    {path: '/foo', component: Foo},
    {path: '/bar', component: Bar}
];

const router = new VueRouter({
    routes
});

var app = new Vue({
    router: router,
    el: '#app',
    render: h => h(App)
});

Encountering an error after running the project:

Uncaught ReferenceError: process is not defined

By using Vue as an external library and uncommenting the line

["vue","vue-router"], external: ["vue","vue-router"]
, everything works fine.

How can I resolve the compilation and functionality issues with rollup?

Answer №1

Encountered a similar issue but was able to find a solution at this link: https://github.com/rollup/rollup/issues/487

The resolution involves utilizing the rollup replace plugin to substitute all instances of process.env.NODE_ENV in every imported file, as demonstrated below:

plugins: [
  replace({
    'process.env.NODE_ENV': JSON.stringify( 'production' )
  })
]

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

issue with using references to manipulate the DOM of a video element in fullscreen mode

My current objective is to detect when my video tag enters fullscreen mode so I can modify attributes of that specific video ID or reference. Despite trying various methods, I have managed to log the element using my current approach. Earlier attempts with ...

Mistakes in design when transforming inline SVG to PNG format

One of my main objectives is to convert a <div> element that contains multiple inline svg images into a png file. The entire process must be carried out within the client's browser using JavaScript. I have experimented with various techniques: ...

Loop through an array of div IDs and update their CSS styles individually

How can I iterate through an array of Div IDs and change their CSS (background color) one after the other instead of all at once? I have tried looping through the array, but the CSS is applied simultaneously to all the divs. Any tips on how to delay the ...

how to make a scroll event bubble in rxjs

When using vanilla JavaScript, I can easily catch any scroll event on any element by including true as the last argument: document.addEventListener('scroll', function(e) { console.log(e); }, true); However, with rxjs it's not as straight ...

Is there a way to implement retry functionality with a delay in RxJs without resorting to the outdated retryWhen method?

I'd like to implement a retry mechanism for an observable chain with a delay of 2 seconds. While researching, I found some solutions using retryWhen. However, it appears that retryWhen is deprecated and I prefer not to use it. The retry with delay s ...

Review the file's content prior to uploading

Before uploading a zip or rar file to the server, I need to ensure that the content is safe and not malicious. Let me paint the picture for you. In my web project, there are two types of users: 1: Regular registered users 2: Project administrators Any ...

Encountering an issue while using Vue CLI where the console displays an error message: "Uncaught

My project was initially set up using vue-cli 3.0 and everything was running smoothly. However, when I terminated it with <ctrl>-c and tried running npm run serve again, I kept encountering the following error: Uncaught SyntaxError: Unexpected tok ...

AngularJS presents an error: [ng:areq] The argument 'myAppCtrl' is not recognized as a function, as it returns undefined while implementing routes with ngRoute and $routeProvider

Can anyone assist me with an error I'm encountering while setting routes on two buttons? Despite having everything properly defined, the table is not displaying any data. Your insights would be greatly appreciated. Thank you for your help. Snippet f ...

Learn how to synchronize global packages across multiple computers using npm

After installing several npm global packages on my work computer, I am now looking to synchronize these packages with another device. In a typical project, we utilize a package.json file to keep track of package details, making it easy to install all the ...

What is the best way to instantiate a dynamic object within a literal?

I am dealing with an object that contains multiple fields, mainly consisting of constant string values. However, I also need to incorporate a variable that is determined by the current state. const {order} = this.state; myObject={{ fieldA: 2, fiel ...

Radio button is selected but textbox does not display

Struggling to get the radio button to display the textbox as intended, but unfortunately encountering issues. Here is the HTML code in the JSP page: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> ...

Understanding JavaScript for Reading a Website's "Local Storage"

Can the local storage of one website be accessed by a different domain, or is it restricted to only the domain that saved it? ...

Tips for optimizing node_module file size

Currently, I'm developing 2-3 react applications and noticed that every time I run npm install, it ends up downloading numerous dependencies into the cumbersome "node-modules" folder, totaling around 250-300mb in size! This large size makes it challen ...

What steps can I take to direct mobile visitors to the mobile-friendly version of my website?

Looking for a way to automatically redirect users on mobile devices from www.domain.com to the new mobile version at m.domain.com? ...

"Tips on updating the value of a BehaviorSubject with map, filter, find, or findIndex in an Angular

TS arrData = new BehaviorSubject<any>([]); ngOnInit() { const dataArr1 = [ { id: '1', name: 'Room1', spinning: true }, { id: '2', name: 'Room2&apos ...

When submitting the form for the zip code input, use an XMLHttpRequest to input the zip code and retrieve the corresponding city

I'm currently working on a project that involves inputting zip codes and retrieving the corresponding city information from . In the future, I plan to parse this data and store it as variables in my program while potentially using longitude/latitude f ...

Which regular expression should be used to validate names with international characters?

Currently in my PHP project using Codeigniter, I am implementing form validation. Specifically, I have configured the validation rules for the name field like this: $this->form_validation->set_rules('name', 'Nombre', 'requir ...

AngularJS directive that allows for either a click action to be passed or a ui-router state change to

I have a button (an a tag) that is displayed in multiple locations on my website. It is labeled "View Demo", and sometimes it directs to a demo page using an ui-sref: <a class="btn btn-primary" ui-sref="hamburger-push" target="_blank"> View Demo ...

How come my form isn't functioning properly on mobile devices?

I recently downloaded a form from the website and integrated it within my desktop site successfully. However, when accessed on mobile devices, specifically iOS, the submit button changes to "sending ..." and the form gets stuck without displaying any erro ...

Issues encountered when trying to implement helperText in mui date picker

Can someone assist with this issue? The helper text is not displaying as expected in the following code snippet: <div className={classes.container}> <LocalizationProvider dateAdapter={AdapterDateFns}> <Des ...