Skip to content

Instantly share code, notes, and snippets.

@webislife
Created April 18, 2019 18:23
Show Gist options
  • Save webislife/95ba2a54f543c410aef8b1466be5bb07 to your computer and use it in GitHub Desktop.
Save webislife/95ba2a54f543c410aef8b1466be5bb07 to your computer and use it in GitHub Desktop.
const
merge = require('webpack-merge'),
baseConfig = require('./webpack.base.js'),
BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin,
VueSSRClientPlugin = require('vue-server-renderer/client-plugin'),
path = require('path'),
webpack = require('webpack'),
appConf = require('./../src/env.conf.js'),
sassVars = require('./../src/sass/sass_context'),
webpackExternals = [],
webpackPlugins = [],
sassRecources = [
path.resolve(__dirname, "./../src/sass/_context.scss")
],
styleLoader = [
'vue-style-loader',
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options: {
data: Object.keys(sassVars).map(key => '$' + key + ": " + '"' + sassVars[key] + '";').join(" "),
}
},
{
loader: 'sass-resources-loader',
options: {
resources: sassRecources
}
},
];
//Forward config into application
webpackPlugins.push(
new webpack.DefinePlugin({
'appConf': JSON.stringify(appConf),
"process.env.VUE_ENV": "'client'"
})
)
if(appConf.ENV === 'production') {
webpackPlugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
logLevel: 'warn',
generateStatsFile: true,
statsFilename: 'webpack-stats.json'
}));
}
webpackPlugins.push(new VueSSRClientPlugin({
filename: 'client-manifest.json'
}))
module.exports = merge(baseConfig, {
entry: {
"client/index": './src/client/index.js'
},
mode: appConf.NODE_ENV,
target:"web",
externals: webpackExternals,
output: {
filename: '[name].js',
chunkFilename: "[name].js?" + Date.now(),
path: path.resolve(__dirname, appConf.DIST),
publicPath: appConf.PUBLIC_PATH,
},
module: {
rules: [{
test: /\.vue$/,
use: {
loader: 'vue-loader',
options: {
hotReload: appConf.NODE_ENV === 'development',
loaders: {
js: 'babel-loader',
scss: styleLoader
}
}
}
},
{
test: /\.scss$/,
use: styleLoader
},
{
test: /\.js$/,
exclude: /(node_modules)/,
use: 'babel-loader'
},
{
test: /\.(png|jpe?g|gif|ico)(\?.*)?$/,
loader: "url-loader",
options: {
limit: 10000,
name: "img/[name].[hash:16].[ext]"
}
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
loader: "url-loader?limit=10000"
},
{
test: /\.svg$/,
loader: 'svg-sprite-loader',
options: {
symbolId: filePath => path.basename(filePath),
publicPath: '/'
}
},
]
},
plugins: webpackPlugins
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment