Skip to content

Commit

Permalink
Update Angular example
Browse files Browse the repository at this point in the history
  • Loading branch information
buzz committed Jul 27, 2020
1 parent 6ae9f44 commit 90e088d
Show file tree
Hide file tree
Showing 20 changed files with 12,107 additions and 347 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/build
/mediainfo.d.ts
/types.d.ts
/examples/angular/dist
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use a JavaScript bundler like webpack.

- **CDN**: `<script type="text/javascript" src="https://unpkg.com/mediainfo.js/dist/mediainfo.min.js"></script>`
- **Bundler**: `npm install mediainfo.js`
(Note: When using a bundler you need to make sure `mediainfo.wasm` can be loaded by the library. Check the [webpack example](https://github.com/buzz/mediainfo.js/blob/50830088bd775942a3962416ce61f759b13bc7c2/webpack.config.js#L34) to see how this is achieved using `copy-webpack-plugin`.)
Note: When using a bundler you need to make sure `mediainfo.wasm` can be
loaded by the library. Check the
[React/webpack](https://github.com/buzz/mediainfo.js/blob/50830088bd775942a3962416ce61f759b13bc7c2/webpack.config.js#L34)
and [Angular](TODO) examples.

### Node.js

Expand Down Expand Up @@ -46,7 +49,8 @@ require('mediainfo.js')().then((mediainfo) => {

- [Simple](https://github.com/buzz/mediainfo.js/tree/master/examples/browser-simple)
- [CDN (CodePen)](https://codepen.io/buzzone/pen/eYNjJrx)
- [Webpack](https://github.com/buzz/mediainfo.js/tree/gh-pages-src)
- [React/webpack](https://github.com/buzz/mediainfo.js/tree/gh-pages-src)
- [Angular](https://github.com/buzz/mediainfo.js/tree/master/examples/angular)
- [Node.js](https://github.com/buzz/mediainfo.js/tree/master/examples/node-cli/cli.js)

### API
Expand Down
2 changes: 2 additions & 0 deletions examples/angular/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/dist
58 changes: 23 additions & 35 deletions examples/angular/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
# Mediainfo Angular example
# mediainfo.js Angular example

**Step #1**
## Step #1: WASM module

Copy the node_modules/mediainfo.js/dist/MediaInfoModule.wasm to your project's src directory,
Add `MediaInfoModule.wasm` to the `assets` section in the options of the build
target in your `angular.json`.

**Step #2**
```json
"assets": [
{
"input": "node_modules/mediainfo.js/dist",
"glob": "MediaInfoModule.wasm",
"output": ""
}
]
```

Modify the angular.json file to add that file to the assets section, in the options of build target
## Step #2: Ignore `fs` and `path`

"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {

...
"assets": [
"src/assets",
"src/favicon.ico",
"src/MediaInfoModule.wasm"
],
"styles": [
Add this section to your `package.json`.

**Step #3**

Put this browser section in highest level section of package.json (it can be just above dependencies):

...
"browser": {
"fs": false,
"path": false
},
"dependencies": {
...

**Step #4**

Restart ng serve
```json
"browser": {
"fs": false,
"path": false
},
```

## Credits

To @David that showed how to do this in [this Stackoverflow question](https://stackoverflow.com/questions/63001079/mediainfo-js-integration-in-angular-8)


Based on a [Stack Overflow answer](https://stackoverflow.com/a/63049567) by
[David](https://stackoverflow.com/users/1160794/david).
126 changes: 44 additions & 82 deletions examples/angular/angular.json
Original file line number Diff line number Diff line change
@@ -1,83 +1,45 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"mediainfoangular": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/mediainfoangular",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/assets",
{
"input": "node_modules/mediainfo.js/dist",
"glob": "MediaInfoModule.wasm",
"output": ""
}

],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "mediainfoangular:build"
},
"configurations": {
"production": {
"browserTarget": "mediainfoangular:build:production"
}
}
}
}
}
},
"defaultProject": "mediainfoangular"
}
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"mediainfojs-angular-example": {
"projectType": "application",
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/mediainfojs-angular-example",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.json",
"aot": true,
"assets": [
{
"input": "node_modules/mediainfo.js/dist",
"glob": "MediaInfoModule.wasm",
"output": ""
}
]
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "mediainfojs-angular-example:build"
},
"configurations": {
"production": {
"browserTarget": "mediainfojs-angular-example:build:production"
}
}
}
}
}
},
"defaultProject": "mediainfojs-angular-example"
}
Loading

0 comments on commit 90e088d

Please sign in to comment.