graphql-engine/console/webpack/prod.config.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

174 lines
4.1 KiB
JavaScript
Raw Normal View History

2018-06-28 07:57:37 +03:00
// Webpack config for creating the production bundle.
const path = require('path');
const webpack = require('webpack');
const CleanPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const hasuraConfig = require('../hasuraconfig');
const relativeAssetsPath = '../static/dist';
const assetsPath = path.join(__dirname, relativeAssetsPath);
const TerserPlugin = require('terser-webpack-plugin');
2018-06-28 07:57:37 +03:00
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
2020-03-05 12:31:32 +03:00
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const commonConfig = require('./common.config');
2018-06-28 07:57:37 +03:00
const cleanOptions = {
root: process.cwd(),
verbose: true,
dry: false,
};
module.exports = {
mode: 'production',
context: path.resolve(__dirname, '..'),
entry: {
main: ['./src/client.js'],
2018-06-28 07:57:37 +03:00
},
output: {
path: assetsPath,
filename: '[name].js',
chunkFilename: '[name].js',
publicPath: hasuraConfig.webpackPrefix,
},
2020-02-19 12:59:20 +03:00
node: {
module: 'empty',
fs: 'empty',
net: 'empty',
child_process: 'empty',
},
2018-06-28 07:57:37 +03:00
module: {
rules: [
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
},
{
2020-03-05 12:31:32 +03:00
test: /\.(j|t)sx?$/,
2018-06-28 07:57:37 +03:00
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.flow$/,
loader: 'ignore-loader',
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 2,
sourceMap: false,
modules: {},
},
},
{
loader: 'sass-loader',
options: {
// Prefer `dart-sass`
implementation: require('sass'),
sassOptions: {
outputStyle: 'expanded',
},
sourceMap: false,
sourceMapContents: false,
},
},
2018-06-28 07:57:37 +03:00
],
},
...commonConfig.assetsRules,
2018-06-28 07:57:37 +03:00
],
},
resolve: {
modules: ['src', 'node_modules'],
2020-03-05 12:31:32 +03:00
extensions: ['.json', '.js', '.jsx', '.mjs', '.ts', '.tsx'],
plugins: commonConfig.resolvePlugins,
2018-06-28 07:57:37 +03:00
},
optimization: {
minimize: true,
runtimeChunk: {
name: 'vendor',
},
minimizer: [
new TerserPlugin({
terserOptions: {
2018-06-28 07:57:37 +03:00
ecma: 8,
warnings: false,
compress: false,
mangle: true,
output: {
comments: false,
beautify: false,
},
toplevel: false,
nameCache: null,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
safari10: false,
parallel: 2,
2018-06-28 07:57:37 +03:00
},
extractComments: false,
2018-06-28 07:57:37 +03:00
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/,
}),
],
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'initial',
},
},
},
},
stats: {
errorDetails: true,
},
2018-06-28 07:57:37 +03:00
plugins: [
new CleanPlugin(['./static/dist/*.*'], cleanOptions),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'main.css',
chunkFilename: 'main.css',
}),
new webpack.DefinePlugin({
__CLIENT__: true,
__SERVER__: false,
__DEVELOPMENT__: false,
__DEVTOOLS__: false,
}),
// ignore dev config
new webpack.IgnorePlugin(/\.\/dev/, /\/config$/),
// set global consts
new webpack.DefinePlugin({
'process.env': {
// Useful to reduce the size of client-side libraries, e.g. react
NODE_ENV: JSON.stringify('production'),
},
CONSOLE_ASSET_VERSION: Date.now().toString(),
2020-03-19 19:44:14 +03:00
'process.hrtime': () => null,
2018-06-28 07:57:37 +03:00
}),
2020-03-05 12:31:32 +03:00
new ForkTsCheckerWebpackPlugin({
compilerOptions: {
allowJs: true,
2020-03-05 12:31:32 +03:00
checkJs: false,
},
}),
2018-06-28 07:57:37 +03:00
],
};