2019-01-09 02:40:57 -06:00
|
|
|
const path = require('path');
|
2020-03-19 01:51:22 -05:00
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
2019-10-21 09:39:43 -05:00
|
|
|
module.exports = ({ config, mode }) => {
|
2020-06-30 04:44:38 -05:00
|
|
|
const isProductionBuild = mode === 'PRODUCTION';
|
2019-10-21 09:39:43 -05:00
|
|
|
config.module.rules = [
|
|
|
|
...(config.module.rules || []),
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: require.resolve('ts-loader'),
|
|
|
|
options: {
|
|
|
|
// transpileOnly: true,
|
2019-10-25 07:35:29 -05:00
|
|
|
configFile: path.resolve(__dirname, 'tsconfig.json'),
|
2019-10-21 09:39:43 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: require.resolve('react-docgen-typescript-loader'),
|
|
|
|
options: {
|
2019-10-25 07:35:29 -05:00
|
|
|
tsconfigPath: path.resolve(__dirname, 'tsconfig.json'),
|
2019-10-21 09:39:43 -05:00
|
|
|
// https://github.com/styleguidist/react-docgen-typescript#parseroptions
|
|
|
|
// @ts-ignore
|
|
|
|
propFilter: prop => {
|
|
|
|
if (prop.parent) {
|
|
|
|
return !prop.parent.fileName.includes('node_modules/@types/react/');
|
|
|
|
}
|
2019-01-09 02:40:57 -06:00
|
|
|
|
2019-10-21 09:39:43 -05:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2019-01-16 03:27:09 -06:00
|
|
|
|
2019-01-09 02:40:57 -06:00
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.scss$/,
|
|
|
|
use: [
|
|
|
|
{
|
2020-03-17 03:52:46 -05:00
|
|
|
loader: 'style-loader',
|
2020-04-09 11:42:59 -05:00
|
|
|
options: { injectType: 'lazyStyleTag' },
|
2019-01-09 02:40:57 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: false,
|
|
|
|
config: { path: __dirname + '../../../../scripts/webpack/postcss.config.js' },
|
|
|
|
},
|
|
|
|
},
|
2019-02-06 10:03:42 -06:00
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
2019-03-21 10:06:55 -05:00
|
|
|
sourceMap: false,
|
2019-02-06 10:03:42 -06:00
|
|
|
},
|
|
|
|
},
|
2019-01-09 02:40:57 -06:00
|
|
|
],
|
|
|
|
});
|
2019-01-16 03:27:09 -06:00
|
|
|
|
|
|
|
config.module.rules.push({
|
|
|
|
test: require.resolve('jquery'),
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'expose-loader',
|
|
|
|
query: 'jQuery',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'expose-loader',
|
|
|
|
query: '$',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2020-03-19 01:51:22 -05:00
|
|
|
config.optimization = {
|
|
|
|
nodeEnv: 'production',
|
2020-06-29 12:58:47 -05:00
|
|
|
moduleIds: 'hashed',
|
|
|
|
runtimeChunk: 'single',
|
|
|
|
splitChunks: {
|
|
|
|
chunks: 'all',
|
|
|
|
minChunks: 1,
|
|
|
|
cacheGroups: {
|
|
|
|
vendors: {
|
|
|
|
test: /[\\/]node_modules[\\/].*[jt]sx?$/,
|
|
|
|
chunks: 'initial',
|
|
|
|
priority: -10,
|
|
|
|
reuseExistingChunk: true,
|
|
|
|
enforce: true,
|
|
|
|
},
|
|
|
|
default: {
|
|
|
|
priority: -20,
|
|
|
|
chunks: 'all',
|
|
|
|
test: /.*[jt]sx?$/,
|
|
|
|
reuseExistingChunk: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-30 04:44:38 -05:00
|
|
|
minimize: isProductionBuild,
|
|
|
|
minimizer: isProductionBuild
|
|
|
|
? [
|
|
|
|
new TerserPlugin({ cache: false, parallel: false, sourceMap: false, exclude: /monaco/ }),
|
|
|
|
new OptimizeCSSAssetsPlugin({}),
|
|
|
|
]
|
|
|
|
: [],
|
2020-04-09 11:42:59 -05:00
|
|
|
};
|
2020-03-19 01:51:22 -05:00
|
|
|
|
2019-10-22 02:05:14 -05:00
|
|
|
config.resolve.extensions.push('.ts', '.tsx', '.mdx');
|
2020-04-09 11:42:59 -05:00
|
|
|
|
2019-10-21 09:39:43 -05:00
|
|
|
config.stats = {
|
|
|
|
warningsFilter: /export .* was not found in/,
|
|
|
|
};
|
2020-03-17 03:52:46 -05:00
|
|
|
|
2019-01-09 02:40:57 -06:00
|
|
|
return config;
|
|
|
|
};
|