I created a new angularjs project with angularjs seed.
I added some external dependencies with bower - like bootstrap4 and some angularjs additional modules like ui-rout and ui-grid.
The size of all the source files is about 25 Megabyte.
I want to minify it obviously :)
I tried doing with grunt and grunt-es and uglify with concatanating the files and without, and it always fails :(
Usually with 'unexpected character' error.
Anyone here that Minified Angularjs seed + bootstrap4 with grunt or any other tasks manager tool that can guide me?
Im getting really frustrated :(
MY PACKAGE.JSON
{
"name": "angular-seed",
"private": true,
"version": "0.0.0",
"description": "A starter project for AngularJS",
"repository": "https://github.com/angular/angular-seed",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"bower": "^1.7.7",
"grunt": "^1.0.3",
"grunt-babel": "^7.0.0",
"grunt-cli": "^1.2.0",
"grunt-contrib-uglify-es": "git+https://github.com/gruntjs/grunt-contrib-uglify.git#harmony",
"grunt-dist": "0.0.6",
"grunt-es6-transpiler": "^1.0.2",
"http-server": "^0.9.0",
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-chrome-launcher": "^0.2.3",
"karma-firefox-launcher": "^0.1.7",
"karma-jasmine": "^0.3.8",
"karma-junit-reporter": "^0.4.1",
"protractor": "^4.0.9"
},
"scripts": {
"postinstall": "bower install",
"update-deps": "npm update",
"postupdate-deps": "bower update",
"prestart": "npm install",
"start": "http-server -a localhost -p 8000 -c-1 ./app",
"pretest": "npm install",
"test": "karma start karma.conf.js",
"test-single-run": "karma start karma.conf.js --single-run",
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",
"preprotractor": "npm run update-webdriver",
"protractor": "protractor e2e-tests/protractor.conf.js",
"update-index-async": "node -e \"var fs=require('fs'),indexFile='app/index-async.html',loaderFile='app/bower_components/angular-loader/angular-loader.min.js',loaderText=fs.readFileSync(loaderFile,'utf-8').split(/sourceMappingURL=angular-loader.min.js.map/).join('sourceMappingURL=bower_components/angular-loader/angular-loader.min.js.map'),indexText=fs.readFileSync(indexFile,'utf-8').split(/\\/\\/##NG_LOADER_START##[\\s\\S]*\\/\\/##NG_LOADER_END##/).join('//##NG_LOADER_START##\\n'+loaderText+' //##NG_LOADER_END##');fs.writeFileSync(indexFile,indexText);\""
},
"dependencies": {
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-qunit": "^2.0.0",
"grunt-contrib-watch": "^1.1.0"
}
}
PROJECT STRUCTRUE
I found this thread
AngularJS has some naming conventions which seem to collide with minification:
Since AngularJS infers the controller's dependencies from the names of
arguments to the controller's constructor function, if you were to
minify the JavaScript code for the PhoneListController controller, all
of its function arguments would be minified as well, and the
dependency injector would not be able to identify services correctly.
This plugin seems deal with the issue:
ng-annotate
Related
I can't seem to get Babel to work with Parcel, although the presets are being installed automatically. It works locally and in Chrome, but it's not transpiling node_modules es6 files, so the output still has const/let/... and it cannot run in Safari.
.babelrc
{
"presets": ["#babel/preset-env","#babel/preset-react"]
}
(I've also tried the env and react ones).
package.json scripts
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html",
Why would this be?
Full package.json (note this is after messing around in order to try to get it working)
{
"name": "my-react-app",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html"
},
"author": "",
"license": "ISC",
"dependencies": {
"#babel/core": "^7.1.5",
"#babel/preset-env": "^7.1.5",
"#babel/preset-react": "^7.0.0",
"axios": "^0.18.0",
"babel-polyfill": "^6.26.0",
"browserslist": "^4.3.4",
"lodash": "^4.17.11",
"node-sass": "^4.10.0",
"pinyin": "^2.8.3",
"prop-types": "^15.6.2",
"react": "^16.6.1",
"react-dom": "^16.6.1",
"react-notifications": "^1.4.3",
"react-router-dom": "^4.3.1"
},
"devDependencies": {
"cssnano": "^4.1.7",
"sass": "^1.14.3"
}
}
Still getting .js files with const, let. Any ideas what I am missing?
I've found a solution to it from https://github.com/parcel-bundler/parcel/issues/1655#issuecomment-425593377
// .browserslistrc.packages
node 10.11
// package.json
{
"scripts": {
"postinstall": "npm-run-all -p \"postinstall:*\"",
"postinstall:p-retry": "cpy --rename=.browserslistrc .browserslistrc.packages node_modules/p-retry",
"postinstall:query-string": "cpy --rename=.browserslistrc .browserslistrc.packages node_modules/query-string"
}
}
Add a postinstall:package-name for every npm package that you need to add transpilation (in my case, pinyin) and run npm run postinstall after every npm install. Babel should now also transpile that npm package!
So I am new in angular and i am working on visual studio 2015 update 3.
Simple Angular app work perfectly on VS2015 dotnet MVC project.
I have a problem when i downgradecomponent in app.module.ts file
angular.module('app').directive('viewTest', downgradeComponent({ component: ViewTestComponent }));
error is on angular it says cannot find name 'angular'
my package.json file
{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"build": "tsc -p src/",
"build:watch": "tsc -p src/ -w",
"build:e2e": "tsc -p e2e/",
"serve": "lite-server -c=bs-config.json",
"serve:e2e": "lite-server -c=bs-config.e2e.json",
"prestart": "npm run build",
"start": "concurrently \"npm run build:watch\" \"npm run serve\"",
"pree2e": "npm run build:e2e",
"e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
"preprotractor": "webdriver-manager update",
"protractor": "protractor protractor.config.js",
"pretest": "npm run build",
"test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
"pretest:once": "npm run build",
"test:once": "karma start karma.conf.js --single-run",
"lint": "tslint ./src/**/*.ts -t verbose"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"#angular/common": "~4.3.4",
"#angular/compiler": "~4.3.4",
"#angular/core": "~4.3.4",
"#angular/forms": "~4.3.4",
"#angular/http": "~4.3.4",
"#angular/platform-browser": "~4.3.4",
"#angular/platform-browser-dynamic": "~4.3.4",
"#angular/router": "~4.3.4",
"#angular/upgrade": "~4.3.4",
"angular-in-memory-web-api": "~0.3.0",
"systemjs": "0.19.40",
"core-js": "^2.4.1",
"rxjs": "5.5.10",
"zone.js": "^0.8.4"
},
"devDependencies": {
"concurrently": "^3.2.0",
"lite-server": "^2.2.2",
"typescript": "~2.8.1",
"canonical-path": "0.0.2",
"tslint": "^3.15.1",
"lodash": "^4.16.4",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"#types/node": "^6.0.46",
"#types/jasmine": "2.5.36"
},
"repository": {}
}
I also declare this.
declare var angular: any;
by doing that project run with no error. but nothing is rendering.
when i inspect element in browser it show me the converted component but not rendering any other angularjs component.
need help thanks
I'm new to Angular. I downloaded the Angular 2 quick-start template from https://github.com/angular/quickstart (app folder is inside an src folder), and then used VS code to modify packages.json content and manually create files/folders inside the app folder for components/services/etc.. based on tutorials that I found online. The application runs and works fine when I kick it off using npm start but I'm stuck creating the DIST folder which I need in order to upload a minified version of my application to azure web app. Whenever I run ng build from the root of my angular 2 project, I get the below error:
Cannot read property '0' of undefined
TypeError: Cannot read property '0' of undefined
at Class.run (C:\AngularTestProject\node_modules\angular-cli\tasks\build-webpack.js:15:98)
at Class.run (C:\AngularTestProject\node_modules\angular-cli\commands\build.js:51:26)
at Class.<anonymous> (C:\AngularTestProject\node_modules\angular-cli\angular-cli\lib\models\command.js:152:17)
at process._tickCallback (internal/process/next_tick.js:103:7)
This is the content of packages.json:
{
"name": "EventRecorder",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"angular-cli": {},
"scripts": {
"build": "tsc -p src/",
"build:watch": "tsc -p src/ -w",
"build:e2e": "tsc -p e2e/",
"serve": "lite-server -c=bs-config.json",
"serve:e2e": "lite-server -c=bs-config.e2e.json",
"prestart": "npm run build",
"start": "concurrently \"npm run build:watch\" \"npm run serve\"",
"pree2e": "npm run build:e2e",
"e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
"preprotractor": "webdriver-manager update",
"protractor": "protractor protractor.config.js",
"pretest": "npm run build",
"test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
"pretest:once": "npm run build",
"test:once": "karma start karma.conf.js --single-run",
"lint": "tslint ./src/**/*.ts -t verbose"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"#angular/common": "~2.4.0",
"#angular/compiler": "~2.4.0",
"#angular/core": "~2.4.0",
"#angular/forms": "~2.4.0",
"#angular/http": "~2.4.0",
"#angular/platform-browser": "~2.4.0",
"#angular/platform-browser-dynamic": "~2.4.0",
"#angular/router": "~3.4.0",
"angular-in-memory-web-api": "~0.2.4",
"systemjs": "0.19.40",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"zone.js": "^0.7.4",
"bootstrap": "^3.3.6"
},
"devDependencies": {
"#angular/compiler-cli": "2.2.1",
"concurrently": "^3.2.0",
"lite-server": "^2.2.2",
"typescript": "~2.0.10",
"angular-cli": "1.0.0-beta.21",
"canonical-path": "0.0.2",
"tslint": "^3.15.1",
"lodash": "^4.16.4",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"ts-node": "1.2.1",
"#types/node": "^6.0.46",
"#types/jasmine": "2.5.36",
"webdriver-manager": "10.2.5"
},
"repository": {}
}
And lastly this is the folder structure of my app:
App Folder Structure
Issue was resolved by installing the latest version of Angular CLI (1.0.0-rc.1) and recreating the Angular project (using ng new projectname command) and copying my TS files from my old project over.
I have a react web application, that uses webpack.
Due to the issue with Left-pad I am including my node_modules folder in source control.
I have mocha and enzyme set up to unit test my react modules and my packages.json has the following test configuration.
"test": "mocha-webpack --webpack-config webpack.config-test.js \"source/**/*.test.js\""
It all works great. when I run
npm run test
on my local development machine. All my test's get executed.
The problem I have is when I run "npm run test" as part of a build process on a dedicated build machine I get the following error
Error: Cannot find module 'enzyme'
After some digging around, I discovered that if I ran
npm install enzyme
on the build machine before I ran the test, then it worked fine.
The reason this worked is that the install modified my node_modules/enzyme/packages.json file. There are 2 full paths stored in this file that had the paths to my local dev environment in them, and they got changed to the full path to where my project was run on the build machine.
One under _Args and one under _where
{
"_args": [
[
{
"raw": "enzyme#^2.6.0",
"scope": null,
"escapedName": "enzyme",
"name": "enzyme",
"rawSpec": "^2.6.0",
"spec": ">=2.6.0 <3.0.0",
"type": "range"
},
"C:\\Dev\\UnifiedWeb"
]
],
"_from": "enzyme#>=2.6.0 <3.0.0",
"_id": "enzyme#2.6.0",
"_inCache": true,
"_location": "/enzyme",
"_nodeVersion": "7.0.0",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/enzyme-2.6.0.tgz_1478746866117_0.454174768878147"
},
"_npmUser": {
"name": "ljharb",
"email": "ljharb#gmail.com"
},
"_npmVersion": "3.10.8",
"_phantomChildren": {},
"_requested": {
"raw": "enzyme#^2.6.0",
"scope": null,
"escapedName": "enzyme",
"name": "enzyme",
"rawSpec": "^2.6.0",
"spec": ">=2.6.0 <3.0.0",
"type": "range"
},
"_requiredBy": [
"#DEV:/",
"#USER"
],
"_resolved": "https://registry.npmjs.org/enzyme/-/enzyme-2.6.0.tgz",
"_shasum": "148d742b25e2565f7e80870a0c92aea9be1b90ea",
"_shrinkwrap": null,
"_spec": "enzyme#^2.6.0",
"_where": "C:\\Dev\\UnifiedWeb",
"author": {
"name": "Leland Richardson",
"email": "leland.richardson#airbnb.com"
},
"bugs": {
"url": "https://github.com/airbnb/enzyme/issues"
},
"dependencies": {
"cheerio": "^0.22.0",
"function.prototype.name": "^1.0.0",
"in-publish": "^2.0.0",
"is-subset": "^0.1.1",
"lodash": "^4.16.4",
"object-is": "^1.0.1",
"object.assign": "^4.0.4",
"object.entries": "^1.0.3",
"object.values": "^1.0.3",
"uuid": "^2.0.3"
},
"description": "JavaScript Testing utilities for React",
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-eslint": "^7.1.0",
"babel-loader": "^6.2.7",
"babel-preset-airbnb": "^2.1.1",
"babel-register": "^6.18.0",
"chai": "^3.5.0",
"coveralls": "^2.11.14",
"enzyme-example-jest": "^0.1.0",
"enzyme-example-karma": "^0.1.1",
"enzyme-example-karma-webpack": "^0.1.4",
"enzyme-example-mocha": "^0.1.0",
"enzyme-example-react-native": "^0.1.0",
"eslint": "^3.9.1",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.6.0",
"gitbook-cli": "^1.0.1",
"istanbul": "^1.0.0-alpha.2",
"jsdom": "^6.1.0",
"json-loader": "^0.5.4",
"karma": "^1.3.0",
"karma-chrome-launcher": "^1.0.1",
"karma-firefox-launcher": "^1.0.0",
"karma-mocha": "^1.2.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"mocha": "^3.1.2",
"rimraf": "^2.5.4",
"safe-publish-latest": "^1.1.1",
"sinon": "^1.17.6",
"webpack": "^1.13.3"
},
"directories": {},
"dist": {
"shasum": "148d742b25e2565f7e80870a0c92aea9be1b90ea",
"tarball": "https://registry.npmjs.org/enzyme/-/enzyme-2.6.0.tgz"
},
"gitHead": "5c37d91715a88d393f3c260447a189a446d76e0c",
"homepage": "https://github.com/airbnb/enzyme#readme",
"keywords": [
"javascript",
"shallow rendering",
"shallowRender",
"test",
"reactjs",
"react",
"flux",
"testing",
"test utils",
"assertion helpers",
"tdd",
"mocha"
],
"license": "MIT",
"main": "build",
"maintainers": [
{
"name": "airbnb",
"email": "jordan.harband+npm#airbnb.com"
},
{
"name": "intelligibabble",
"email": "leland.m.richardson#gmail.com"
},
{
"name": "ljharb",
"email": "ljharb#gmail.com"
}
],
"name": "enzyme",
"optionalDependencies": {},
"peerDependencies": {
"react": "0.13.x || 0.14.x || ^15.0.0-0 || 15.x"
},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/airbnb/enzyme.git"
},
"scripts": {
"build": "babel src --out-dir build",
"check": "npm run lint && npm run test:all",
"clean": "rimraf build",
"docs:build": "npm run docs:prepare && gitbook build",
"docs:clean": "rimraf _book",
"docs:prepare": "gitbook install",
"docs:publish": "npm run docs:clean && npm run docs:build && cd _book && git init && git commit --allow-empty -m 'update book' && git fetch git#github.com:airbnb/enzyme.git gh-pages && git checkout -b gh-pages && git add . && git commit -am 'update book' && git push git#github.com:airbnb/enzyme.git gh-pages --force",
"docs:watch": "npm run docs:prepare && gitbook serve",
"lint": "eslint --ext js,jsx src test",
"postversion": "git push && git push --tags && npm run clean && npm run docs:publish",
"prepublish": "not-in-publish || (npm run clean && npm run build && safe-publish-latest)",
"pretest": "npm run lint",
"preversion": "npm run clean && npm run check",
"react:13": "npm run react:clean && npm i react#0.13",
"react:14": "npm run react:clean && npm i react#0.14 react-dom#0.14 react-addons-test-utils#0.14",
"react:15": "npm run react:clean && npm i react#15 react-dom#15 react-addons-test-utils#15",
"react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils",
"test": "npm run clean && npm run build && npm run test:only",
"test:all": "npm run react:13 && npm run test:only && npm run react:14 && npm run test:only && npm run react:15 && npm run test:only",
"test:env": "sh ./example-test.sh",
"test:karma": "karma start",
"test:only": "mocha --recursive test",
"test:single": "mocha --watch",
"test:watch": "mocha --recursive --watch test",
"travis": "babel-node ./node_modules/.bin/istanbul cover --report html _mocha -- test --recursive",
"version": "npm run build"
},
"version": "2.6.0"
}
This problem will also affect other developers in my team, as the paths will need to be changed to their local development if they want to run the tests locally.
Why is the full path in the enzyme package? Is there a better way of handling this? Am I missing something, or is npm not portable?
Have you tried npm link ext/* --prefix=node_modules
As per this thread - Local dependency in package.json
I'm working through the Angular 2 tutorial (https://angular.io/guide/quickstart) and using npm start to watch the TypeScript files and automatically transpile and reload the built-in web server when they change.
It works fine but there seems to be a lot of lag. Sometimes it can take 10 seconds before it notices that the files have changed. Once it sees the changes, it compiles and reloads very quickly.
Does anyone know if there's a way to set the polling interval to something faster?
I looked in the documentation for npm start and for the concurrently module, and I couldn't find any documented settings to change this.
Here's my package.json:
{
"name": "myapp",
"version": "0.1.0",
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" ",
"test": "live-server --open=src/unit-tests.html"
},
"license": "ISC",
"dependencies": {
"angular2": "2.0.0-beta.0",
"systemjs": "0.19.6",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.0",
"zone.js": "0.5.10"
},
"devDependencies": {
"concurrently": "^1.0.0",
"jasmine-core": "2.4.1",
"lite-server": "^1.3.1",
"typescript": "^1.7.3"
}
}
It's a typescript bug from version 1.7.4+.
In the package.json, write "typescript": "1.7.3" and then execute npm update to install that version.