[add] Jhipster base

This commit is contained in:
2018-08-06 21:49:34 -06:00
parent 1390427ec0
commit 11626e6efb
247 changed files with 145182 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,28 @@
const fs = require('fs');
const path = require('path');
module.exports = {
parseVersion,
root,
isExternalLib
};
// Returns a static version number when server is skipped
function parseVersion() {
return '0.0.1-SNAPSHOT';
}
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;
}

View File

@@ -0,0 +1,121 @@
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const path = require('path');
const utils = require('./utils.js');
const getTsLoaderRule = env => {
const rules = [
{
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
}
}
];
if (env === 'development') {
rules.unshift({
loader: 'react-hot-loader/webpack'
});
}
return rules;
};
module.exports = options => ({
cache: options.env !== 'production',
resolve: {
extensions: [
'.js', '.jsx', '.ts', '.tsx', '.json'
],
modules: ['node_modules'],
alias: {
app: utils.root('src/main/webapp/app/')
}
},
module: {
rules: [
{
test: /\.tsx?$/,
use: getTsLoaderRule(options.env),
include: [utils.root('./src/main/webapp/app')],
exclude: ['node_modules']
},
{
test: /\.(jpe?g|png|gif|svg|woff2?|ttf|eot)$/i,
loaders: ['file-loader?hash=sha512&digest=hex&name=content/[hash].[ext]']
},
{
enforce: 'pre',
test: /\.jsx?$/,
loader: 'source-map-loader'
},
{
test: /\.tsx?$/,
enforce: 'pre',
loaders: 'tslint-loader',
exclude: ['node_modules']
}
]
},
stats: {
children: false
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: `'${options.env}'`,
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 ForkTsCheckerWebpackPlugin({ tslint: true }),
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/static/', 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: 'dependency',
inject: 'body'
}),
]
});

View File

@@ -0,0 +1,81 @@
const webpack = require('webpack');
const writeFilePlugin = require('write-file-webpack-plugin');
const webpackMerge = require('webpack-merge');
const BrowserSyncPlugin = require('browser-sync-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: 'cheap-module-source-map', // https://reactjs.org/docs/cross-origin-errors.html
mode: ENV,
entry: [
'react-hot-loader/patch',
'./src/main/webapp/app/index'
],
output: {
path: utils.root('build/www'),
filename: 'app/[name].bundle.js',
chunkFilename: 'app/[id].chunk.js'
},
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
loaders: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader']
},
]
},
devServer: {
stats: options.stats,
hot: true,
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://127.0.0.1:8080',
secure: false,
headers: { host: 'localhost:9000' }
}],
watchOptions: {
ignored: /node_modules/
}
},
plugins: [
new SimpleProgressWebpackPlugin({
format: options.stats === 'minimal' ? 'compact' : 'expanded'
}),
new FriendlyErrorsWebpackPlugin(),
new BrowserSyncPlugin({
host: 'localhost',
port: 9000,
proxy: {
target: 'http://localhost:9060'
}
}, {
reload: false
}),
new webpack.HotModuleReplacementPlugin(),
new writeFilePlugin(),
new webpack.WatchIgnorePlugin([
utils.root('src/test'),
]),
new WebpackNotifierPlugin({
title: 'JHipster',
contentImage: path.join(__dirname, 'logo-jhipster.png')
})
]
});

View File

@@ -0,0 +1,90 @@
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const path = require('path');
const utils = require('./utils.js');
const commonConfig = require('./webpack.common.js');
const ENV = 'production';
module.exports = webpackMerge(commonConfig({ env: ENV }), {
// devtool: 'source-map', // Enable source maps. Please note that this will slow down the build
mode: ENV,
entry: {
main: './src/main/webapp/app/index'
},
output: {
path: utils.root('build/www'),
filename: 'app/[name].[hash].bundle.js',
chunkFilename: 'app/[name].[hash].chunk.js'
},
module: {
rules: [
{
enforce: 'pre',
test: /\.s?css$/,
loader: 'stripcomment-loader'
},
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../'
}
},
'css-loader',
'postcss-loader',
'sass-loader'
]
},
]
},
optimization: {
runtimeChunk: false,
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
// sourceMap: true, // Enable source maps. Please note that this will slow down the build
uglifyOptions: {
beautify: false,
comments: false,
compress: {
warnings: false
},
mangle: {
keep_fnames: true
}
}
}),
new OptimizeCSSAssetsPlugin({})
]
},
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
filename: 'content/[name].[hash].css',
chunkFilename: 'content/[name].[hash].css'
}),
new MomentLocalesPlugin({
localesToKeep: [
// jhipster-needle-i18n-language-moment-webpack - JHipster will add/remove languages in this array
]
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new WorkboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true,
})
]
});