mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
process.BROWSER_BUILD
This commit is contained in:
parent
d203d48c05
commit
e441b7eb12
@ -50,18 +50,22 @@ I added `vue-notifications` in the `vendor` key to make sure that it won't be in
|
||||
|
||||
### Only in browser build
|
||||
|
||||
Some plugins might work only in the browser, for this, you can use the `process.BROWSER` variable to check if the plugin will run from the server or from the client.
|
||||
Some plugins might work only in the browser, for this, you can use the `process.BROWSER_BUILD` variable to check if the plugin will run from the server or from the client.
|
||||
|
||||
Example:
|
||||
```js
|
||||
import Vue from 'vue'
|
||||
import VueNotifications from 'vue-notifications'
|
||||
|
||||
if (process.BROWSER) {
|
||||
if (process.BROWSER_BUILD) {
|
||||
Vue.use(VueNotifications)
|
||||
}
|
||||
```
|
||||
|
||||
### Only in server build
|
||||
|
||||
In case you need to require some libraries only for the server, you can use the `process.SERVER_BUILD` variable set to `true` when webpack is creating the `server.bundle.js` file.
|
||||
|
||||
## Demo
|
||||
|
||||
```bash
|
||||
|
@ -7,15 +7,13 @@
|
||||
|
||||
<script>
|
||||
let miniToastr
|
||||
if (process.BROWSER) {
|
||||
if (process.BROWSER_BUILD) {
|
||||
miniToastr = require('mini-toastr')
|
||||
}
|
||||
|
||||
export default {
|
||||
mounted () {
|
||||
if (process.BROWSER) {
|
||||
miniToastr.init()
|
||||
}
|
||||
},
|
||||
notifications: {
|
||||
showLoginError: {
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Vue from 'vue'
|
||||
import VueNotifications from 'vue-notifications'
|
||||
|
||||
if (process.BROWSER) {
|
||||
if (process.BROWSER_BUILD) {
|
||||
// Include mini-toaster (or any other UI-notification library
|
||||
const miniToastr = require('mini-toastr')
|
||||
|
||||
|
@ -36,7 +36,8 @@ module.exports = function () {
|
||||
// strip comments in Vue code
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
|
||||
'process.BROWSER': true
|
||||
'process.BROWSER_BUILD': true,
|
||||
'process.SERVER_BUILD': false
|
||||
}),
|
||||
// Extract vendor chunks for better caching
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
|
@ -26,8 +26,8 @@ module.exports = function () {
|
||||
plugins: (config.plugins || []).concat([
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
|
||||
'process.env.VUE_ENV': '"server"',
|
||||
'process.BROWSER': false
|
||||
'process.BROWSER_BUILD': false,
|
||||
'process.SERVER_BUILD': true
|
||||
})
|
||||
])
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user