2016-11-10 02:38:11 +00:00
|
|
|
'use strict'
|
|
|
|
|
2016-11-07 01:34:58 +00:00
|
|
|
const webpack = require('webpack')
|
2016-11-09 22:59:41 +00:00
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
2016-11-07 01:34:58 +00:00
|
|
|
const base = require('./base.config')
|
2016-11-09 22:59:41 +00:00
|
|
|
const { resolve } = require('path')
|
2016-11-07 01:34:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Webpack Client Config
|
|
|
|
|
|
|
|
|
| Generate public/dist/client-vendor-bundle.js
|
|
|
|
| Generate public/dist/client-bundle.js
|
|
|
|
|
|
|
|
|
| In production, will generate public/dist/style.css
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
*/
|
2016-11-09 22:59:41 +00:00
|
|
|
module.exports = function () {
|
|
|
|
let config = base.call(this)
|
2016-11-07 01:34:58 +00:00
|
|
|
|
2016-11-09 22:59:41 +00:00
|
|
|
// Entry
|
|
|
|
config.entry.app = resolve(this.dir, '.nuxt', 'client.js')
|
|
|
|
|
|
|
|
// Add vendors
|
|
|
|
if (this.options.store) {
|
|
|
|
config.entry.vendor.push('vuex')
|
|
|
|
}
|
|
|
|
config.entry.vendor = config.entry.vendor.concat(this.options.build.vendor)
|
|
|
|
|
|
|
|
// Output
|
|
|
|
config.output.path = resolve(this.dir, '.nuxt', 'dist')
|
|
|
|
config.output.filename = this.options.build.filenames.app
|
|
|
|
|
|
|
|
// Webpack plugins
|
|
|
|
config.plugins = (config.plugins || []).concat([
|
2016-11-07 01:34:58 +00:00
|
|
|
// strip comments in Vue code
|
|
|
|
new webpack.DefinePlugin({
|
2016-11-09 22:59:41 +00:00
|
|
|
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
|
2016-11-24 00:46:20 +00:00
|
|
|
'process.BROWSER_BUILD': true,
|
|
|
|
'process.SERVER_BUILD': false
|
2016-11-09 22:59:41 +00:00
|
|
|
}),
|
|
|
|
// Extract vendor chunks for better caching
|
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
|
|
name: 'vendor',
|
|
|
|
filename: this.options.build.filenames.vendor
|
2016-11-07 01:34:58 +00:00
|
|
|
})
|
|
|
|
])
|
|
|
|
|
2016-11-09 22:59:41 +00:00
|
|
|
// Production client build
|
|
|
|
if (!this.dev) {
|
|
|
|
config.plugins.push(
|
|
|
|
// Use ExtractTextPlugin to extract CSS into a single file
|
|
|
|
new ExtractTextPlugin({
|
|
|
|
filename: this.options.build.filenames.css,
|
|
|
|
allChunks: true
|
|
|
|
}),
|
|
|
|
// This is needed in webpack 2 for minifying CSS
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
minimize: true
|
|
|
|
}),
|
|
|
|
// Minify JS
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
compress: {
|
|
|
|
warnings: false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return config
|
2016-11-07 01:34:58 +00:00
|
|
|
}
|