我已经用jhipster创建了一个项目,几个月前,我已经停止使用prod版本,并一直在使用开发版本,但是就服务器空间而言它们太昂贵了,性能太慢了……我正在构建未进行生产构建的产品,因此,为了使应用程序流畅,流畅地工作,我尝试运行产品构建。 任何帮助将不胜感激。
这是我的webpack.prod.js
/**
* Production config for the app.
*/
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-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';
const extractSASS = new ExtractTextPlugin(`assets/css/[name].[hash].css`);
const extractCSS = new ExtractTextPlugin(`assets/[name].[hash].css`);
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/polyfills',
global: './src/assets/scss/global.scss',
main: './src/main',
},
output: {
path: utils.root('./../../public/app'),
publicPath: 'app/',
filename: '[name].[hash].bundle.js',
chunkFilename: '[id].[hash].chunk.js',
pathinfo: false
},
module: {
rules: [
{
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
use: ['@ngtools/webpack']
},
{
test: /\.scss$/,
loaders: ['to-string-loader', 'css-loader', 'sass-loader'],
exclude: /(vendor\.scss|global\.scss)/
},
{
test: /(vendor\.scss|global\.scss)/,
use: extractSASS.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader', 'sass-loader'],
})
},
{
test: /\.css$/,
loaders: ['to-string-loader', 'css-loader'],
exclude: /(vendor\.css|global\.css)/
},
{
test: /(vendor\.css|global\.css)/,
use: extractCSS.extract({
fallback: 'style-loader',
use: ['css-loader'],
})
}
]
},
optimization: {
runtimeChunk: false,
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
},
minimizer: [
new UglifyJSPlugin({
parallel: true,
uglifyOptions: {
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
}
}
})
]
},
plugins: [
extractSASS,
extractCSS,
new MomentLocalesPlugin({
localesToKeep: [
'en',
'es'
]
}),
new AngularCompilerPlugin({
platform: 0,
mainPath: utils.root('./src/main.ts'),
tsConfigPath: utils.root('tsconfig-aot.json'),
sourceMap: true,
skipCodeGeneration: true,
compilerOptions: {}
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new WorkboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true,
})
],
mode: 'production'
});
这是我的package.json
{
"name": "Harshit-demo",
"version": "0.0.1",
"description": "a demo project ",
"private": true,
"cacheDirectories": [
"node_modules"
],
"engines": {
"node": ">=8.11.3",
"yarn": ">=1.7.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"IE 11"
],
"dependencies": {
"@angular/animations": "^7.2.12",
"@angular/cdk": "^6.4.7",
"@angular/common": "^7.2.12",
"@angular/compiler": "^7.2.12",
"@angular/core": "^7.2.12",
"@angular/forms": "^7.2.12",
"@angular/http": "^7.2.12",
"@angular/platform-browser": "^7.2.12",
"@angular/platform-browser-dynamic": "^7.2.12",
"@angular/platform-server": "^7.2.12",
"@angular/router": "^7.2.12",
"@ng-idle/core": "^6.0.0-beta.5",
"@ng-idle/keepalive": "^6.0.0-beta.5",
"@types/html2canvas": "0.0.35",
"@types/socket.io-client": "^1.4.32",
"angular-laravel-echo": "^2.1.0",
"classlist.js": "^1.1.20150312",
"core-js": "^2.6.3",
"html2canvas": "^1.0.0-rc.1",
"jspdf": "^1.5.3",
"laravel-echo": "^1.4.1",
"libphonenumber-js": "^1.7.15",
"ng-connection-service": "^1.0.4",
"ng-simple-slideshow": "^1.2.9",
"ngx-cookie": "4.0.2",
"ngx-filesaver": "^2.1.1",
"reflect-metadata": "0.1.12",
"socket.io-client": "^2.1.1",
"tslib": "1.9.0",
"zone.js": "^0.8.29"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.12.3",
"@angular/cli": "^7.3.8",
"@angular/compiler-cli": "^7.2.12",
"@angular/language-service": "^7.2.12",
"@ngtools/webpack": "^6.1.1",
"@types/jasmine": "^3.3.8",
"@types/jasminewd2": "2.0.3",
"@types/jquery": "^3.3.5",
"@types/node": "^10.14.4",
"angular-router-loader": "^0.8.5",
"angular2-template-loader": "^0.6.2",
"browser-sync": "^2.26.0",
"browser-sync-webpack-plugin": "^2.2.2",
"cache-loader": "^1.2.5",
"codelyzer": "^4.5.0",
"copy-webpack-plugin": "^4.5.2",
"css-loader": "^1.0.1",
"del-cli": "^1.1.0",
"exports-loader": "0.7.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"file-loader": "^1.1.11",
"fork-ts-checker-webpack-plugin": "0.4.1",
"friendly-errors-webpack-plugin": "1.7.0",
"hard-source-webpack-plugin": "^0.12.0",
"html-loader": "0.5.5",
"html-webpack-plugin": "3.2.0",
"husky": "0.14.3",
"image-webpack-loader": "^4.5.0",
"jasmine-core": "^3.4.0",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^4.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "^2.0.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "^2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"lint-staged": "7.0.0",
"merge-jsons-webpack-plugin": "1.0.14",
"moment-locales-webpack-plugin": "1.0.5",
"node-sass": "^4.9.3",
"postcss-loader": "2.1.1",
"protractor": "^5.4.2",
"proxy-middleware": "0.15.0",
"raw-loader": "0.5.1",
"rimraf": "2.6.1",
"sass-loader": "7.0.1",
"simple-progress-webpack-plugin": "1.1.2",
"style-loader": "0.20.3",
"tapable": "1.0.0",
"thread-loader": "1.1.5",
"to-string-loader": "1.1.5",
"ts-loader": "4.0.1",
"ts-node": "5.0.1",
"tslint": "^5.12.1",
"tslint-config-prettier": "1.9.0",
"tslint-loader": "3.6.0",
"typescript": "^3.2.4",
"uglifyjs-webpack-plugin": "1.2.5",
"webdriver-manager": "^12.1.0",
"webpack": "4.8.2",
"webpack-cli": "2.1.3",
"webpack-dev-server": "3.1.10",
"webpack-merge": "4.1.2",
"webpack-notifier": "1.6.0",
"webpack-visualizer-plugin": "0.1.11",
"workbox-webpack-plugin": "3.4.1",
"write-file-webpack-plugin": "4.2.0",
"xml2js": "0.4.19"
},
"resolutions": {},
"scripts": {
"ng": "ng",
"clean:cache": "yarn cache clean",
"clean": "rimraf ../../public/app/*",
"build:dev": "yarn run webpack:dev",
"build:prod": "yarn run webpack:prod",
"serve": "yarn run webpack:dev-run",
"lint": "tslint -c tslint.json -p tsconfig.json -e 'node_modules/**'",
"lint:fix": "yarn run lint --fix",
"protractor": "protractor test/protractor.conf.js",
"e2e": "protractor test/protractor.conf.js",
"test": "yarn run lint && jest --coverage --logHeapUsage -w=2 --config test/javascript/jest.conf.js",
"test:watch": "yarn test --watch --clearCache",
"webpack:dev-run": "yarn run webpack-dev-server --config webpack/webpack.dev.js --watch-content-base --env.stats=minimal",
"webpack:dev": "yarn run clean && yarn run webpack --config webpack/webpack.dev.js --env.stats=normal",
"webpack:prod": "yarn run clean && yarn run webpack --config webpack/webpack.prod.js",
"webpack-dev-server": "node node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"webpack": "node node_modules/webpack/bin/webpack.js"
}
}