-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.common.js
More file actions
151 lines (148 loc) · 5.16 KB
/
webpack.common.js
File metadata and controls
151 lines (148 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const { hashElement } = require('folder-hash');
const MergeJsonWebpackPlugin = require('merge-jsons-webpack-plugin');
const utils = require('./utils.js');
const environment = require('./environment');
const getTsLoaderRule = env => {
const rules = [
{
loader: 'thread-loader',
options: {
// There should be 1 cpu for the fork-ts-checker-webpack-plugin.
// The value may need to be adjusted (e.g. to 1) in some CI environments,
// as cpus() may report more cores than what are available to the build.
workers: require('os').cpus().length - 1,
},
},
{
loader: 'ts-loader',
options: {
transpileOnly: true,
happyPackMode: true,
},
},
];
return rules;
};
module.exports = async options => {
const development = options.env === 'development';
const languagesHash = await hashElement(path.resolve(__dirname, '../src/main/webapp/i18n'), {
algo: 'md5',
encoding: 'hex',
files: { include: ['*.json'] },
});
return merge(
{
cache: {
// 1. Set cache type to filesystem
type: 'filesystem',
cacheDirectory: path.resolve(__dirname, '../target/webpack'),
buildDependencies: {
// 2. Add your config as buildDependency to get cache invalidation on config change
config: [
__filename,
path.resolve(__dirname, `webpack.${development ? 'dev' : 'prod'}.js`),
path.resolve(__dirname, 'environment.js'),
path.resolve(__dirname, 'utils.js'),
path.resolve(__dirname, '../postcss.config.js'),
path.resolve(__dirname, '../tsconfig.json'),
],
},
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
modules: ['node_modules'],
alias: utils.mapTypescriptAliasToWebpackAlias(),
fallback: {
path: require.resolve('path-browserify'),
},
},
module: {
rules: [
{
test: /\.tsx?$/,
use: getTsLoaderRule(options.env),
include: [utils.root('./src/main/webapp/app')],
exclude: [utils.root('node_modules')],
},
/*
,
Disabled due to https://github.com/jhipster/generator-jhipster/issues/16116
Can be enabled with @reduxjs/toolkit@>1.6.1
{
enforce: 'pre',
test: /\.jsx?$/,
loader: 'source-map-loader'
}
*/
],
},
stats: {
children: false,
},
plugins: [
new webpack.EnvironmentPlugin({
// react-jhipster requires LOG_LEVEL config.
LOG_LEVEL: development ? 'info' : 'error',
}),
new webpack.DefinePlugin({
I18N_HASH: JSON.stringify(languagesHash.hash),
DEVELOPMENT: JSON.stringify(development),
VERSION: JSON.stringify(environment.VERSION),
SERVER_API_URL: JSON.stringify(environment.SERVER_API_URL),
}),
new ESLintPlugin({
baseConfig: {
parserOptions: {
project: ['../tsconfig.json'],
},
},
}),
new ForkTsCheckerWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{
// https://github.com/swagger-api/swagger-ui/blob/v4.6.1/swagger-ui-dist-package/README.md
context: require('swagger-ui-dist').getAbsoluteFSPath(),
from: '*.{js,css,html,png}',
to: 'swagger-ui/',
globOptions: { ignore: ['**/index.html'] },
},
{
from: require.resolve('axios/dist/axios.min.js'),
to: 'swagger-ui/',
},
{ from: './src/main/webapp/swagger-ui/', to: 'swagger-ui/' },
{ from: './src/main/webapp/content/', to: 'content/' },
{ from: './src/main/webapp/favicon.ico', to: 'favicon.ico' },
{ from: './src/main/webapp/manifest.webapp', to: 'manifest.webapp' },
// jhipster-needle-add-assets-to-webpack - JHipster will add/remove third-party resources in this array
{ from: './src/main/webapp/robots.txt', to: 'robots.txt' },
],
}),
new HtmlWebpackPlugin({
template: './src/main/webapp/index.html',
chunksSortMode: 'auto',
inject: 'body',
base: '/',
}),
new MergeJsonWebpackPlugin({
output: {
groupBy: [
{ pattern: './src/main/webapp/i18n/en/*.json', fileName: './i18n/en.json' },
{ pattern: './src/main/webapp/i18n/tr/*.json', fileName: './i18n/tr.json' },
// jhipster-needle-i18n-language-webpack - JHipster will add/remove languages in this array
],
},
}),
],
}
// jhipster-needle-add-webpack-config - JHipster will add custom config
);
};