-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Migration to Angular 6, RxJs 6 and Webpack 4 #2019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
133b543
0a907c0
ecb04c3
81dc5c0
c4c50af
028533b
4cfa10e
bfc0d6b
5469a5c
5b16142
ff514b5
68b1033
dcf29ab
2a6a916
21abae0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,12 @@ const helpers = require('./helpers'); | |
* problem with copy-webpack-plugin | ||
*/ | ||
const DefinePlugin = require('webpack/lib/DefinePlugin'); | ||
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin'); | ||
const CopyWebpackPlugin = require('copy-webpack-plugin'); | ||
const HtmlElementsPlugin = require('./html-elements-plugin'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const WebpackInlineManifestPlugin = require('webpack-inline-manifest-plugin'); | ||
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin'); | ||
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin'); | ||
const ngcWebpack = require('ngc-webpack'); | ||
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin; | ||
|
||
const buildUtils = require('./build-utils'); | ||
|
||
|
@@ -26,19 +24,19 @@ const buildUtils = require('./build-utils'); | |
* | ||
* See: https://webpack.js.org/configuration/ | ||
*/ | ||
module.exports = function (options) { | ||
module.exports = function(options) { | ||
const isProd = options.env === 'production'; | ||
const APP_CONFIG = require(process.env.ANGULAR_CONF_FILE || (isProd ? './config.prod.json' : './config.dev.json')); | ||
|
||
const METADATA = Object.assign({}, buildUtils.DEFAULT_METADATA,options.metadata || {}); | ||
const METADATA = Object.assign({}, buildUtils.DEFAULT_METADATA, options.metadata || {}); | ||
const GTM_API_KEY = process.env.GTM_API_KEY || APP_CONFIG.gtmKey; | ||
|
||
const ngcWebpackConfig = buildUtils.ngcWebpackSetup(isProd, METADATA); | ||
const supportES2015 = buildUtils.supportES2015(METADATA.tsConfigPath); | ||
|
||
const entry = { | ||
polyfills: './src/polyfills.browser.ts', | ||
main: './src/main.browser.ts' | ||
main: './src/main.browser.ts' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't these 2 paths start with '../src/' because webpack.common.js is in config folder? |
||
}; | ||
|
||
Object.assign(ngcWebpackConfig.plugin, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose the path is relative to the folder in which node process for webpack is getting launched from, so that would be the root with package.json - not /config... |
||
|
@@ -61,7 +59,7 @@ module.exports = function (options) { | |
* See: https://webpack.js.org/configuration/resolve/ | ||
*/ | ||
resolve: { | ||
mainFields: [ ...(supportES2015 ? ['es2015'] : []), 'browser', 'module', 'main' ], | ||
mainFields: [...(supportES2015 ? ['es2015'] : []), 'browser', 'module', 'main'], | ||
|
||
/** | ||
* An array of extensions that should be used to resolve modules. | ||
|
@@ -103,7 +101,6 @@ module.exports = function (options) { | |
* See: https://webpack.js.org/configuration/module/ | ||
*/ | ||
module: { | ||
|
||
rules: [ | ||
...ngcWebpackConfig.loaders, | ||
|
||
|
@@ -155,9 +152,7 @@ module.exports = function (options) { | |
test: /\.(eot|woff2?|svg|ttf)([\?]?.*)$/, | ||
use: 'file-loader' | ||
} | ||
|
||
], | ||
|
||
] | ||
}, | ||
|
||
/** | ||
|
@@ -177,40 +172,15 @@ module.exports = function (options) { | |
*/ | ||
// NOTE: when adding more properties make sure you include them in custom-typings.d.ts | ||
new DefinePlugin({ | ||
'ENV': JSON.stringify(METADATA.ENV), | ||
'HMR': METADATA.HMR, | ||
'AOT': METADATA.AOT, | ||
ENV: JSON.stringify(METADATA.ENV), | ||
HMR: METADATA.HMR, | ||
AOT: METADATA.AOT, | ||
'process.env.ENV': JSON.stringify(METADATA.ENV), | ||
'process.env.NODE_ENV': JSON.stringify(METADATA.ENV), | ||
'process.env.HMR': METADATA.HMR, | ||
'process.env.HMR': METADATA.HMR | ||
// 'FIREBASE_CONFIG': JSON.stringify(APP_CONFIG.firebase), | ||
}), | ||
|
||
/** | ||
* Plugin: CommonsChunkPlugin | ||
* Description: Shares common code between the pages. | ||
* It identifies common modules and put them into a commons chunk. | ||
* | ||
* See: https://webpack.js.org/plugins/commons-chunk-plugin/ | ||
* See: https://github.com/webpack/docs/wiki/optimization#multi-page-app | ||
*/ | ||
new CommonsChunkPlugin({ | ||
name: 'polyfills', | ||
chunks: ['polyfills'] | ||
}), | ||
|
||
new CommonsChunkPlugin({ | ||
minChunks: Infinity, | ||
name: 'inline' | ||
}), | ||
new CommonsChunkPlugin({ | ||
name: 'main', | ||
async: 'common', | ||
children: true, | ||
minChunks: 2 | ||
}), | ||
|
||
|
||
/** | ||
* Plugin: CopyWebpackPlugin | ||
* Description: Copy files and directories in webpack. | ||
|
@@ -219,11 +189,9 @@ module.exports = function (options) { | |
* | ||
* See: https://www.npmjs.com/package/copy-webpack-plugin | ||
*/ | ||
new CopyWebpackPlugin([ | ||
{ from: 'src/assets', to: 'assets' }, | ||
{ from: 'src/meta'} | ||
], | ||
isProd ? { ignore: [ 'mock-data/**/*' ] } : undefined | ||
new CopyWebpackPlugin( | ||
[{ from: 'src/assets', to: 'assets' }, { from: 'src/meta' }], | ||
isProd ? { ignore: ['mock-data/**/*'] } : undefined | ||
), | ||
|
||
/* | ||
|
@@ -237,22 +205,24 @@ module.exports = function (options) { | |
new HtmlWebpackPlugin({ | ||
template: 'src/index.html', | ||
title: METADATA.title, | ||
chunksSortMode: function (a, b) { | ||
const entryPoints = ["inline","polyfills","sw-register","styles","vendor","main"]; | ||
chunksSortMode: function(a, b) { | ||
const entryPoints = ['inline', 'polyfills', 'sw-register', 'styles', 'vendor', 'main']; | ||
return entryPoints.indexOf(a.names[0]) - entryPoints.indexOf(b.names[0]); | ||
}, | ||
metadata: METADATA, | ||
gtmKey: GTM_API_KEY, | ||
inject: 'body', | ||
xhtml: true, | ||
minify: isProd ? { | ||
caseSensitive: true, | ||
collapseWhitespace: true, | ||
keepClosingSlash: true | ||
} : false | ||
minify: isProd | ||
? { | ||
caseSensitive: true, | ||
collapseWhitespace: true, | ||
keepClosingSlash: true | ||
} | ||
: false | ||
}), | ||
|
||
/** | ||
/** | ||
* Plugin: ScriptExtHtmlWebpackPlugin | ||
* Description: Enhances html-webpack-plugin functionality | ||
* with different deployment options for your scripts including: | ||
|
@@ -292,22 +262,15 @@ module.exports = function (options) { | |
headTags: require('./head-config.common') | ||
}), | ||
|
||
/** | ||
* Plugin LoaderOptionsPlugin (experimental) | ||
* | ||
* See: https://gist.github.com/sokra/27b24881210b56bbaff7 | ||
*/ | ||
new LoaderOptionsPlugin({}), | ||
|
||
new ngcWebpack.NgcWebpackPlugin(ngcWebpackConfig.plugin), | ||
new AngularCompilerPlugin(ngcWebpackConfig.plugin), | ||
|
||
/** | ||
* Plugin: WebpackInlineManifestPlugin | ||
* Inline Webpack's manifest.js in index.html | ||
* | ||
* https://github.com/almothafar/webpack-inline-manifest-plugin | ||
*/ | ||
new WebpackInlineManifestPlugin(), | ||
new WebpackInlineManifestPlugin() | ||
], | ||
|
||
/** | ||
|
@@ -324,6 +287,5 @@ module.exports = function (options) { | |
clearImmediate: false, | ||
setImmediate: false | ||
} | ||
|
||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't you delete this line? I thought you replaced ngcwebpack with ngtoolswebpack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config is still used, though. ngcWebpack is just a wrapper around webpack/ngtools and almost all config values are the same.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to do some renaming here for clarity...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!