Skip to content

Commit d572792

Browse files
committed
Actually allow the router to lazy load.
1 parent de5139b commit d572792

File tree

1 file changed

+11
-33
lines changed

1 file changed

+11
-33
lines changed

addon/ng2/models/webpack-build-common.ts

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ import * as HtmlWebpackPlugin from 'html-webpack-plugin';
44
import * as webpack from 'webpack';
55
import * as atl from 'awesome-typescript-loader';
66

7-
import {SystemJSRegisterPublicModules} from './webpack-plugin-systemjs-registry';
87
import {findLazyModules} from './find-lazy-modules';
98

109

1110
export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
11+
const sourceRoot = path.resolve(projectRoot, `./${sourceDir}`);
12+
1213
const lazyModules = findLazyModules(path.resolve(projectRoot, sourceDir));
1314
const entries = Object.assign({
14-
main: [path.resolve(projectRoot, `./${sourceDir}/main.ts`)],
15-
polyfills: path.resolve(projectRoot, `./${sourceDir}/polyfills.ts`)
15+
main: [path.join(sourceRoot, 'main.ts')],
16+
polyfills: path.join(sourceRoot, 'polyfills.ts')
1617
}, lazyModules);
1718

19+
1820
return {
1921
devtool: 'inline-source-map',
2022
resolve: {
@@ -41,7 +43,7 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
4143
test: /(systemjs_component_resolver|system_js_ng_module_factory_loader)\.js$/,
4244
loader: 'string-replace-loader',
4345
query: {
44-
search: '(lang_1(.*[\\n\\r]\\s*\\.|\\.))?(global(.*[\\n\\r]\\s*\\.|\\.))?(System|SystemJS)(.*[\\n\\r]\\s*\\.|\\.)import',
46+
search: '(lang_1(.*[\\n\\r]+\\s*\\.|\\.))?(global(.*[\\n\\r]+\\s*\\.|\\.))?(System|SystemJS)(.*[\\n\\r]+\\s*\\.|\\.)import',
4547
replace: 'System.import',
4648
flags: 'g'
4749
}
@@ -54,7 +56,6 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
5456
{
5557
loader: 'awesome-typescript-loader',
5658
query: {
57-
useForkChecker: true,
5859
tsconfig: path.resolve(projectRoot, `./${sourceDir}/tsconfig.json`)
5960
}
6061
}, {
@@ -73,6 +74,11 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
7374
]
7475
},
7576
plugins: [
77+
new webpack.ContextReplacementPlugin(
78+
/.*/,
79+
sourceRoot,
80+
lazyModules
81+
),
7682
new atl.ForkCheckerPlugin(),
7783
new HtmlWebpackPlugin({
7884
template: path.resolve(projectRoot, `./${sourceDir}/index.html`),
@@ -92,34 +98,6 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
9298
from: '**/*',
9399
to: path.resolve(projectRoot, './dist')
94100
}]),
95-
// new SystemJSRegisterPublicModules({
96-
// // automatically configure SystemJS to load webpack chunks (defaults to true)
97-
// bundlesConfigForChunks: true,
98-
//
99-
// // select which modules to expose as public modules
100-
// registerModules: [
101-
// // "default" filters provided are "local" and "public"
102-
// { filter: 'public' },
103-
// //
104-
// // // keyname allows a custom naming system for public modules
105-
// // {
106-
// // filter: 'local',
107-
// // keyname: 'app/[relPath]'
108-
// // },
109-
// //
110-
// // // keyname can be a function
111-
// // {
112-
// // filter: 'public',
113-
// // keyname: (module) => 'publicModule-' + module.id
114-
// // },
115-
// //
116-
// // // filter can also be a function
117-
// // {
118-
// // filter: (m) => m.relPath.match(/src/),
119-
// // keyname: 'random-naming-system-[id]'
120-
// // }
121-
// ]
122-
// })
123101
],
124102
node: {
125103
fs: 'empty',

0 commit comments

Comments
 (0)