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