Improve webpack config

- Remove filenames.css
- Add FriendlyErrorsWebpackPlugin()
- Add sourceMaps for UglifyJS
- Minify CSS for server-rendered pages
- Add css-loader for imports
This commit is contained in:
Sébastien Chopin 2017-03-24 01:28:04 +01:00
parent 53f9d62fce
commit d4db5792a4
6 changed files with 24 additions and 3 deletions

View File

@ -47,7 +47,6 @@ const defaults = {
analyze: false,
publicPath: '/_nuxt/',
filenames: {
css: 'style.[hash].css',
vendor: 'vendor.bundle.[hash].js',
app: 'nuxt.bundle.[chunkhash].js'
},

View File

@ -68,6 +68,10 @@ export default function ({ isClient, isServer }) {
presets: ['vue-app'],
cacheDirectory: !!this.dev
})
},
{
test: /\.css$/,
loader: 'vue-style-loader!css-loader'
}
]
},

View File

@ -3,6 +3,7 @@
import { each } from 'lodash'
import webpack from 'webpack'
import HTMLPlugin from 'html-webpack-plugin'
import FriendlyErrorsWebpackPlugin from 'friendly-errors-webpack-plugin'
import ScriptExtHtmlWebpackPlugin from 'script-ext-html-webpack-plugin'
import PreloadWebpackPlugin from 'preload-webpack-plugin'
import ProgressBarPlugin from 'progress-bar-webpack-plugin'
@ -77,12 +78,20 @@ export default function () {
config.plugins.push(
new ProgressBarPlugin()
)
// Add friendly error plugin
if (this.dev) {
config.plugins.push(new FriendlyErrorsWebpackPlugin())
}
// Production client build
if (!this.dev) {
config.plugins.push(
// This is needed in webpack 2 for minifying CSS
new webpack.LoaderOptionsPlugin({
minimize: true
}),
// Minify JS
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}

View File

@ -43,7 +43,14 @@ export default function () {
}))
])
})
// This is needed in webpack 2 for minifying CSS
if (!this.dev) {
config.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true
})
)
}
// Externals
const nuxtPackageJson = require('../../package.json')
const projectPackageJsonPath = resolve(this.dir, 'package.json')

View File

@ -11,6 +11,7 @@ export default function ({ isClient }) {
postcss: this.options.build.postcss,
loaders: {
'js': 'babel-loader?' + babelOptions,
'css': 'vue-style-loader!css-loader',
'less': 'vue-style-loader!css-loader!less-loader',
'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax',
'scss': 'vue-style-loader!css-loader!sass-loader',

View File

@ -63,6 +63,7 @@
"css-loader": "^0.27.3",
"debug": "^2.6.3",
"file-loader": "^0.10.1",
"friendly-errors-webpack-plugin": "^1.6.1",
"fs-extra": "^2.1.2",
"glob": "^7.1.1",
"hash-sum": "^1.0.2",