namesny-com/webpack.config.js

103 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-07-15 14:52:09 +00:00
const { resolve, join } = require('path')
const webpack = require('webpack')
2018-12-27 19:24:59 +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")
const ManifestPlugin = require('webpack-manifest-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const nodeExternals = require('webpack-node-externals')
2017-04-07 19:57:56 +00:00
2018-12-27 19:24:59 +00:00
const commonConfig = {
rules: [
{
test: /\.js$/,
use: [
'babel-loader'
],
exclude: '/node_modules/'
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 2,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
},
{
loader: "postcss-loader"
},
{
loader: 'sass-loader'
}
]
},
{
test: /\.(png|jpg)$/,
exclude: /node_modules/,
loader: 'url-loader',
options: {
limit: 8192
}
},
]
}
const browserConfig = {
mode: 'production',
2017-07-15 14:52:09 +00:00
context: resolve(__dirname, 'src'),
entry: {
2018-07-25 19:04:10 +00:00
bundle: [
2017-07-15 14:52:09 +00:00
'./app-client.js'
]
},
2017-04-07 19:57:56 +00:00
output: {
2018-12-27 19:24:59 +00:00
path: resolve(__dirname, 'public/static'),
filename: '[name].[contenthash].js',
2017-07-15 14:52:09 +00:00
publicPath: '/static/'
2017-04-07 19:57:56 +00:00
},
2018-12-27 19:24:59 +00:00
module: commonConfig,
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true // set to true if you want JS source maps
}),
new OptimizeCSSAssetsPlugin({})
2017-04-07 19:57:56 +00:00
]
},
2017-07-15 14:52:09 +00:00
plugins: [
2018-12-27 19:24:59 +00:00
new webpack.DefinePlugin({__isBrowser__: "true"}),
2018-12-28 13:42:58 +00:00
new CleanWebpackPlugin(['public/static'], {}),
2018-12-27 19:24:59 +00:00
new MiniCssExtractPlugin({filename: '[name].[contenthash].css'}),
2018-12-28 13:42:58 +00:00
// new CompressionPlugin({}),
// new ManifestPlugin(),
2018-12-27 19:24:59 +00:00
]
}
const serverConfig = {
entry: './src/server.js',
target: 'node',
externals: [nodeExternals()],
output: {
path: __dirname,
filename: 'server.js',
publicPath: '/'
},
module: commonConfig,
plugins: [
new webpack.DefinePlugin({
__isBrowser__: "false"
}),
new MiniCssExtractPlugin({filename: '[name].[contenthash].css'}),
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]