Skip to content

Commit

Permalink
feat(custom-webpack): support ESM (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-jeb authored Jan 30, 2022
1 parent 79654fa commit 9d8cd2d
Show file tree
Hide file tree
Showing 53 changed files with 1,665 additions and 37 deletions.
2 changes: 1 addition & 1 deletion examples/custom-webpack/full-cycle-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@angular/language-service": "13.2.0",
"@types/jasmine": "3.10.3",
"@types/node": "16.11.21",
"cypress": "latest",
"cypress": "9.3.1",
"html-webpack-plugin": "5.5.0",
"jasmine-core": "4.0.0",
"karma": "6.3.12",
Expand Down
16 changes: 16 additions & 0 deletions examples/custom-webpack/sanity-app-esm/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support

# You can see what browsers were selected by your queries by running:
# npx browserslist

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
16 changes: 16 additions & 0 deletions examples/custom-webpack/sanity-app-esm/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single

[*.md]
max_line_length = off
trim_trailing_whitespace = false
42 changes: 42 additions & 0 deletions examples/custom-webpack/sanity-app-esm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# Compiled output
/dist
/tmp
/out-tsc
/bazel-out

# Node
/node_modules
npm-debug.log
yarn-error.log

# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# Miscellaneous
/.angular/cache
.sass-cache/
/connect.lock
/coverage
/libpeerconnection.log
testem.log
/typings

# System files
.DS_Store
Thumbs.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
"recommendations": ["angular.ng-template"]
}
20 changes: 20 additions & 0 deletions examples/custom-webpack/sanity-app-esm/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ng serve",
"type": "pwa-chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"url": "http://localhost:4200/"
},
{
"name": "ng test",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: test",
"url": "http://localhost:9876/debug.html"
}
]
}
42 changes: 42 additions & 0 deletions examples/custom-webpack/sanity-app-esm/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
},
{
"type": "npm",
"script": "test",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
}
]
}
27 changes: 27 additions & 0 deletions examples/custom-webpack/sanity-app-esm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SanityAppEsm

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.2.0.

## Development server

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.

## Code scaffolding

Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.

## Build

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.

## Running unit tests

Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Running end-to-end tests

Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
176 changes: 176 additions & 0 deletions examples/custom-webpack/sanity-app-esm/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"cli": {
"packageManager": "yarn"
},
"newProjectRoot": "projects",
"projects": {
"sanity-app-esm": {
"projectType": "application",
"schematics": {
"@schematics/angular:application": {
"strict": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"outputPath": "dist/sanity-app-esm",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
},
"esm": {
"customWebpackConfig": {
"path": "custom-webpack.config.js"
},
"indexTransform": "index.transform.js"
},
"cjs": {
"customWebpackConfig": {
"path": "custom-webpack.config.cjs"
},
"indexTransform": "index.transform.cjs"
},
"tsEsm": {
"customWebpackConfig": {
"path": "custom-webpack.config.ts"
},
"indexTransform": "index.transform.ts"
}
},
"defaultConfiguration": "production,esm"
},
"serve": {
"builder": "@angular-builders/custom-webpack:dev-server",
"options": {
"port": 5005
},
"configurations": {
"production": {
"browserTarget": "sanity-app-esm:build:production"
},
"development": {
"browserTarget": "sanity-app-esm:build:development"
},
"cjs": {
"browserTarget": "sanity-app-esm:build:cjs"
},
"esm": {
"browserTarget": "sanity-app-esm:build:esm"
},
"tsEsm": {
"browserTarget": "sanity-app-esm:build:tsEsm"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "sanity-app-esm:build"
}
},
"test": {
"builder": "@angular-builders/custom-webpack:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.cjs",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"cypress-run": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "sanity-app-esm:serve"
},
"configurations": {
"production": {
"devServerTarget": "sanity-app-esm:serve:production"
}
}
},
"cypress-open": {
"builder": "@cypress/schematic:cypress",
"options": {
"watch": true,
"headless": false
}
},
"e2e": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "sanity-app-esm:serve",
"browser": "chrome",
"port": 4224
},
"configurations": {
"production": {
"devServerTarget": "sanity-app-esm:serve:production"
},
"esm": {
"devServerTarget": "sanity-app-esm:serve:esm"
},
"cjs": {
"devServerTarget": "sanity-app-esm:serve:cjs"
}
},
"defaultConfiguration": "esm"
}
}
}
},
"defaultProject": "sanity-app-esm"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Configuration } from 'webpack';

export default async (cfg: Configuration) => {
const { default: configFromEsm } = await import('./custom-webpack.config.js');
// Do some stuff with config and configFromEsm
return { ...cfg, ...configFromEsm };
};
9 changes: 9 additions & 0 deletions examples/custom-webpack/sanity-app-esm/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"integrationFolder": "e2e/src",
"testFiles": "**/*.e2e-spec.ts",
"baseUrl": "http://localhost:5005",
"video": false,
"screenshotOnRunFailure": false,
"pluginsFile": false,
"supportFile": false
}
14 changes: 14 additions & 0 deletions examples/custom-webpack/sanity-app-esm/e2e/src/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { AppPage } from './app.po';

describe('workspace-project App', () => {
let page: AppPage;

beforeEach(() => {
page = new AppPage();
});

it('should display welcome message', () => {
page.navigateTo();
page.getTitle().should('have.text', 'sanity-app-esm app is running!');
});
});
Loading

0 comments on commit 9d8cd2d

Please sign in to comment.