Created
April 18, 2019 18:24
-
-
Save webislife/b1cc1740190fe22c489a893961d304ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const merge = require('webpack-merge'), | |
path = require('path'), | |
fs = require('fs'), | |
webpack = require('webpack'), | |
appConf = require('./../src/env.conf.js'), | |
VueSSRServerPlugin = require("vue-server-renderer/server-plugin"), | |
sassVars = require('./../src/sass/sass_context'), | |
baseConfig = require('./webpack.base.js'), | |
sassRecources = [ | |
path.resolve(__dirname, "./../src/sass/_context.scss") | |
], | |
webpackExternals = [], | |
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 | |
} | |
}, | |
]; | |
//Map node_mdoules support as webpack externals array for TARGET=node | |
let nodeModules = {}; | |
fs.readdirSync('node_modules') | |
.filter(x => ['.bin'].indexOf(x) === -1) | |
.forEach(m => { | |
nodeModules[m] = 'commonjs ' + m | |
}); | |
nodeModules['fs'] = 'commonjs fs'; | |
webpackExternals.push(nodeModules); | |
module.exports = merge(baseConfig, { | |
mode: appConf.NODE_ENV, | |
module: { | |
rules: [{ | |
test: /\.vue$/, | |
use: { | |
loader: 'vue-loader', | |
options: { | |
hotReload: appConf.NODE_ENV === 'development', | |
loaders: { | |
js: 'babel-loader' | |
} | |
} | |
} | |
}, | |
{ | |
test: /\.scss$/, | |
use: styleLoader | |
}, | |
{ | |
test: /\.js$/, | |
exclude: /(node_modules|bower_components)/, | |
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) | |
} | |
} | |
] | |
}, | |
target: "node", | |
externals: webpackExternals, | |
entry: { | |
"server/index": './src/server/index.js' | |
}, | |
output: { | |
filename: '[name].js', | |
path: path.resolve(__dirname, appConf.DIST), | |
publicPath: appConf.PUBLIC_PATH, | |
libraryTarget: "commonjs2" | |
}, | |
plugins: [ | |
new webpack.DefinePlugin({ | |
'appConf': JSON.stringify(appConf), | |
"process.env.VUE_ENV": "'server'" | |
}), | |
new VueSSRServerPlugin() | |
] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment