Vue: runtime-only build from CDN contain references to process.env.NODE_ENV - offer alternative build?

Created on 14 Oct 2016  路  11Comments  路  Source: vuejs/vue

I'm bundling my code only and using Vue from unpkg.
But even if I'm not using the template option, I'm forced to use the standalone build because the runtime-only one has some node variables, like process or module.

Uncaught ReferenceError: process is not defined

discussion

Most helpful comment

@LinusBorg module.exports gave problems too...
@posva Yeah, there is a couple of solutions, but... since they are on a CDN, they should be browser ready; with a minified version too.

All 11 comments

Why would you want to use the runtime-only build inside browsers?
Are you sure you don't need template/jsx compilation and just want to write all render functions by hand?

I have my build system configured with support for .vue files and jsx, and both of them don't use the template option.

Since you do have a build system, why not just use runtime-only build with it, instead of loading vue separately in browser?

I just don't want one single big bundled file. It would be better if I just load frameworks and libraries separately from my code.
In webpack there is CommonsChunkPlugin, but I'm using Rollup here :/

@NicolasParada As a fix, add a script tag that adds process.env.NODE_ENV to the global namespace:

<script>
  window.process = { env: { NODE_ENV: 'production' } }
</script>
<script src ="https://unpkg.com/[email protected]/dist/vue.common.js" />

@fnlctrl I'm not sure weither these variables are supposed to be present in a build on a CDN. At least it's inconvenient to offer CDN access to these files and then require a workaround like above to use them.

Think we should discuss internally how to deal with this.

I think the runtime only is meant to be used with a bundler. If you're using rollup you can use https://github.com/rollup/rollup-plugin-replace

@LinusBorg module.exports gave problems too...
@posva Yeah, there is a couple of solutions, but... since they are on a CDN, they should be browser ready; with a minified version too.

@NicolasParada They're automatically added to CDNs so it's normal for some of them not to be browser ready and/or without a minified version

I wanted to start using the CDN version of vue inside a Rails app today and met the same issue. Building upon @LinusBorg & @NicolasParada input, here is the version that works for me:

<script type="text/javascript">
  window.process = { env: { NODE_ENV: 'production' } };
  window.module = {};
</script>

I wonder if there's a version hosted somewhere which can be used without any tweak?

When next release is out you can use the UMD runtime build via https://unpkg.com/vue/dist/vue.runtime.js

when I change vue.common.js to vue.min.js,problem solved.however,I still don't understand why.

Was this page helpful?
0 / 5 - 0 ratings