Skip to content

Commit f9a7c01

Browse files
authored
feature(@ngtools/webpack): add an option to skip code generation. (#3181)
Also use that option to replace awesome-typescript-loader.
1 parent 54ef738 commit f9a7c01

13 files changed

+626
-177
lines changed

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"@angular/tsc-wrapped": "0.4.0",
4848
"angular2-template-loader": "^0.5.0",
4949
"autoprefixer": "^6.5.3",
50-
"awesome-typescript-loader": "^2.2.3",
5150
"chalk": "^1.1.3",
5251
"common-tags": "^1.3.1",
5352
"compression-webpack-plugin": "^0.3.2",
@@ -60,6 +59,7 @@
6059
"ember-cli-normalize-entity-name": "^1.0.0",
6160
"ember-cli-preprocess-registry": "^2.0.0",
6261
"ember-cli-string-utils": "^1.0.0",
62+
"enhanced-resolve": "^2.3.0",
6363
"exists-sync": "0.0.3",
6464
"extract-text-webpack-plugin": "^2.0.0-beta.4",
6565
"file-loader": "^0.8.5",
@@ -81,6 +81,7 @@
8181
"less": "^2.7.1",
8282
"less-loader": "^2.2.3",
8383
"lodash": "^4.11.1",
84+
"magic-string": "^0.16.0",
8485
"markdown-it": "4.3.0",
8586
"markdown-it-terminal": "0.0.3",
8687
"minimatch": "^3.0.0",
@@ -111,6 +112,7 @@
111112
"script-loader": "^0.7.0",
112113
"semver": "^5.1.0",
113114
"silent-error": "^1.0.0",
115+
"source-map": "^0.5.6",
114116
"source-map-loader": "^0.1.5",
115117
"sourcemap-istanbul-instrumenter-loader": "^0.2.0",
116118
"string-replace-loader": "^1.0.5",
@@ -151,6 +153,7 @@
151153
"@types/node": "^6.0.36",
152154
"@types/request": "0.0.30",
153155
"@types/rimraf": "0.0.25-alpha",
156+
"@types/source-map": "^0.5.0",
154157
"@types/webpack": "^1.12.22-alpha",
155158
"chai": "^3.5.0",
156159
"conventional-changelog": "^1.1.0",

packages/angular-cli/models/webpack-build-test.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
const path = require('path');
44
const webpack = require('webpack');
5-
const atl = require('awesome-typescript-loader');
5+
const ngtools = require('@ngtools/webpack');
6+
7+
8+
const g = global;
9+
const webpackLoader = g['angularCliIsLocal']
10+
? g.angularCliPackages['@ngtools/webpack'].main
11+
: '@ngtools/webpack';
12+
613

714
const getWebpackTestConfig = function (projectRoot, environment, appConfig, testConfig) {
815

@@ -48,8 +55,8 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig, test
4855
resolve: {
4956
extensions: ['.ts', '.js'],
5057
plugins: [
51-
new atl.TsConfigPathsPlugin({
52-
tsconfig: path.resolve(appRoot, appConfig.tsconfig)
58+
new ngtools.PathsPlugin({
59+
tsConfigPath: path.resolve(appRoot, appConfig.tsconfig)
5360
})
5461
]
5562
},
@@ -74,16 +81,11 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig, test
7481
test: /\.ts$/,
7582
loaders: [
7683
{
77-
loader: 'awesome-typescript-loader',
84+
loader: webpackLoader,
7885
query: {
79-
tsconfig: path.resolve(appRoot, appConfig.tsconfig),
80-
module: 'commonjs',
81-
target: 'es5',
82-
forkChecker: true
86+
tsConfigPath: path.resolve(appRoot, appConfig.tsconfig),
87+
module: 'commonjs'
8388
}
84-
},
85-
{
86-
loader: 'angular2-template-loader'
8789
}
8890
],
8991
exclude: [/\.e2e\.ts$/]

packages/angular-cli/models/webpack-build-typescript.ts

+7-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import * as path from 'path';
2-
import * as webpack from 'webpack';
3-
import {findLazyModules} from './find-lazy-modules';
42
import {AotPlugin} from '@ngtools/webpack';
53

6-
const atl = require('awesome-typescript-loader');
74

85
const g: any = global;
96
const webpackLoader: string = g['angularCliIsLocal']
@@ -12,37 +9,22 @@ const webpackLoader: string = g['angularCliIsLocal']
129

1310

1411
export const getWebpackNonAotConfigPartial = function(projectRoot: string, appConfig: any) {
15-
const appRoot = path.resolve(projectRoot, appConfig.root);
16-
const lazyModules = findLazyModules(appRoot);
17-
1812
return {
19-
resolve: {
20-
plugins: [
21-
new atl.TsConfigPathsPlugin({
22-
tsconfig: path.resolve(appRoot, appConfig.tsconfig)
23-
})
24-
]
25-
},
2613
module: {
2714
rules: [
2815
{
2916
test: /\.ts$/,
30-
loaders: [{
31-
loader: 'awesome-typescript-loader',
32-
query: {
33-
forkChecker: true,
34-
tsconfig: path.resolve(appRoot, appConfig.tsconfig)
35-
}
36-
}, {
37-
loader: 'angular2-template-loader'
38-
}],
17+
loader: webpackLoader,
3918
exclude: [/\.(spec|e2e)\.ts$/]
4019
}
41-
],
20+
]
4221
},
4322
plugins: [
44-
new webpack.ContextReplacementPlugin(/.*/, appRoot, lazyModules),
45-
new atl.ForkCheckerPlugin(),
23+
new AotPlugin({
24+
tsConfigPath: path.resolve(projectRoot, appConfig.root, appConfig.tsconfig),
25+
mainPath: path.join(projectRoot, appConfig.root, appConfig.main),
26+
skipCodeGeneration: true
27+
}),
4628
]
4729
};
4830
};

packages/angular-cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"@angular/core": "2.2.1",
3333
"@ngtools/webpack": "^1.0.0",
3434
"angular2-template-loader": "^0.5.0",
35-
"awesome-typescript-loader": "^2.2.3",
3635
"chalk": "^1.1.3",
3736
"common-tags": "^1.3.1",
3837
"compression-webpack-plugin": "^0.3.2",
@@ -45,6 +44,7 @@
4544
"ember-cli-normalize-entity-name": "^1.0.0",
4645
"ember-cli-preprocess-registry": "^2.0.0",
4746
"ember-cli-string-utils": "^1.0.0",
47+
"enhanced-resolve": "^2.3.0",
4848
"exists-sync": "0.0.3",
4949
"extract-text-webpack-plugin": "^2.0.0-beta.4",
5050
"file-loader": "^0.8.5",

packages/webpack/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ The loader works with the webpack plugin to compile your TypeScript. It's import
3535
* `basePath`. Optional. The root to use by the compiler to resolve file paths. By default, use the `tsConfigPath` root.
3636
* `entryModule`. Optional if specified in `angularCompilerOptions`. The path and classname of the main application module. This follows the format `path/to/file#ClassName`.
3737
* `mainPath`. Optional if `entryModule` is specified. The `main.ts` file containing the bootstrap code. The plugin will use AST to determine the `entryModule`.
38-
* `genDir`. Optional. The output directory of the offline compiler. The files created by the offline compiler will be in a virtual file system, but the import paths might change. This can also be specified in `angularCompilerOptions`, and by default will be the same as `basePath`.
39-
* `typeChecking`. Optional, defaults to true. Enable type checking through your application. This will slow down compilation, but show syntactic and semantic errors in webpack.
38+
* `skipCodeGeneration`. Optional, defaults to false. Disable code generation and do not refactor the code to bootstrap. This replaces `templateUrl: "string"` with `template: require("string")` (and similar for styles) to allow for webpack to properly link the resources.
39+
* `typeChecking`. Optional, defaults to true. Enable type checking through your application. This will slow down compilation, but show syntactic and semantic errors in webpack.

packages/webpack/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"npm": ">= 3.0.0"
2626
},
2727
"dependencies": {
28-
"@angular-cli/ast-tools": "^1.0.0"
28+
"@angular-cli/ast-tools": "^1.0.0",
29+
"magic-string": "^0.16.0",
30+
"source-map": "^0.5.6"
2931
},
3032
"peerDependencies": {
3133
"typescript": "^2.0.2",

packages/webpack/src/compiler.ts

-16
This file was deleted.

packages/webpack/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'reflect-metadata';
22

3-
export * from './plugin'
4-
export {ngcLoader as default} from './loader'
3+
export * from './plugin';
4+
export {ngcLoader as default} from './loader';
5+
export {PathsPlugin} from './paths-plugin';

0 commit comments

Comments
 (0)