mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Add config.env option
This commit is contained in:
parent
8ae76db287
commit
a6d4e5136b
@ -1,5 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const _ = require('lodash')
|
||||
const webpack = require('webpack')
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
||||
const base = require('./base.config')
|
||||
@ -31,14 +32,19 @@ module.exports = function () {
|
||||
config.output.path = resolve(this.dir, '.nuxt', 'dist')
|
||||
config.output.filename = this.options.build.filenames.app
|
||||
|
||||
// env object defined in nuxt.config.js
|
||||
let env = {}
|
||||
_.each(this.options.env, (value, key) => {
|
||||
env['process.env.' + key] = (typeof value === 'string' ? JSON.stringify(value) : value)
|
||||
})
|
||||
// Webpack plugins
|
||||
config.plugins = (config.plugins || []).concat([
|
||||
// strip comments in Vue code
|
||||
new webpack.DefinePlugin({
|
||||
new webpack.DefinePlugin(Object.assign(env, {
|
||||
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
|
||||
'process.BROWSER_BUILD': true,
|
||||
'process.SERVER_BUILD': false
|
||||
}),
|
||||
})),
|
||||
// Extract vendor chunks for better caching
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
name: 'vendor',
|
||||
|
@ -1,5 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const _ = require('lodash')
|
||||
const webpack = require('webpack')
|
||||
const base = require('./base.config')
|
||||
const { uniq } = require('lodash')
|
||||
@ -14,6 +15,12 @@ const { resolve } = require('path')
|
||||
module.exports = function () {
|
||||
let config = base.call(this)
|
||||
|
||||
// env object defined in nuxt.config.js
|
||||
let env = {}
|
||||
_.each(this.options.env, (value, key) => {
|
||||
env['process.env.' + key] = (typeof value === 'string' ? JSON.stringify(value) : value)
|
||||
})
|
||||
|
||||
config = Object.assign(config, {
|
||||
target: 'node',
|
||||
devtool: false,
|
||||
@ -24,11 +31,11 @@ module.exports = function () {
|
||||
libraryTarget: 'commonjs2'
|
||||
}),
|
||||
plugins: (config.plugins || []).concat([
|
||||
new webpack.DefinePlugin({
|
||||
new webpack.DefinePlugin(Object.assign(env, {
|
||||
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
|
||||
'process.BROWSER_BUILD': false,
|
||||
'process.SERVER_BUILD': true
|
||||
})
|
||||
}))
|
||||
])
|
||||
})
|
||||
|
||||
|
@ -24,6 +24,7 @@ class Nuxt {
|
||||
_build: true,
|
||||
// general options
|
||||
dev: true,
|
||||
env: {},
|
||||
head: {},
|
||||
plugins: [],
|
||||
css: [],
|
||||
|
Loading…
Reference in New Issue
Block a user