Skip to content

Commit a936635

Browse files
committed
Actually allow the router to lazy load.
1 parent 77b9148 commit a936635

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

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

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +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+
13+
const lazyModules = findLazyModules(path.resolve(projectRoot, sourceDir));
14+
const entries = Object.assign({
15+
main: [path.join(sourceRoot, 'main.ts')],
16+
polyfills: path.join(sourceRoot, 'polyfills.ts')
17+
}, lazyModules);
18+
19+
1220
return {
1321
devtool: 'source-map',
1422
resolve: {
@@ -22,6 +30,25 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
2230
filename: '[name].bundle.js'
2331
},
2432
module: {
33+
preLoaders: [
34+
{
35+
test: /\.js$/,
36+
loader: 'source-map-loader',
37+
exclude: [
38+
path.resolve(projectRoot, 'node_modules/rxjs'),
39+
path.resolve(projectRoot, 'node_modules/@angular'),
40+
]
41+
},
42+
{
43+
test: /(systemjs_component_resolver|system_js_ng_module_factory_loader)\.js$/,
44+
loader: 'string-replace-loader',
45+
query: {
46+
search: '(lang_1(.*[\\n\\r]+\\s*\\.|\\.))?(global(.*[\\n\\r]+\\s*\\.|\\.))?(System|SystemJS)(.*[\\n\\r]+\\s*\\.|\\.)import',
47+
replace: 'System.import',
48+
flags: 'g'
49+
}
50+
},
51+
],
2552
loaders: [
2653
{
2754
test: /\.ts$/,
@@ -67,34 +94,6 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
6794
from: '**/*',
6895
to: path.resolve(projectRoot, './dist')
6996
}]),
70-
// new SystemJSRegisterPublicModules({
71-
// // automatically configure SystemJS to load webpack chunks (defaults to true)
72-
// bundlesConfigForChunks: true,
73-
//
74-
// // select which modules to expose as public modules
75-
// registerModules: [
76-
// // "default" filters provided are "local" and "public"
77-
// { filter: 'public' },
78-
// //
79-
// // // keyname allows a custom naming system for public modules
80-
// // {
81-
// // filter: 'local',
82-
// // keyname: 'app/[relPath]'
83-
// // },
84-
// //
85-
// // // keyname can be a function
86-
// // {
87-
// // filter: 'public',
88-
// // keyname: (module) => 'publicModule-' + module.id
89-
// // },
90-
// //
91-
// // // filter can also be a function
92-
// // {
93-
// // filter: (m) => m.relPath.match(/src/),
94-
// // keyname: 'random-naming-system-[id]'
95-
// // }
96-
// ]
97-
// })
9897
],
9998
node: {
10099
fs: 'empty',

0 commit comments

Comments
 (0)