Initial application generated by JHipster-5.8.2
This commit is contained in:
BIN
webpack/logo-jhipster.png
Normal file
BIN
webpack/logo-jhipster.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
30
webpack/utils.js
Normal file
30
webpack/utils.js
Normal file
@ -0,0 +1,30 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
parseVersion,
|
||||
root,
|
||||
isExternalLib
|
||||
};
|
||||
|
||||
// Returns the second occurrence of the version number from `build.gradle` file
|
||||
function parseVersion() {
|
||||
const versionRegex = /^version\s*=\s*[',"]([^',"]*)[',"]/gm; // Match and group the version number
|
||||
const buildGradle = fs.readFileSync('build.gradle', 'utf8');
|
||||
return versionRegex.exec(buildGradle)[1];
|
||||
}
|
||||
|
||||
const _root = path.resolve(__dirname, '..');
|
||||
|
||||
function root(args) {
|
||||
args = Array.prototype.slice.call(arguments, 0);
|
||||
return path.join.apply(path, [_root].concat(args));
|
||||
}
|
||||
|
||||
function isExternalLib(module, check = /node_modules/) {
|
||||
const req = module.userRequest;
|
||||
if (typeof req !== 'string') {
|
||||
return false;
|
||||
}
|
||||
return req.search(check) >= 0;
|
||||
}
|
96
webpack/webpack.common.js
Normal file
96
webpack/webpack.common.js
Normal file
@ -0,0 +1,96 @@
|
||||
const webpack = require('webpack');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const rxPaths = require('rxjs/_esm5/path-mapping');
|
||||
const MergeJsonWebpackPlugin = require("merge-jsons-webpack-plugin");
|
||||
|
||||
const utils = require('./utils.js');
|
||||
|
||||
module.exports = (options) => ({
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js'],
|
||||
modules: ['node_modules'],
|
||||
alias: {
|
||||
app: utils.root('src/main/webapp/app/'),
|
||||
...rxPaths()
|
||||
}
|
||||
},
|
||||
stats: {
|
||||
children: false
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.html$/,
|
||||
loader: 'html-loader',
|
||||
options: {
|
||||
minimize: true,
|
||||
caseSensitive: true,
|
||||
removeAttributeQuotes:false,
|
||||
minifyJS:false,
|
||||
minifyCSS:false
|
||||
},
|
||||
exclude: /(src\/main\/webapp\/index.html)/
|
||||
},
|
||||
{
|
||||
test: /\.(jpe?g|png|gif|svg|woff2?|ttf|eot)$/i,
|
||||
loader: 'file-loader',
|
||||
options: {
|
||||
digest: 'hex',
|
||||
hash: 'sha512',
|
||||
name: 'content/[hash].[ext]'
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /manifest.webapp$/,
|
||||
loader: 'file-loader',
|
||||
options: {
|
||||
name: 'manifest.webapp'
|
||||
}
|
||||
},
|
||||
// Ignore warnings about System.import in Angular
|
||||
{ test: /[\/\\]@angular[\/\\].+\.js$/, parser: { system: true } },
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: `'${options.env}'`,
|
||||
BUILD_TIMESTAMP: `'${new Date().getTime()}'`,
|
||||
VERSION: `'${utils.parseVersion()}'`,
|
||||
DEBUG_INFO_ENABLED: options.env === 'development',
|
||||
// The root URL for API calls, ending with a '/' - for example: `"https://www.jhipster.tech:8081/myservice/"`.
|
||||
// If this URL is left empty (""), then it will be relative to the current context.
|
||||
// If you use an API server, in `prod` mode, you will need to enable CORS
|
||||
// (see the `jhipster.cors` common JHipster property in the `application-*.yml` configurations)
|
||||
SERVER_API_URL: `''`
|
||||
}
|
||||
}),
|
||||
new CopyWebpackPlugin([
|
||||
{ from: './node_modules/swagger-ui/dist/css', to: 'swagger-ui/dist/css' },
|
||||
{ from: './node_modules/swagger-ui/dist/lib', to: 'swagger-ui/dist/lib' },
|
||||
{ from: './node_modules/swagger-ui/dist/swagger-ui.min.js', to: 'swagger-ui/dist/swagger-ui.min.js' },
|
||||
{ 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 MergeJsonWebpackPlugin({
|
||||
output: {
|
||||
groupBy: [
|
||||
{ pattern: "./src/main/webapp/i18n/de/*.json", fileName: "./i18n/de.json" },
|
||||
{ pattern: "./src/main/webapp/i18n/en/*.json", fileName: "./i18n/en.json" }
|
||||
// jhipster-needle-i18n-language-webpack - JHipster will add/remove languages in this array
|
||||
]
|
||||
}
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
template: './src/main/webapp/index.html',
|
||||
chunks: ['vendors', 'polyfills', 'main', 'global'],
|
||||
chunksSortMode: 'manual',
|
||||
inject: 'body'
|
||||
})
|
||||
]
|
||||
});
|
132
webpack/webpack.dev.js
Normal file
132
webpack/webpack.dev.js
Normal file
@ -0,0 +1,132 @@
|
||||
const webpack = require('webpack');
|
||||
const writeFilePlugin = require('write-file-webpack-plugin');
|
||||
const webpackMerge = require('webpack-merge');
|
||||
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
|
||||
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
||||
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
|
||||
const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin');
|
||||
const WebpackNotifierPlugin = require('webpack-notifier');
|
||||
const path = require('path');
|
||||
|
||||
const utils = require('./utils.js');
|
||||
const commonConfig = require('./webpack.common.js');
|
||||
|
||||
const ENV = 'development';
|
||||
|
||||
module.exports = (options) => webpackMerge(commonConfig({ env: ENV }), {
|
||||
devtool: 'eval-source-map',
|
||||
devServer: {
|
||||
contentBase: './build/www',
|
||||
proxy: [{
|
||||
context: [
|
||||
/* jhipster-needle-add-entity-to-webpack - JHipster will add entity api paths here */
|
||||
'/api',
|
||||
'/management',
|
||||
'/swagger-resources',
|
||||
'/v2/api-docs',
|
||||
'/h2-console',
|
||||
'/auth'
|
||||
],
|
||||
target: `http${options.tls ? 's' : ''}://127.0.0.1:8080`,
|
||||
secure: false,
|
||||
changeOrigin: options.tls,
|
||||
headers: { host: 'localhost:9000' }
|
||||
}],
|
||||
stats: options.stats,
|
||||
watchOptions: {
|
||||
ignored: /node_modules/
|
||||
}
|
||||
},
|
||||
entry: {
|
||||
polyfills: './src/main/webapp/app/polyfills',
|
||||
global: './src/main/webapp/content/css/global.css',
|
||||
main: './src/main/webapp/app/app.main'
|
||||
},
|
||||
output: {
|
||||
path: utils.root('build/www'),
|
||||
filename: 'app/[name].bundle.js',
|
||||
chunkFilename: 'app/[id].chunk.js'
|
||||
},
|
||||
module: {
|
||||
rules: [{
|
||||
test: /\.ts$/,
|
||||
enforce: 'pre',
|
||||
loader: 'tslint-loader',
|
||||
exclude: [/(node_modules)/, new RegExp('reflect-metadata\\' + path.sep + 'Reflect\\.ts')]
|
||||
},
|
||||
{
|
||||
test: /\.ts$/,
|
||||
use: [
|
||||
'angular2-template-loader',
|
||||
{
|
||||
loader: 'cache-loader',
|
||||
options: {
|
||||
cacheDirectory: path.resolve('build/cache-loader')
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: 'thread-loader',
|
||||
options: {
|
||||
// there should be 1 cpu for the fork-ts-checker-webpack-plugin
|
||||
workers: require('os').cpus().length - 1
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
transpileOnly: true,
|
||||
happyPackMode: true
|
||||
}
|
||||
},
|
||||
'angular-router-loader'
|
||||
],
|
||||
exclude: /(node_modules)/
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ['to-string-loader', 'css-loader'],
|
||||
exclude: /(vendor\.css|global\.css)/
|
||||
},
|
||||
{
|
||||
test: /(vendor\.css|global\.css)/,
|
||||
use: ['style-loader', 'css-loader']
|
||||
}]
|
||||
},
|
||||
stats: process.env.JHI_DISABLE_WEBPACK_LOGS ? 'none' : options.stats,
|
||||
plugins: [
|
||||
process.env.JHI_DISABLE_WEBPACK_LOGS
|
||||
? null
|
||||
: new SimpleProgressWebpackPlugin({
|
||||
format: options.stats === 'minimal' ? 'compact' : 'expanded'
|
||||
}),
|
||||
new FriendlyErrorsWebpackPlugin(),
|
||||
new ForkTsCheckerWebpackPlugin(),
|
||||
new BrowserSyncPlugin({
|
||||
host: 'localhost',
|
||||
port: 9000,
|
||||
proxy: {
|
||||
target: 'http://localhost:9060'
|
||||
},
|
||||
socket: {
|
||||
clients: {
|
||||
heartbeatTimeout: 60000
|
||||
}
|
||||
}
|
||||
}, {
|
||||
reload: false
|
||||
}),
|
||||
new webpack.ContextReplacementPlugin(
|
||||
/angular(\\|\/)core(\\|\/)/,
|
||||
path.resolve(__dirname, './src/main/webapp')
|
||||
),
|
||||
new writeFilePlugin(),
|
||||
new webpack.WatchIgnorePlugin([
|
||||
utils.root('src/test'),
|
||||
]),
|
||||
new WebpackNotifierPlugin({
|
||||
title: 'JHipster',
|
||||
contentImage: path.join(__dirname, 'logo-jhipster.png')
|
||||
})
|
||||
].filter(Boolean),
|
||||
mode: 'development'
|
||||
});
|
125
webpack/webpack.prod.js
Normal file
125
webpack/webpack.prod.js
Normal file
@ -0,0 +1,125 @@
|
||||
const webpack = require('webpack');
|
||||
const webpackMerge = require('webpack-merge');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
|
||||
const Visualizer = require('webpack-visualizer-plugin');
|
||||
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
const WorkboxPlugin = require('workbox-webpack-plugin');
|
||||
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
|
||||
const path = require('path');
|
||||
|
||||
const utils = require('./utils.js');
|
||||
const commonConfig = require('./webpack.common.js');
|
||||
|
||||
const ENV = 'production';
|
||||
|
||||
module.exports = webpackMerge(commonConfig({ env: ENV }), {
|
||||
// Enable source maps. Please note that this will slow down the build.
|
||||
// You have to enable it in UglifyJSPlugin config below and in tsconfig-aot.json as well
|
||||
// devtool: 'source-map',
|
||||
entry: {
|
||||
polyfills: './src/main/webapp/app/polyfills',
|
||||
global: './src/main/webapp/content/css/global.css',
|
||||
main: './src/main/webapp/app/app.main'
|
||||
},
|
||||
output: {
|
||||
path: utils.root('build/www'),
|
||||
filename: 'app/[name].[hash].bundle.js',
|
||||
chunkFilename: 'app/[id].[hash].chunk.js'
|
||||
},
|
||||
module: {
|
||||
rules: [{
|
||||
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
|
||||
loader: '@ngtools/webpack'
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ['to-string-loader', 'css-loader'],
|
||||
exclude: /(vendor\.css|global\.css)/
|
||||
},
|
||||
{
|
||||
test: /(vendor\.css|global\.css)/,
|
||||
use: [
|
||||
MiniCssExtractPlugin.loader,
|
||||
'css-loader',
|
||||
'postcss-loader'
|
||||
]
|
||||
}]
|
||||
},
|
||||
optimization: {
|
||||
runtimeChunk: false,
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
commons: {
|
||||
test: /[\\/]node_modules[\\/]/,
|
||||
name: 'vendors',
|
||||
chunks: 'all'
|
||||
}
|
||||
}
|
||||
},
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
parallel: true,
|
||||
cache: true,
|
||||
terserOptions: {
|
||||
ie8: false,
|
||||
// sourceMap: true, // Enable source maps. Please note that this will slow down the build
|
||||
compress: {
|
||||
dead_code: true,
|
||||
warnings: false,
|
||||
properties: true,
|
||||
drop_debugger: true,
|
||||
conditionals: true,
|
||||
booleans: true,
|
||||
loops: true,
|
||||
unused: true,
|
||||
toplevel: true,
|
||||
if_return: true,
|
||||
inline: true,
|
||||
join_vars: true
|
||||
},
|
||||
output: {
|
||||
comments: false,
|
||||
beautify: false,
|
||||
indent_level: 2
|
||||
}
|
||||
}
|
||||
}),
|
||||
new OptimizeCSSAssetsPlugin({})
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new MiniCssExtractPlugin({
|
||||
// Options similar to the same options in webpackOptions.output
|
||||
// both options are optional
|
||||
filename: '[name].[contenthash].css',
|
||||
chunkFilename: '[id].css'
|
||||
}),
|
||||
new MomentLocalesPlugin({
|
||||
localesToKeep: [
|
||||
'de',
|
||||
'en'
|
||||
// jhipster-needle-i18n-language-moment-webpack - JHipster will add/remove languages in this array
|
||||
]
|
||||
}),
|
||||
new Visualizer({
|
||||
// Webpack statistics in target folder
|
||||
filename: '../stats.html'
|
||||
}),
|
||||
new AngularCompilerPlugin({
|
||||
mainPath: utils.root('src/main/webapp/app/app.main.ts'),
|
||||
tsConfigPath: utils.root('tsconfig-aot.json'),
|
||||
sourceMap: true
|
||||
}),
|
||||
new webpack.LoaderOptionsPlugin({
|
||||
minimize: true,
|
||||
debug: false
|
||||
}),
|
||||
new WorkboxPlugin.GenerateSW({
|
||||
clientsClaim: true,
|
||||
skipWaiting: true,
|
||||
})
|
||||
],
|
||||
mode: 'production'
|
||||
});
|
Reference in New Issue
Block a user