Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Does not work with Vue.js #75

Closed
victorwpbastos opened this issue Jun 20, 2016 · 10 comments
Closed

Does not work with Vue.js #75

victorwpbastos opened this issue Jun 20, 2016 · 10 comments

Comments

@victorwpbastos
Copy link

main.js:

import Vue from 'vue';

new Vue({
    el: 'body'
})

rollup.config.js:

// rollup.config.js
import nodeResolve from 'rollup-plugin-node-resolve';
import nodeGlobals from 'rollup-plugin-node-globals';
import nodeBuiltins from 'rollup-plugin-node-builtins';
import commonjs from 'rollup-plugin-commonjs';

export default {
    entry: 'src/main.js',

    dest: 'dist/bundle-rollup.js',

    plugins: [
        nodeGlobals(),
        nodeBuiltins(),
        nodeResolve({
            jsnext: true,  // Default: false
            main: true,
            browser: true  // Default: false
        }),
        commonjs({
            include: 'node_modules/**'
        })
    ]
}

error:
image

@TrySound
Copy link
Member

@victorwpbastos
Copy link
Author

That instructions does not work either.

@TrySound
Copy link
Member

@victorwpbastos Why do you need rollup-plugin-node-globals and rollup-plugin-node-builtins? Everything works without them.

@victorwpbastos
Copy link
Author

With vue does not work.

@victorwpbastos
Copy link
Author

I did try a lot, without success.

@TrySound
Copy link
Member

What exactly doesn't work without those plugins?

@victorwpbastos
Copy link
Author

Vue uses process and global node vars. When you try to bundle with rollup, both process and global are undefined.

@TrySound TrySound reopened this Jul 20, 2016
@TrySound
Copy link
Member

TrySound commented Jul 20, 2016

Okay. process.env.NODE_ENV should be handled in another way with https://github.com/rollup/rollup-plugin-replace

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

This will let rollup remove constantly false conditions for prodution.

global does not affect your runtime.

@nicolasparada
Copy link

nicolasparada commented Oct 14, 2016

To use set from Vue I have to add it to namedExports so I can use it like so:

import { set } from 'vue'
set(object, key, value)

So far, so good. But then I end with a problem at runtime from Vuex:

Uncaught TypeError: Vue.set is not a function

Yeah, I could just remove it from the namedExports and do:

import Vue from 'vue'
Vue.set(object, key, value)

And all works fine, but I want to know why.
When a I use the namedExports option am I unable to import the whole library?
@Rich-Harris some help, please.

@jonataswalker
Copy link

This works for me:

import json from 'rollup-plugin-json';
import vue from 'rollup-plugin-vue';
import buble from 'rollup-plugin-buble';
import resolve from 'rollup-plugin-node-resolve';
import includePaths from 'rollup-plugin-includepaths';

let includePathOptions = {
  include: {
    'vue': 'node_modules/vue/dist/vue.common.js',
    'vue-router': 'node_modules/vue-router/dist/vue-router.js'
  },
  external: ['vue', 'vue-router']
};

export default {
  format: 'iife',
  entry: 'src/index.js',
  dest: 'app/app.js',
  globals: {
    'vue': 'Vue',
    'vue-router': 'VueRouter'
  },
  plugins: [
    json(),
    vue(),
    includePaths(includePathOptions),
    resolve({
      browser: true,
      main: true
    }),
    buble()
  ]
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants