Skip to content

Commit

Permalink
some polish
Browse files Browse the repository at this point in the history
  • Loading branch information
deepu105 committed Jun 25, 2017
1 parent df75a8d commit 258106e
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 55 deletions.
2 changes: 1 addition & 1 deletion generators/client/templates/angular/_package.json
Expand Up @@ -141,7 +141,7 @@
"webpack:build:vendor": "webpack --config webpack/webpack.vendor.js --progress --profile",
"webpack:build:dev": "webpack --config webpack/webpack.dev.js --progress --profile",
"webpack:build": "<%= clientPackageManager %> run cleanup && <%= clientPackageManager %> run webpack:build:vendor && <%= clientPackageManager %> run webpack:build:dev",
"webpack:prod": "<%= clientPackageManager %> run cleanup && webpack -p --config webpack/webpack.vendor.js --progress --profile && webpack -p --config webpack/webpack.prod.js --progress --profile",
"webpack:prod": "<%= clientPackageManager %> run cleanup && webpack -p --config webpack/webpack.prod.js --progress --profile --bail",
"webpack:test": "<%= clientPackageManager %> run test",
"test": "<%= clientPackageManager %> run lint && karma start src/test/javascript/karma.conf.js",
"test:watch": "karma start src/test/javascript/karma.conf.js --watch",
Expand Down
10 changes: 5 additions & 5 deletions generators/client/templates/angular/_tsconfig-aot.json
Expand Up @@ -33,12 +33,12 @@
"node_modules/@types"
]
},

"files": [
"<%= MAIN_SRC_DIR %>app/app.module.ts",
"<%= MAIN_SRC_DIR %>app/app.main-aot.ts"
"include": [
"<%= MAIN_SRC_DIR %>app"
],
"exclude": [
"<%= MAIN_SRC_DIR %>app/app.main-aot.ts"
],

"angularCompilerOptions": {
"genDir": "<%= BUILD_DIR %>aot",
"skipMetadataEmit" : true
Expand Down
4 changes: 2 additions & 2 deletions generators/client/templates/angular/_tsconfig.json
Expand Up @@ -34,8 +34,8 @@
]
},
"include": [
"src/main/webapp/app",
"src/test/javascript"
"<%= MAIN_SRC_DIR %>app",
"<%= TEST_SRC_DIR %>"
],
"exclude": [
"<%= MAIN_SRC_DIR %>app/app.main-aot.ts"
Expand Down
Expand Up @@ -22,10 +22,6 @@ import { <%=angular2AppName%>AppModuleNgFactory } from '../../../../<%= BUILD_DI

ProdConfig();

if (module['hot']) {
module['hot'].accept();
}

platformBrowser().bootstrapModuleFactory(<%=angular2AppName%>AppModuleNgFactory)
.then((success) => console.log(`Application started`))
.catch((err) => console.error(err));
11 changes: 10 additions & 1 deletion generators/client/templates/angular/webpack/_utils.js
Expand Up @@ -17,9 +17,11 @@
limitations under the License.
-%>
const fs = require('fs');
const path = require('path');

module.exports = {
parseVersion : parseVersion
parseVersion,
root
};

<%_ if (buildTool === 'maven') { _%>
Expand Down Expand Up @@ -53,3 +55,10 @@ 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));
}
27 changes: 7 additions & 20 deletions generators/client/templates/angular/webpack/_webpack.common.js
Expand Up @@ -17,7 +17,6 @@
limitations under the License.
-%>
const webpack = require('webpack');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const StringReplacePlugin = require('string-replace-webpack-plugin');
Expand All @@ -35,15 +34,6 @@ module.exports = (options) => {
DEBUG_INFO_ENABLED: options.env === 'dev'
};
return {
entry: {
'polyfills': './src/main/webapp/app/polyfills',
<%_ if (useSass) { _%>
'global': './src/main/webapp/content/scss/global.scss',
<%_ } else { _%>
'global': './src/main/webapp/content/css/global.css',
<%_ } _%>
'main': './src/main/webapp/app/app.main'
},
resolve: {
extensions: ['.ts', '.js'],
modules: ['node_modules']
Expand All @@ -61,7 +51,7 @@ module.exports = (options) => {
minifyJS:false,
minifyCSS:false
},
exclude: ['./src/main/webapp/index.html']
exclude: ['./<%= MAIN_SRC_DIR %>index.html']
},
<%_ if (useSass) { _%>
{
Expand Down Expand Up @@ -103,17 +93,14 @@ module.exports = (options) => {
]
},
plugins: [
new CommonsChunkPlugin({
names: ['manifest', 'polyfills'].reverse()
}),
new CopyWebpackPlugin([
{ from: './node_modules/core-js/client/shim.min.js', to: 'core-js-shim.min.js' },
{ from: './node_modules/swagger-ui/dist', to: 'swagger-ui/dist' },
{ from: './src/main/webapp/swagger-ui/', to: 'swagger-ui' },
{ from: './src/main/webapp/favicon.ico', to: 'favicon.ico' },
{ from: './src/main/webapp/manifest.webapp', to: 'manifest.webapp' },
// { from: './src/main/webapp/sw.js', to: 'sw.js' },
{ from: './src/main/webapp/robots.txt', to: 'robots.txt' }
{ from: './<%= MAIN_SRC_DIR %>swagger-ui/', to: 'swagger-ui' },
{ from: './<%= MAIN_SRC_DIR %>favicon.ico', to: 'favicon.ico' },
{ from: './<%= MAIN_SRC_DIR %>manifest.webapp', to: 'manifest.webapp' },
// { from: './<%= MAIN_SRC_DIR %>sw.js', to: 'sw.js' },
{ from: './<%= MAIN_SRC_DIR %>robots.txt', to: 'robots.txt' }
]),
new webpack.ProvidePlugin({
$: "jquery",
Expand All @@ -129,7 +116,7 @@ module.exports = (options) => {
}),
<%_ } _%>
new HtmlWebpackPlugin({
template: './src/main/webapp/index.html',
template: './<%= MAIN_SRC_DIR %>index.html',
chunksSortMode: 'dependency',
inject: 'body'
}),
Expand Down
25 changes: 19 additions & 6 deletions generators/client/templates/angular/webpack/_webpack.dev.js
Expand Up @@ -26,12 +26,13 @@ const execSync = require('child_process').execSync;
const fs = require('fs');
const path = require('path');

const utils = require('./utils.js');
const commonConfig = require('./webpack.common.js');

const ddlPath = './<%= BUILD_DIR %>www/vendor.json';
const ddlPath = '<%= BUILD_DIR %>www/vendor.json';
const ENV = 'dev';

if (!fs.existsSync(ddlPath)) {
if (!fs.existsSync(utils.root(ddlPath))) {
execSync('webpack --config webpack/webpack.vendor.js');
}

Expand Down Expand Up @@ -60,8 +61,17 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
ws: true
}<% } %>]
},
entry: {
'polyfills': './<%= MAIN_SRC_DIR %>app/polyfills',
<%_ if (useSass) { _%>
'global': './<%= MAIN_SRC_DIR %>content/scss/global.scss',
<%_ } else { _%>
'global': './<%= MAIN_SRC_DIR %>content/css/global.css',
<%_ } _%>
'main': './<%= MAIN_SRC_DIR %>app/app.main'
},
output: {
path: path.resolve('<%= BUILD_DIR %>www'),
path: utils.root('<%= BUILD_DIR %>www'),
filename: 'app/[name].bundle.js',
chunkFilename: 'app/[id].chunk.js'
},
Expand All @@ -82,6 +92,9 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
}]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['manifest', 'polyfills'].reverse()
}),
new BrowserSyncPlugin({
host: 'localhost',
port: 9000,
Expand All @@ -94,17 +107,17 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
}),
new webpack.DllReferencePlugin({
context: './',
manifest: require(path.resolve('./<%= BUILD_DIR %>www/vendor.json'))
manifest: require(utils.root(ddlPath))
}),
new AddAssetHtmlPlugin([
{ filepath: path.resolve('./<%= BUILD_DIR %>www/vendor.dll.js'), includeSourcemap: false }
{ filepath: utils.root('<%= BUILD_DIR %>www/vendor.dll.js'), includeSourcemap: false }
]),
new ExtractTextPlugin('styles.css'),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin(),
new writeFilePlugin(),
new webpack.WatchIgnorePlugin([
path.resolve('./src/test'),
utils.root('src/test'),
])
]
});
21 changes: 9 additions & 12 deletions generators/client/templates/angular/webpack/_webpack.prod.js
Expand Up @@ -22,27 +22,21 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const Visualizer = require('webpack-visualizer-plugin');
const AotPlugin = require('@ngtools/webpack').AotPlugin;
const path = require('path');

const utils = require('./utils.js');
const commonConfig = require('./webpack.common.js');

const ENV = 'prod';
const _root = path.resolve(__dirname, '..');

function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [_root].concat(args));
}

module.exports = webpackMerge(commonConfig({ env: ENV }), {
devtool: 'source-map',
entry: {
'polyfills': './src/main/webapp/app/polyfills',
'main': './src/main/webapp/app/app.main-aot',
'vendor': './src/main/webapp/app/vendor-aot'
'polyfills': './<%= MAIN_SRC_DIR %>app/polyfills',
'vendor': './<%= MAIN_SRC_DIR %>app/vendor-aot',
'main': './<%= MAIN_SRC_DIR %>app/app.main-aot'
},
output: {
path: path.resolve('./<%= BUILD_DIR %>www'),
path: utils.root('<%= BUILD_DIR %>www'),
filename: 'app/[hash].[name].bundle.js',
chunkFilename: 'app/[hash].[id].chunk.js'
},
Expand All @@ -53,6 +47,9 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
}]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['main', 'vendor', 'polyfills']
}),
new ExtractTextPlugin('[hash].styles.css'),
new Visualizer({
// Webpack statistics in target folder
Expand All @@ -61,7 +58,7 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
// AOT Plugin
new AotPlugin({
tsConfigPath: './tsconfig-aot.json',
entryModule: root('src/main/webapp/app/app.module#<%=angular2AppName%>AppModule')
entryModule: utils.root('<%= MAIN_SRC_DIR %>app/app.module#<%=angular2AppName%>AppModule')
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
Expand Down
Expand Up @@ -17,12 +17,13 @@
limitations under the License.
-%>
const webpack = require('webpack');
const path = require('path');

const utils = require('./utils.js');

module.exports = {
entry: {
'vendor': [
'./src/main/webapp/app/vendor',
'./<%= MAIN_SRC_DIR %>app/vendor',
'@angular/common',
'@angular/compiler',
'@angular/core',
Expand Down Expand Up @@ -70,13 +71,13 @@ module.exports = {
},
output: {
filename: '[name].dll.js',
path: path.resolve('./<%= BUILD_DIR %>www'),
path: utils.root('<%= BUILD_DIR %>www'),
library: '[name]'
},
plugins: [
new webpack.DllPlugin({
name: '[name]',
path: path.resolve('./<%= BUILD_DIR %>www/[name].json')
path: utils.root('<%= BUILD_DIR %>www/[name].json')
})
]
};

0 comments on commit 258106e

Please sign in to comment.