Created
October 26, 2019 19:58
-
-
Save shobishani/f12966617b5a1a3b2f352208850cdfd7 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 CleanWebpackPlugin = require('clean-webpack-plugin'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const StyleLintPlugin = require('stylelint-webpack-plugin'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | |
const merge = require('webpack-merge'); | |
const common = require('./webpack.common.config'); | |
const path = require('path'); | |
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin"); | |
const smp = new SpeedMeasurePlugin(); | |
const { | |
EnvironmentPlugin, | |
} = require('webpack'); | |
const { | |
GENERAL, | |
PATHS, | |
} = require('../../settings'); | |
module.exports = smp.wrap(merge(common, { | |
mode: 'production', | |
devtool: 'source-map', | |
module: { | |
rules: [ | |
{ | |
test: /\.tsx?$/, | |
exclude: /node_modules/, | |
loader: 'tslint-loader', | |
enforce: 'pre', | |
options: { | |
configFile: PATHS.configs.tslint, | |
emitErrors: true, | |
typeCheck: true, | |
tsConfigFile: PATHS.configs.tsconfig, | |
}, | |
}, | |
{ | |
test: /\.(s*)css$/, | |
exclude: /node_modules/, | |
use: ExtractTextPlugin.extract({ | |
fallback: { | |
loader: 'style-loader', | |
options: { | |
sourceMap: false, | |
} | |
}, | |
use: [ | |
{ | |
loader: 'css-loader', | |
options: { | |
importLoaders: 2, | |
localIdentName: '[name]__[hash:base64:6]', | |
minimize: true, | |
modules: true, | |
namedExport: true, | |
sourceMap: false, | |
}, | |
}, | |
{ | |
loader: 'postcss-loader', | |
options: { | |
sourceMap: false, | |
}, | |
}, | |
{ | |
loader: 'sass-loader', | |
options: { | |
sourceMap: false, | |
}, | |
}, | |
], | |
}) | |
} | |
] | |
}, | |
optimization: { | |
runtimeChunk: 'single', | |
splitChunks: { | |
chunks: 'all', | |
maxInitialRequests: Infinity, | |
minSize: 0, | |
cacheGroups: { | |
vendor: { | |
test: /[\\/]node_modules[\\/]/, | |
name(module) { | |
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]; | |
return `npm.${packageName.replace('@', '')}`; | |
}, | |
}, | |
} | |
}, | |
minimizer: [ | |
new UglifyJsPlugin({ | |
cache: path.join(PATHS.cache, 'uglifyjs-webpack-plugin'), | |
parallel: true, | |
sourceMap: false, | |
uglifyOptions: { | |
compress: true, | |
mangle: true, | |
}, | |
}), | |
] | |
}, | |
plugins: [ | |
new CleanWebpackPlugin([PATHS.static, PATHS.templates], { | |
root: PATHS.backend, | |
}), | |
new ExtractTextPlugin({ | |
allChunks: true, | |
filename: '[name].[hash].css', | |
}), | |
new HtmlWebpackPlugin({ | |
filename: PATHS.index.output, | |
template: PATHS.index.input, | |
title: GENERAL.name, | |
cache: true, | |
minify: true, | |
}), | |
new StyleLintPlugin({ | |
configFile: PATHS.configs.stylelint, | |
context: PATHS.client, | |
emitErrors: true, | |
files: [ | |
'styles/*.scss', | |
'app/**/*.scss', | |
], | |
syntax: 'scss', | |
quiet: true, | |
}), | |
new EnvironmentPlugin({ | |
// * explicitly setting the node environment variable for clarity | |
NODE_ENV: 'production', | |
}), | |
], | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment