Skip to content
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

angular-cli 6 (with webpack 4) compatibility #3491

Merged
merged 17 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/angular/src/server/angular-cli_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logger } from '@storybook/node-logger';

function isAngularCliInstalled() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: @angular/cli module is no longer needed, so I prefer such as isBuildAngularInstalled.

try {
require.resolve('@angular/cli');
require.resolve('@angular-devkit/build-angular');
return true;
} catch (e) {
return false;
Expand All @@ -21,12 +21,19 @@ export function getAngularCliWebpackConfigOptions(dirToSearch, appIndex = 0) {
throw new Error('.angular-cli.json must have apps entry.');
}
const appConfig = cliConfig.apps[appIndex];
const { root, styles, scripts } = appConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should read the build options from angular.json (not .angular-cli.json). And the structures of them are not compatible.

const angularJson = JSON.parse(fs.readFileSync(path.resolve(dirToSearch, 'angular.json'), 'utf8'))
const project = angularJson['projects'][angularJson['defaultProject']];
const cliWebpackConfigOptions = {
  buildOptions: project.architect.build.options,
  root: project.root,
  projectRoot: dirToSearch,
  supportES2015: false,
  tsConfig: {
    options: { },
    fileNames: [],
    errors: [],
  },
  tsConfigPath: path.resolve(dirToSearch, 'src/tsconfig.app.json'),
};

I've created the sample repo to extract webpack config object using @angular-devkit/build-angular
https://github.com/Quramy/how-to-extract-webpack-conf-from-angular-cli


const cliWebpackConfigOptions = {
root,
projectRoot: dirToSearch,
appConfig,
buildOptions: {
outputPath: 'outputPath', // It's dummy value to avoid to Angular CLI's error
scripts,
styles,
},
tsConfig: {
options: {},
},
supportES2015: false,
};
Expand All @@ -43,7 +50,7 @@ export function applyAngularCliWebpackConfig(baseConfig, cliWebpackConfigOptions
}

// eslint-disable-next-line global-require, import/no-extraneous-dependencies
const ngcliConfigFactory = require('@angular/cli/models/webpack-configs');
const ngcliConfigFactory = require('@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs');

let cliCommonConfig;
let cliStyleConfig;
Expand Down
2 changes: 1 addition & 1 deletion app/angular/src/server/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function(configDir, quiet) {
new webpack.ProgressPlugin(),
quiet ? null : new webpack.ProgressPlugin(),
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)(@angular|esm5)/,
/angular(\\|\/)core(\\|\/)(@angular|esm5|fesm5)/,
path.resolve(__dirname, '../src')
),
new Dotenv({ silent: true }),
Expand Down
22 changes: 12 additions & 10 deletions examples/angular-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@
"test": "ng test"
},
"dependencies": {
"@angular/common": "^5.2.10",
"@angular/compiler": "^5.2.10",
"@angular/core": "^5.2.10",
"@angular/forms": "^5.2.10",
"@angular/platform-browser": "^5.2.10",
"@angular/platform-browser-dynamic": "^5.2.10",
"@ngrx/store": "^5.2.0",
"@angular/common": "^6.0.0-rc.5",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, new angular/cli v6 needs not .angular-cli.json but angular.json. I think it's better to re-generate the example project with ng new angular-cli.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stable 6 version is out now, please upgrade

Copy link
Member Author

@igor-dv igor-dv May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I am on it

"@angular/compiler": "^6.0.0-rc.5",
"@angular/core": "^6.0.0-rc.5",
"@angular/forms": "^6.0.0-rc.5",
"@angular/platform-browser": "^6.0.0-rc.5",
"@angular/platform-browser-dynamic": "^6.0.0-rc.5",
"@ngrx/store": "^6.0.0-beta.1",
"core-js": "^2.5.5",
"rxjs": "^5.5.10",
"rxjs": "^6.0.0",
"rxjs-compat": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/cli": "1.7.4",
"@angular/compiler-cli": "^5.2.10",
"@angular-devkit/build-angular": "^0.5.8",
"@angular/cli": "^6.0.0-rc.6",
"@angular/compiler-cli": "^6.0.0-rc.5",
"@storybook/addon-actions": "4.0.0-alpha.3",
"@storybook/addon-knobs": "4.0.0-alpha.3",
"@storybook/addon-links": "4.0.0-alpha.3",
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
"chromatic": "npm --prefix examples/official-storybook run chromatic"
},
"devDependencies": {
"@angular/common": "^5.2.10",
"@angular/compiler": "^5.2.10",
"@angular/core": "^5.2.10",
"@angular/forms": "^5.2.10",
"@angular/platform-browser": "^5.2.10",
"@angular/platform-browser-dynamic": "^5.2.10",
"@angular/common": "^6.0.0-rc.5",
"@angular/compiler": "^6.0.0-rc.5",
"@angular/core": "^6.0.0-rc.5",
"@angular/forms": "^6.0.0-rc.5",
"@angular/platform-browser": "^6.0.0-rc.5",
"@angular/platform-browser-dynamic": "^6.0.0-rc.5",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.3",
Expand Down
Loading