Skip to content
This repository has been archived by the owner on Jun 8, 2020. It is now read-only.

Commit

Permalink
Fixed issue where production build was throwing errors.
Browse files Browse the repository at this point in the history
- Had to revert babel-loader package and swap mini-css-extract-plugin for extract-text-webpack-plugin
  • Loading branch information
ashour committed Apr 19, 2019
1 parent 079a4b7 commit b77d534
Show file tree
Hide file tree
Showing 29 changed files with 292 additions and 203 deletions.
11 changes: 5 additions & 6 deletions build/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
const path = require('path')
const config = require('../config')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const packageConfig = require('../package.json')

exports.assetsPath = function (_path) {
Expand Down Expand Up @@ -30,7 +30,7 @@ exports.cssLoaders = function (options) {
}

// generate loader string to be used with extract text plugin
function generateLoaders (loader, loaderOptions) {
function generateLoaders(loader, loaderOptions) {
const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]

if (loader) {
Expand All @@ -45,10 +45,9 @@ exports.cssLoaders = function (options) {
// Extract CSS when that option is specified
// (which is the case during production build)
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: 'vue-style-loader'
})
return [
MiniCssExtractPlugin.loader,
].concat(loaders)
} else {
return ['vue-style-loader'].concat(loaders)
}
Expand Down
53 changes: 16 additions & 37 deletions build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

const env = require('../config/prod.env')

Expand All @@ -27,7 +28,20 @@ const webpackConfig = merge(baseWebpackConfig, {
filename: utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
},
optimization: {
runtimeChunk: 'single', // enable "runtime" chunk
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all'
}
}
}
},
plugins: [
new VueLoaderPlugin(),
// http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({
'process.env': env
Expand All @@ -41,14 +55,8 @@ const webpackConfig = merge(baseWebpackConfig, {
sourceMap: config.build.productionSourceMap,
parallel: true
}),
// extract css into its own file
new ExtractTextPlugin({
new MiniCssExtractPlugin({
filename: utils.assetsPath('css/[name].[contenthash].css'),
// Setting the following option to `false` will not extract CSS from codesplit chunks.
// Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
// It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`,
// increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
allChunks: true,
}),
// Compress extracted CSS. We are using this plugin so that possible
// duplicated CSS from different components can be deduped.
Expand Down Expand Up @@ -78,35 +86,6 @@ const webpackConfig = merge(baseWebpackConfig, {
new webpack.HashedModuleIdsPlugin(),
// enable scope hoisting
new webpack.optimize.ModuleConcatenationPlugin(),
// split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks (module) {
// any required modules inside node_modules are extracted to vendor
return (
module.resource &&
/\.js$/.test(module.resource) &&
module.resource.indexOf(
path.join(__dirname, '../node_modules')
) === 0
)
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
}),
// This instance extracts shared chunks from code splitted chunks and bundles them
// in a separate chunk, similar to the vendor chunk
// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
new webpack.optimize.CommonsChunkPlugin({
name: 'app',
async: 'vendor-async',
children: true,
minChunks: 3
}),

// copy custom static assets
new CopyWebpackPlugin([
Expand Down
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Gawa — A Vue.js I18n Demo</title><link href=/static/css/app.4971dc5b664fd127cd3bda3830fea98b.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.2ae2e69a05c33dfc65f8.js></script><script type=text/javascript src=/static/js/vendor.6ffedde0bc27521e991a.js></script><script type=text/javascript src=/static/js/app.5f542bdd195abc612adc.js></script></body></html>
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Gawa — A Vue.js I18n Demo</title><link href=/static/css/vendor.c53ed0b8a3fd41e3278a.css rel=stylesheet><link href=/static/css/app.e75d7e2daf8bdbd036a9.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/runtime.ecaa6fff7a670ca93401.js></script><script type=text/javascript src=/static/js/2.9d358c86de0d42f4f4ce.js></script><script type=text/javascript src=/static/js/0.7c77e2bcab41f91aa2dd.js></script></body></html>
8 changes: 0 additions & 8 deletions dist/static/css/app.4971dc5b664fd127cd3bda3830fea98b.css

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions dist/static/css/app.e75d7e2daf8bdbd036a9.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b77d534

Please sign in to comment.