2019-02-16 18:32:32 +00:00
|
|
|
const { resolve } = require('path')
|
2017-07-15 14:52:09 +00:00
|
|
|
const webpack = require('webpack')
|
2019-02-16 18:32:32 +00:00
|
|
|
// const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
|
|
// const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
|
|
|
// const CompressionPlugin = require('compression-webpack-plugin')
|
2018-12-27 19:24:59 +00:00
|
|
|
const ManifestPlugin = require('webpack-manifest-plugin')
|
|
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin')
|
|
|
|
const nodeExternals = require('webpack-node-externals')
|
2019-02-18 20:18:55 +00:00
|
|
|
const CreateFileWebpack = require('create-file-webpack')
|
2017-04-07 19:57:56 +00:00
|
|
|
|
2018-12-27 19:24:59 +00:00
|
|
|
const browserConfig = {
|
|
|
|
mode: 'production',
|
2017-07-15 14:52:09 +00:00
|
|
|
entry: {
|
2018-07-25 19:04:10 +00:00
|
|
|
bundle: [
|
2019-02-16 16:56:43 +00:00
|
|
|
'./src/app-client.js'
|
2017-07-15 14:52:09 +00:00
|
|
|
]
|
|
|
|
},
|
2017-04-07 19:57:56 +00:00
|
|
|
output: {
|
2018-12-27 19:24:59 +00:00
|
|
|
path: resolve(__dirname, 'public/static'),
|
2019-01-21 18:21:51 +00:00
|
|
|
filename: '[name].js',
|
|
|
|
// filename: '[name].[contenthash].js',
|
2017-07-15 14:52:09 +00:00
|
|
|
publicPath: '/static/'
|
2017-04-07 19:57:56 +00:00
|
|
|
},
|
2019-02-18 20:18:55 +00:00
|
|
|
devtool: 'eval-source-map',
|
2018-12-29 22:07:50 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
use: [
|
|
|
|
'babel-loader'
|
|
|
|
],
|
|
|
|
exclude: '/node_modules/'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
|
|
|
use: [
|
2019-02-16 16:56:43 +00:00
|
|
|
MiniCssExtractPlugin.loader,
|
2018-12-29 22:07:50 +00:00
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
modules: true,
|
2019-02-16 16:56:43 +00:00
|
|
|
importLoaders: 2,
|
|
|
|
localIdentName: '[name]__[local]___[hash:base64:5]'
|
2018-12-29 22:07:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-02-16 18:32:32 +00:00
|
|
|
loader: 'postcss-loader'
|
2018-12-29 22:07:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 8192
|
|
|
|
}
|
2019-02-16 18:32:32 +00:00
|
|
|
}
|
2017-04-07 19:57:56 +00:00
|
|
|
]
|
|
|
|
},
|
2017-07-15 14:52:09 +00:00
|
|
|
plugins: [
|
2019-02-16 18:32:32 +00:00
|
|
|
new webpack.DefinePlugin({ __isBrowser__: 'true' }),
|
2018-12-29 22:07:50 +00:00
|
|
|
new CleanWebpackPlugin(['public/static', 'build'], {}),
|
2019-02-16 16:56:43 +00:00
|
|
|
new MiniCssExtractPlugin(),
|
2018-12-28 13:42:58 +00:00
|
|
|
// new CompressionPlugin({}),
|
2019-02-16 18:32:32 +00:00
|
|
|
new ManifestPlugin()
|
|
|
|
],
|
|
|
|
node: { fs: 'empty' }
|
2018-12-27 19:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const serverConfig = {
|
|
|
|
entry: './src/server.js',
|
|
|
|
target: 'node',
|
|
|
|
externals: [nodeExternals()],
|
|
|
|
output: {
|
2018-12-29 22:07:50 +00:00
|
|
|
path: resolve(__dirname, 'build'),
|
2018-12-27 19:24:59 +00:00
|
|
|
filename: 'server.js',
|
|
|
|
publicPath: '/'
|
|
|
|
},
|
2018-12-29 22:07:50 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
use: [
|
|
|
|
'babel-loader'
|
|
|
|
],
|
|
|
|
exclude: '/node_modules/'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
|
|
|
use: [
|
2019-02-16 16:56:43 +00:00
|
|
|
MiniCssExtractPlugin.loader,
|
2018-12-29 22:07:50 +00:00
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
modules: true,
|
2019-01-21 18:21:51 +00:00
|
|
|
exportOnlyLocals: true,
|
2018-12-29 22:07:50 +00:00
|
|
|
importLoaders: 2,
|
|
|
|
localIdentName: '[name]__[local]___[hash:base64:5]'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-02-16 16:56:43 +00:00
|
|
|
loader: 'postcss-loader'
|
2018-12-29 22:07:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
2019-02-16 16:56:43 +00:00
|
|
|
limit: 10000
|
2018-12-29 22:07:50 +00:00
|
|
|
}
|
2019-02-16 18:32:32 +00:00
|
|
|
}
|
2018-12-29 22:07:50 +00:00
|
|
|
]
|
|
|
|
},
|
2018-12-27 19:24:59 +00:00
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
2019-02-16 18:32:32 +00:00
|
|
|
__isBrowser__: 'false'
|
2018-12-27 19:24:59 +00:00
|
|
|
}),
|
2019-02-18 20:18:55 +00:00
|
|
|
new MiniCssExtractPlugin(),
|
|
|
|
new CreateFileWebpack({
|
|
|
|
path: './src/utils/',
|
|
|
|
fileName: 'data.json',
|
|
|
|
content: JSON.stringify({
|
|
|
|
'posts': [],
|
|
|
|
'other': []
|
|
|
|
})
|
|
|
|
})
|
2017-07-15 14:52:09 +00:00
|
|
|
]
|
2017-04-07 19:57:56 +00:00
|
|
|
}
|
2018-12-27 19:24:59 +00:00
|
|
|
|
|
|
|
module.exports = [browserConfig, serverConfig]
|