Angular2: PrimeNG - XHR error (404 Not Found) - angularjs

I want to use Dialog from PrimeNG-Module, but i always get the Error:
Unhandled Promise rejection: (SystemJS) Error: XHR error (404 Not Found) loading http://localhost:4200/node_modules/primeng/primeng.js
I used the setup configuration from http://www.primefaces.org/primeng/#/setup
But everything that i've tried, will not work.
I'm using Angular2 RC4.
system-config.ts
/** Map relative paths to URLs. */
const map: any = {
'firebase': 'vendor/firebase/firebase.js',
'angularfire2': 'vendor/angularfire2',
'primeng': 'node_modules/primeng'
};
/** User packages configuration. */
const packages: any = {
angularfire2: {
defaultExtension: 'js',
main: 'angularfire2.js'
},
'primeng': { defaultExtension: 'js' }
};
////////////////////////////////////////////////////////////////////////////////////////////////
/***********************************************************************************************
* Everything underneath this line is managed by the CLI.
**********************************************************************************************/
const barrels: string[] = [
// Angular specific barrels.
'#angular/core',
'#angular/common',
'#angular/compiler',
'#angular/forms',
'#angular/http',
'#angular/router',
'#angular/platform-browser',
'#angular/platform-browser-dynamic',
// Thirdparty barrels.
'rxjs',
// App specific barrels.
'app',
'app/shared',
/** #cli-barrel */
];
const cliSystemConfigPackages: any = {};
barrels.forEach((barrelName: string) => {
cliSystemConfigPackages[barrelName] = { main: 'index' };
});
/** Type declaration for ambient System. */
declare var System: any;
// Apply the CLI SystemJS configuration.
System.config({
map: {
'#angular': 'vendor/#angular',
'rxjs': 'vendor/rxjs',
'main': 'main.js'
},
packages: cliSystemConfigPackages
});
// Apply the user's configuration.
System.config({ map, packages });
angular-cli-build.js
/* global require, module */
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(ts|js|js.map)',
'rxjs/**/*.+(js|js.map)',
'#angular/**/*.+(js|js.map)',
'angularfire2/**/*.js',
'firebase/*.js',
'primeng/*.js'
]
});
};
location-component.ts
import {Component} from "#angular/core";
import {LocationGridComponent} from "./location-grid/location-grid.component";
import {LocationDetailComponent} from "./location-detail/location-detail.component";
import {Dialog} from "primeng/primeng";
#Component({
selector: 'app-location',
templateUrl: 'app/location/location.component.html',
styleUrls: ['app/orienteering/orienteering.component.css', 'app/location/location.component.css'],
directives: [LocationGridComponent, LocationDetailComponent, Dialog]
})
export class LocationComponent {
display: boolean = false;
showDialog() {
this.display = true;
}
}
package.json
{
"name": "digitaler-lerngarten",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"postinstall": "typings install",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"#angular/common": "^2.0.0-rc.4",
"#angular/compiler": "^2.0.0-rc.4",
"#angular/core": "^2.0.0-rc.4",
"#angular/forms": "^0.2.0",
"#angular/http": "^2.0.0-rc.4",
"#angular/platform-browser": "^2.0.0-rc.4",
"#angular/platform-browser-dynamic": "^2.0.0-rc.4",
"#angular/router": "^3.0.0-beta.2",
"angular-cli": "^1.0.0-beta.9",
"codelyzer": "0.0.25",
"es6-shim": "^0.35.1",
"karma": "^1.1.1",
"karma-chrome-launcher": "^1.0.1",
"karma-jasmine": "^1.0.2",
"latest-version": "^2.0.0",
"primeng": "^1.0.0-beta.9",
"primeui": "^4.1.12",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"systemjs": "^0.19.31",
"ts-node": "^0.9.3",
"tslint": "^3.13.0",
"typings": "^1.3.1",
"zone.js": "^0.6.12"
},
"devDependencies": {
"angular-cli": "^1.0.0-beta.9",
"codelyzer": "^0.0.25",
"ember-cli-inject-live-reload": "^1.4.0",
"jasmine-core": "^2.4.1",
"jasmine-spec-reporter": "^2.5.0",
"karma": "^1.1.1",
"karma-chrome-launcher": "^1.0.1",
"karma-jasmine": "^1.0.2",
"protractor": "^3.3.0",
"ts-node": "^0.9.3",
"tslint": "^3.11.0",
"typescript": "^1.8.10",
"typings": "^1.3.1"
}
}

I've downgraded to Angular2 RC3, and now it works.
I had to change 'node_modules/primeng' in system-config.ts to 'vendor/primeng'.
Then i add the primeng-files in angular-cli-build.js and then rebuilding the project with "ng build".
system-config.ts
// SystemJS configuration file, see links for more information
// https://github.com/systemjs/systemjs
// https://github.com/systemjs/systemjs/blob/master/docs/config-api.md
/***********************************************************************************************
* User Configuration.
**********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
'firebase': 'vendor/firebase/firebase.js',
'angularfire2': 'vendor/angularfire2',
'primeng': 'vendor/primeng'
};
/** User packages configuration. */
const packages: any = {
angularfire2: {
defaultExtension: 'js',
main: 'angularfire2.js'
},
primeng: { defaultExtension: 'js' }
};
////////////////////////////////////////////////////////////////////////////////////////////////
/***********************************************************************************************
* Everything underneath this line is managed by the CLI.
**********************************************************************************************/
const barrels: string[] = [
// Angular specific barrels.
'#angular/core',
'#angular/common',
'#angular/compiler',
'#angular/forms',
'#angular/http',
'#angular/router',
'#angular/platform-browser',
'#angular/platform-browser-dynamic',
// Thirdparty barrels.
'rxjs',
// App specific barrels.
'app',
'app/shared',
/** #cli-barrel */
];
const cliSystemConfigPackages: any = {};
barrels.forEach((barrelName: string) => {
cliSystemConfigPackages[barrelName] = { main: 'index' };
});
/** Type declaration for ambient System. */
declare var System: any;
// Apply the CLI SystemJS configuration.
System.config({
map: {
'#angular': 'vendor/#angular',
'rxjs': 'vendor/rxjs',
'main': 'main.js'
},
packages: cliSystemConfigPackages
});
// Apply the user's configuration.
System.config({ map, packages });
angular-cli-build.js
// Angular-CLI build configuration
// This file lists all the node_modules files that will be used in a build
// Also see https://github.com/angular/angular-cli/wiki/3rd-party-libs
/* global require, module */
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(ts|js|js.map)',
'rxjs/**/*.+(js|js.map)',
'#angular/**/*.+(js|js.map)',
'angularfire2/**/*.js',
'firebase/*.js',
'primeng/**/*.js',
'primeui/**/*.css'
]
});
};
package.json
{
"name": "digitaler-lerngaraten",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"postinstall": "typings install",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"#angular/common": "2.0.0-rc.3",
"#angular/compiler": "2.0.0-rc.3",
"#angular/core": "2.0.0-rc.3",
"#angular/forms": "0.2.0",
"#angular/http": "2.0.0-rc.3",
"#angular/platform-browser": "2.0.0-rc.3",
"#angular/platform-browser-dynamic": "2.0.0-rc.3",
"#angular/router": "3.0.0-alpha.8",
"angularfire2": "^2.0.0-beta.2",
"es6-shim": "0.35.1",
"firebase": "^3.2.0",
"primeng": "^1.0.0-beta.9",
"primeui": "^4.1.12",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"systemjs": "0.19.26",
"zone.js": "0.6.12"
},
"devDependencies": {
"angular-cli": "1.0.0-beta.9",
"codelyzer": "0.0.20",
"ember-cli-inject-live-reload": "1.4.0",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"karma": "0.13.22",
"karma-chrome-launcher": "0.2.3",
"karma-jasmine": "0.3.8",
"protractor": "3.3.0",
"ts-node": "0.5.5",
"tslint": "3.11.0",
"typescript": "1.8.10",
"typings": "0.8.1"
}
}

Try it once.
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
},
'node_modules/primeng': {
format: 'cjs',
defaultExtension: 'js'
}
},
map: {
"primeng": "node_modules/primeng"
}
});
System.import('app/js/components/main')
.then(null, console.error.bind(console));

Basically follow the examples on how to install 3rd party libraries
Install package via npm
OPTIONAL! Install typings for library
Add package to angular-cli-build.js file to vendorNpmFiles array (very important). It tells where to find the files which will go to the vendor folder inside the dist folder.
Configure SystemJS mappings to know where to look for package (where all the files will be in the dist folder).

Related

React does not have hot/live reload, how to set it up?

I recently joined a company that works with react (classes) and typescript, I was flabbergasted when I knew that the react they are using does not hot/live reload on changes (CSS, state, or any change), what happens on changes is webpack recompiles (takes around 25 seconds) and to see changes I should reload the page which is slowing down the development experience greatly.
Talking to the manager it was decided that we do a migration to a new create react app gradually as there is lots of code and redundancy and we want to use functional react hooks (which will take years maybe as the app is big) but until then I want to resolve the hot reload issue.
I believe the react app a long time ago was not started with creat-react-app or something.
Just to mention I have 1.5 yrs experience in the industry so config stuff is still new to me and am just doing this for my learning benefits and to improve the team experience, it's not really an assigned task to do.
Below are our package.json, webpack file, and index file. Please let me know if you need to see anything else.
Package.json:
{
"name": "web-front-end",
"version": "1.22.19",
"description": "HTML5 implementation of the <our company name>. Written in Typescript, compiled to JavaScript, bundled with Webpack, executing on NodeJS, using React, adopting FLUX patterns.",
"private": true,
"scripts": {
"babel": "babel built/client/js/client.js -o built/client/js/client.js",
"clean": "rm -rf node_modules && rm -rf built && rm -rf coverage && echo 'clean complete'",
"reset": "yarn clean && yarn cache clean && yarn install --frozen-lockfile",
"compile": "yarn compile-client && yarn compile-server && yarn babel",
"debug-client": "NODE_ENV=debug webpack --config webpack.dev.js && echo 'client compile complete'",
"compile-client": "NODE_ENV=production webpack --config webpack.prod.js && echo 'production client compile complete'",
"compile-client-dev": "NODE_ENV=development webpack --config webpack.dev.js && echo 'development client compile complete'",
"compile-client-dev-watch": "NODE_ENV=development webpack --config webpack.dev-watch.js",
"compile-server": "tsc -p src/server && echo 'server compile complete'",
"compile-client-watch": "NODE_ENV=development webpack --config webpack.dev-watch.js",
"compile-server-watch": "tsc -p src/server --watch",
"validate": "yarn --ignore-engines && tslint './src/**/*.{ts,tsx}' './test/**/*.{ts,tsx}' && echo 'validate complete'",
"start-server": "node ./built/server/ServerApp.js",
"test": "tslint --project test && tslint --project src/app && tsc -p test --jsx react && node ./node_modules/jest/bin/jest.js --config=jest.test.config.json --coverage --verbose",
"lint-fix": "tslint --fix --project src && tslint --fix --project test",
"prepare": "patch-package"
},
"dependencies": {
"#emotion/react": "^11.9.3",
"#emotion/styled": "^11.9.3",
"#mui/icons-material": "^5.8.4",
"#mui/material": "^5.8.4",
"#mui/styles": "^5.8.4",
"#stripe/stripe-js": "1.11.0",
"assert": "^2.0.0",
"axios": "^0.27.2",
"blob-stream": "0.1.3",
"buffer": "^6.0.3",
"compression": "1.7.3",
"compression-webpack-plugin": "^10.0.0",
"connected-react-router": "^6.9.2",
"cors": "2.8.4",
"device-uuid": "1.0.4",
"dotenv": "6.0.0",
"express": "4.16.3",
"file-saver": "^2.0.5",
"html-to-image": "^1.10.8",
"https-browserify": "^1.0.0",
"js-cookie": "2.2.0",
"node-zip": "1.1.1",
"path-to-regexp": "2.4.0",
"pug": "2.0.3",
"query-string": "6.1.0",
"react": "17.0.0",
"react-copy-to-clipboard": "5.0.1",
"react-dom": "^17.0.2",
"react-form-validator-core": "0.4.4",
"react-hook-form": "^7.36.0",
"react-inlinesvg": "2.3.0",
"react-jss": "8.5.1",
"react-lazy-load": "3.0.13",
"react-markdown": "4.0.4",
"react-material-ui-form-validator": "^3.0.1",
"react-player": "1.14.2",
"react-redux": "^7.2.6",
"react-router": "5.2.1",
"react-router-dom": "5.3.0",
"react-share": "2.4.0",
"react-speech-recognition": "^3.10.0",
"react-stripe-elements": "2.0.1",
"react-svgmt": "^1.2.0",
"react-virtualized": "9.22.3",
"react-youtube": "7.9.0",
"recompose": "0.27.1",
"rect": "1.2.1",
"redux": "4.0.0",
"redux-thunk": "2.3.0",
"regenerator-runtime": "^0.13.9",
"shortid": "2.2.15",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"svg-to-pdfkit": "0.1.7",
"url": "^0.11.0",
"utf8": "3.0.0"
},
"devDependencies": {
"#babel/cli": "^7.17.6",
"#babel/core": "^7.17.8",
"#babel/types": "^7.17.0",
"#types/blob-stream": "0.1.29",
"#types/code": "4.0.4",
"#types/detect-browser": "3.0.0",
"#types/jest": "25.2.3",
"#types/js-cookie": "2.2.1",
"#types/lab": "11.1.0",
"#types/react": "17.0.14",
"#types/react-dom": "17.0.14",
"#types/react-inlinesvg": "1.0.0",
"#types/react-redux": "^7.1.20",
"#types/react-router": "4.4.5",
"#types/react-virtualized": "9.21.18",
"#types/shortid": "0.0.29",
"#types/utf8": "2.1.6",
"awesome-typescript-loader": "3.4.1",
"copy-webpack-plugin": "4.5.1",
"detect-browser": "3.0.1",
"fork-ts-checker-webpack-plugin": "^7.2.13",
"jest": "^27.5.1",
"patch-package": "6.1.2",
"postinstall-postinstall": "2.0.0",
"process": "^0.11.10",
"source-map-loader": "0.2.3",
"source-map-support": "0.4.18",
"ts-jest": "27.1.2",
"ts-loader": "^9.3.1",
"ts-mockito": "2.3.0",
"ts-node": "^10.8.1",
"tslint": "^6.0.1",
"tslint-eslint-rules": "5.4.0",
"tslint-react": "^5.0.0",
"typescript": "4.1.5",
"webpack": "^5.73.0",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-cli": "^4.10.0",
"webpack-merge": "^5.8.0"
},
"resolutions": {
"#types/prop-types": "15.7.5",
"#types/unist": "2.0.0",
"#types/react-transition-group": "2.0.8",
"#types/react": "17.0.14",
"#types/react-dom": "17.0.14"
},
"repository": {
"type": "git",
"url": "our repo link"
},
"author": "our company name",
"license": "MIT",
}
Webpack.common.js:
const path = require("path");
const webpack = require('webpack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = {
entry: "./src/app/Main.ts",
cache: false,
optimization: {
providedExports: true,
usedExports: true,
removeAvailableModules: true,
removeEmptyChunks: true,
mergeDuplicateChunks: true,
chunkIds: 'named',
},
plugins: [
new webpack.ProvidePlugin({process: "process/browser"}),
new ForkTsCheckerWebpackPlugin(
{
typescript: {
configFile: './src/app/tsconfig.json'
}
}),
],
module: {
rules: [
{
test: /\.tsx?$/i,
loader: "ts-loader",
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: "asset/resource",
generator: {
filename: 'assets/[hash][ext]',
},
},
],
},
resolve: {
alias: {
core: path.join(__dirname, "src", "core"),
client: path.join(__dirname, "src", "client"),
server: path.join(__dirname, "src", "server"),
'<our company name>-typescript-common': path.resolve(__dirname, 'node_modules/<our company name>-typescript-common/'),
},
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js", ".jsx"],
fallback: {
"util": require.resolve('util'),
"os": false,
"fs": false,
"path": false,
"zlib": false,
"buffer": require.resolve('buffer'),
"http": require.resolve('stream-http'),
"https": require.resolve('https-browserify'),
"url": require.resolve('url'),
"stream": require.resolve('stream-browserify'),
},
},
output: {
path: path.resolve(__dirname, "built"),
filename: "client/js/client.js",
clean: true,
},
};
index.js (called Main.ts on our codebase)
import { render } from 'react-dom';
import { AppWrapper } from './view/App/AppWrapper';
declare var window: any;
class CompanyName {
constructor() {
window.dataLayer = window.dataLayer || [];
window._hsq = window._hsq || [];
const rootHtmlElement = document.body.appendChild(document.createElement('div'));
render(new AppWrapper({
lang: window.appConfig.LANGUAGE,
appConfig: window.appConfig,
startupTimestamp: window.sts}).render(), rootHtmlElement);
}
}
// tslint:disable-next-line:no-unused-expression
new CompanyName();
webpack.dev-watch.js:
const { merge } = require("webpack-merge");
const common = require("./webpack.dev.js");
const path = require('path');
module.exports = merge(common, {
watch: true,
optimization: {
minimize: false,
mangleExports: false,
mangleWasmImports: false
},
watchOptions: {
ignored: [
path.posix.resolve(__dirname, './node_modules'),
path.posix.resolve(__dirname, './rfg'),
path.posix.resolve(__dirname, './patches'),
path.posix.resolve(__dirname, './built'),
],
poll: 1500,
aggregateTimeout: 1000,
},
});
I would be grateful if you provide any explanations, explanatory links or videos in your answers so I can learn more.
Thanks.

WebSocket connection to 'wss://localhost:3000/sockjs-node' failed:

I am working in a react application (Below Package.json)
{
"name": "seed",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8080",
"dependencies": {
"#ckeditor/ckeditor5-adapter-ckfinder": "23.1.0",
"#ckeditor/ckeditor5-alignment": "23.1.0",
"#ckeditor/ckeditor5-autoformat": "23.1.0",
"#ckeditor/ckeditor5-basic-styles": "23.1.0",
"#ckeditor/ckeditor5-block-quote": "23.1.0",
"#ckeditor/ckeditor5-build-classic": "23.1.0",
"#ckeditor/ckeditor5-ckfinder": "23.1.0",
"#ckeditor/ckeditor5-dev-utils": "^23.5.1",
"#ckeditor/ckeditor5-dev-webpack-plugin": "^23.5.1",
"#ckeditor/ckeditor5-easy-image": "23.1.0",
"#ckeditor/ckeditor5-editor-classic": "23.1.0",
"#ckeditor/ckeditor5-editor-decoupled": "23.1.0",
"#ckeditor/ckeditor5-font": "23.1.0",
"#ckeditor/ckeditor5-heading": "23.1.0",
"#ckeditor/ckeditor5-highlight": "23.1.0",
"#ckeditor/ckeditor5-image": "23.1.0",
"#ckeditor/ckeditor5-link": "23.1.0",
"#ckeditor/ckeditor5-list": "23.1.0",
"#ckeditor/ckeditor5-media-embed": "23.1.0",
"#ckeditor/ckeditor5-paste-from-office": "23.1.0",
"#ckeditor/ckeditor5-react": "3.0.0",
"#ckeditor/ckeditor5-real-time-collaboration": "23.1.0",
"#ckeditor/ckeditor5-remove-format": "23.1.0",
"#ckeditor/ckeditor5-table": "23.1.0",
"#ckeditor/ckeditor5-theme-lark": "23.1.0",
"#date-io/date-fns": "1.3.13",
"#material-ui/core": "4.9.10",
"#material-ui/icons": "^4.9.1",
"#material-ui/lab": "^4.0.0-alpha.56",
"#material-ui/pickers": "^3.2.10",
"#types/pdfjs-dist": "^2.1.5",
"aws-amplify": "^3.0.22",
"babel-polyfill": "6.26.0",
"connected-react-router": "^6.3.2",
"date-fns": "^2.14.0",
"env-cmd": "8.0.2",
"formik": "2.1.5",
"history": "4.7.2",
"juice": "^7.0.0",
"lodash": "^4.17.11",
"pdf-viewer-reactjs": "^2.0.7",
"pdfjs-dist": "2.4.456",
"raw-loader": "^4.0.1",
"react": "^16.8.3",
"react-dom": "^16.8.3",
"react-hot-toast": "^1.0.2",
"react-intl": "2.7.2",
"react-redux": "^6.0.1",
"react-router": "4.3.1",
"react-router-dom": "4.3.1",
"react-scripts": "^2.1.5",
"redux": "4.0.1",
"redux-persist": "5.10.0",
"redux-persist-transform-filter": "^0.0.20",
"redux-saga": "^1.0.2",
"styled-components": "4.1.1",
"superagent": "4.0.0",
"typesafe-actions": "^3.0.0",
"yup": "^0.28.3"
},
"scripts": {
"start": "HTTPS=true REACT_APP_ENV=local react-app-rewired start",
"start:windows": "set HTTPS=true&&set REACT_APP_ENV=local&&react-app-rewired start",
"build": "env-cmd .env.${REACT_APP_ENV} react-app-rewired build",
"build:staging": "REACT_APP_ENV=staging env-cmd .env.staging react-app-rewired build ",
"build:qa": "REACT_APP_ENV=qa env-cmd .env.qa react-app-rewired build ",
"build:qaint": "REACT_APP_ENV=qaint env-cmd .env.qaint react-app-rewired build ",
"build:euat": "REACT_APP_ENV=euat env-cmd .env.euat react-app-rewired build ",
"test": "react-app-rewired test --maxWorkers=4",
"test:ci": "react-app-rewired test --maxWorkers=4 --all --coverage",
"eject": "react-app-rewired eject",
"analyze": "env-cmd .env.${REACT_APP_ENV} react-app-rewired build --analyze-bundle",
"test:coverage": "npm run test -- --coverage",
"generate": "plop --plopfile scripts/generators/index.js",
"lint": "eslint 'src/**/*.{js,ts,tsx}'",
"lint:fix": "eslint 'src/**/*.{js,ts,tsx}' --fix",
"lint-style": "stylelint 'src/**/*.style.{ts,tsx}' 'src/**/style.{ts,tsx}'",
"cypress:run": "sudo docker-compose -f docker-compose-cypress.yml run e2e-chrome"
},
"browserslist": [
">0.2%",
"not dead",
"not ie < 11",
"not op_mini all"
],
"jest": {
"collectCoverageFrom": [
"src/**/*.js",
"!src/**/*.test.js",
"!src/**/actions.js",
"!src/**/index.js",
"!src/**/serviceWorker.js",
"!src/**/*.wrap.js",
"!src/index.js",
"!src/tempPolyfills.js",
"!src/setupTests.js",
"!src/redux/reducers.js",
"!src/redux/sagas.js",
"!src/redux/store.js",
"!src/**/mocks/**",
"!src/redux/reducers.ts",
"!src/redux/sagas.ts"
],
"coverageThreshold": {
"global": {
"statements": 0,
"branches": 0,
"functions": 0,
"lines": 0
}
},
"snapshotSerializers": [
"<rootDir>/node_modules/enzyme-to-json/serializer"
],
"setupFiles": [
"core-js"
]
},
"bundlesize": [
{
"path": "./build/static/js/*.js",
"maxSize": "200 kB"
}
],
"devDependencies": {
"#types/cheerio": "^0.22.10",
"#types/enzyme": "^3.1.15",
"#types/enzyme-react-intl": "^2.0.0",
"#types/history": "^4.7.2",
"#types/jest": "^23.3.12",
"#types/lodash": "^4.14.119",
"#types/node": "^10.12.18",
"#types/pdf-viewer-reactjs": "^2.0.0",
"#types/react": "^16.8.3",
"#types/react-dom": "^16.0.11",
"#types/react-intl": "^2.3.15",
"#types/react-redux": "^6.0.12",
"#types/react-router": "^4.4.3",
"#types/react-router-dom": "^4.3.1",
"#types/react-test-renderer": "^16.0.3",
"#types/redux-mock-store": "^1.0.2",
"#types/styled-components": "^4.1.5",
"#types/superagent": "^3.8.6",
"#types/webpack-env": "^1.13.6",
"#types/yup": "^0.26.34",
"#typescript-eslint/eslint-plugin": "^1.6.0",
"#typescript-eslint/parser": "^1.6.0",
"babel-plugin-styled-components": "1.8.0",
"enzyme": "3.7.0",
"enzyme-adapter-react-16": "1.15",
"enzyme-react-intl": "^2.0.6",
"enzyme-to-json": "3.3.4",
"eslint-config-prettier": "4.1.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jest": "22.0.0",
"eslint-plugin-jsx-a11y": "6.1.2",
"eslint-plugin-mysticatea": "4.2.4",
"eslint-plugin-prefer-object-spread": "1.2.1",
"eslint-plugin-prettier": "3.0.0",
"eslint-plugin-react": "7.11.1",
"husky": "^4.2.5",
"mockdate": "^3.0.2",
"plop": "2.1.0",
"prettier": "1.15.1",
"react-app-rewire-webpack-bundle-analyzer": "1.0.1",
"react-app-rewired": "2.1.0",
"react-test-renderer": "16.10",
"redux-mock-store": "^1.5.4",
"redux-saga-test-plan": "^4.0.0-beta.2",
"stylelint": "^9.10.1",
"stylelint-config-prettier": "^4.0.0",
"stylelint-config-standard": "^18.2.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-declaration-strict-value": "^1.1.2",
"stylelint-processor-styled-components": "^1.5.2",
"typescript": "^3.2.2",
"wait-on": "^3.2.0",
"webpack-manifest-plugin": "^2.0.4"
}
}
Below config-overrides.js
const { styles } = require( '#ckeditor/ckeditor5-dev-utils' );
module.exports = {
webpack: function override(config, env) {
const analyzeBundle = process.argv.indexOf('--analyze-bundle') !== -1;
if (analyzeBundle) {
const rewireWebpackBundleAnalyzer = require('react-app-rewire-webpack-bundle-analyzer');
config = rewireWebpackBundleAnalyzer(config, env, {
analyzerMode: 'static',
reportFilename: 'report.html',
});
}
// Fix strange issue with webpack build
// details here: https://stackoverflow.com/questions/60407393/create-react-app-production-build-runtime-error-cannot-read-property-call-of
// TODO: maybe update webpack to fix while keeping import optimization
config.optimization.sideEffects = false;
// Customize webpack config here
console.log("Loading Custom config for Webpack, rebuilding ckeditor");
const oneOfIndex = config.module.rules.findIndex(item => {
return item.hasOwnProperty("oneOf");
});
oneOf = config.module.rules[oneOfIndex].oneOf;
// Add the SVG and CSS loaders to the oneOf array
const additions = [
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
use: ["raw-loader"]
},
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/,
use: [
{
loader: "style-loader",
},
{
loader: "postcss-loader",
options: styles.getPostCssConfig({
themeImporter: {
themePath: require.resolve("#ckeditor/ckeditor5-theme-lark")
},
minify: true
})
}
]
}
];
additions.forEach((item) => {
oneOf.push(item);
});
const cssRegex = /\.css$/;
const cssModuleRegex = /\.module\.css$/;
// Modify cssRegex
let loader;
loader = oneOf.find(item => {
if (item.test !== undefined)
return item.test.toString() === cssRegex.toString();
});
loader.exclude = [cssModuleRegex, /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/];
// Modify cssModuleRegex
loader = oneOf.find(item => {
if (item.test !== undefined)
return item.test.toString() === cssModuleRegex.toString();
});
loader.exclude = [/ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/];
// Modify file-loader
loader = oneOf.find(item => {
if (item.loader !== undefined)
return (
item.loader.toString() === require.resolve("file-loader").toString()
);
});
loader.exclude = [
/\.(js|mjs|jsx|ts|tsx)$/,
/\.html$/,
/\.json$/,
/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
/ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/
];
config.module.rules[oneOfIndex].oneOf = oneOf;
return config;
},
devServer: function(configFunction) {
// Return the replacement function for create-react-app to use to generate the Webpack
// Development Server config. "configFunction" is the function that would normally have
// been used to generate the Webpack Development server config - you can use it to create
// a starting configuration to then modify instead of having to create a config from scratch.
return function(proxy, allowedHost) {
// Create the default config by calling configFunction with the proxy/allowedHost parameters
const defaultConfig = configFunction(proxy, allowedHost);
return {
...defaultConfig,
hot: true,
historyApiFallback: true,
// Allow mounting react apps from a page served by the backend.
headers: {
'Access-Control-Allow-Origin': 'http://localhost:8080',
},
};
};
},
};
I am trying to load another react application as a microfront end using :
I ve tested the imported microfront end in a simple react app (container) and everything went well
import React, {useCallback, useEffect} from 'react';
import {History} from 'history';
interface MicroFrontendProps {
history?: History;
name: string;
host: string | undefined;
}
const MicroFrontend: React.FC<MicroFrontendProps> = ({history, name, host,}) => {
const renderMicroFrontend = useCallback(() => {
(window as any)[`render${name}`](`${name}-container`, history);
}, [name, history]);
useEffect(() => {
const scriptId = `micro-frontend-script-${name}`;
if (document.getElementById(scriptId)) {
renderMicroFrontend();
} else {
fetch(`${host}/asset-manifest.json`)
.then(res => res.json())
.then(manifest => {
const promises = Object.keys(manifest.files)
.filter(key => key.endsWith('.js'))
.reduce((sum, key) => {
sum.push(
new Promise(resolve => {
const path = `${host}${manifest.files[key]}`;
const script = document.createElement('script');
if (key === 'main.js') {
script.id = scriptId;
}
script.onload = () => {
resolve();
};
script.crossOrigin = '';
script.src = path;
document.body.after(script);
}),
);
return sum;
}, [] as any);
Promise.allSettled(promises).then(() => {
renderMicroFrontend();
});
});
}
return () => {
(window as any)[`unmount${name}`](`${name}-container`);
};
}, [renderMicroFrontend, host, name]);
return <main id={`${name}-container`} />;
};
export default MicroFrontend;
When I am importing the app, when I go to a link which loads it I am getting this error (the imported app is rendred but server shuts down) :
webpackHotDevClient.js:60 WebSocket connection to 'wss://localhost:3000/sockjs-node' failed:
./node_modules/react-dev-utils/webpackHotDevClient.js # webpackHotDevClient.js:60
webpackHotDevClient.js:76 The development server has disconnected.
Refresh the page if necessary.
Do you have any idea about this error ?
Thanks

Rollup including my react library into bundle even though I have externals written

I am trying to build a component library for myself with a few overrides. But it's constantly giving me an insane challenge. I can't import it into my projects. Rollup for some reason is packing the whole react lib into my bundle.js file.
This rollup config
/* eslint-disable */
import { readdirSync } from 'fs';
import path from 'path';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import external from 'rollup-plugin-peer-deps-external';
import replace from 'rollup-plugin-replace';
import resolve from 'rollup-plugin-node-resolve';
import postcss from 'rollup-plugin-postcss';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
const EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.json'];
const CODES = [
'THIS_IS_UNDEFINED',
'MISSING_GLOBAL_NAME',
'CIRCULAR_DEPENDENCY'
];
const discardWarning = (warning) => {
if (CODES.includes(warning.code)) {
return;
}
console.error(warning);
};
const env = process.env.NODE_ENV;
const commonPlugins = () => [
postcss({
extract: true,
modules: true,
use: ['sass']
}),
external(),
babel({
babelrc: false,
presets: [['#babel/preset-env', { modules: false }], '#babel/preset-react'],
extensions: EXTENSIONS,
exclude: [
'node_modules/**',
'src/*/*.stories.js',
'src/*/*.spec.js',
'src/*/*.test.js'
]
}),
commonjs({
include: /node_modules/
}),
replace({ 'process.env.NODE_ENV': JSON.stringify(env) }),
resolve()
];
export default [
{
onwarn: discardWarning,
input: 'src/index.js',
output: {
esModule: false,
file: pkg.unpkg,
format: 'cjs',
name: 'ph-shared',
exports: 'named'
globals: {
antd: 'antd',
react: 'React',
'react-dom': 'ReactDOM'
}
},
external: ['react', '#ant-design', 'react-notification-system', 'antd'],
plugins: [...commonPlugins(), env === 'production' && terser()],
output: [{ dir: 'dist', format: 'cjs', exports: 'named', sourcemap: true }]
}
];
and this is package.json file
{
"name": "ph-shared",
"version": "0.0.1",
"author": "usmantahirr",
"description": "Component library for PH",
"main": "src/index.js",
"source": "src/index.js",
"module": "dist/bundle.js",
"engines": {
"node": ">=12"
},
"scripts": {
"build": "rollup -c",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint ./src/",
"lint:fix": "eslint ./src/ --fix",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,css}": [
"prettier --write",
"npm run lint:fix",
"git add"
]
},
"peerDependencies": {
"#ant-design/icons": "^4.2.2",
"react-notification-system": "^0.4.0",
"antd": "^4.6.4",
"react": "^16.13.1",
"node-sass": "^4.14.1"
},
"devDependencies": {
"#ant-design/icons": "^4.2.2",
"#babel/core": "^7.11.6",
"#babel/preset-env": "^7.11.5",
"#babel/preset-react": "^7.10.4",
"#storybook/addon-actions": "^6.0.21",
"#storybook/addon-essentials": "^6.0.21",
"#storybook/addon-knobs": "^6.0.21",
"#storybook/addon-links": "^6.0.21",
"#storybook/preset-create-react-app": "^3.1.4",
"#storybook/react": "^6.0.21",
"antd": "^4.6.4",
"babel": "^6.23.0",
"babel-loader": "^8.1.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.7.0",
"eslint-config-standard": "^14.1.0",
"eslint-config-standard-react": "^9.2.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-standard": "^4.0.1",
"husky": "^1.3.1",
"lint-staged": "^8.1.5",
"node-sass": "^4.14.1",
"prettier": "^2.0.4",
"react-is": "^16.13.1",
"react-notification-system": "^0.4.0",
"react-scripts": "^3.4.3",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.3",
"rollup-plugin-postcss": "^3.1.8",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^7.0.2",
"sass-resources-loader": "^2.1.0",
"styled-components": "^5.2.0"
},
"dependencies": {}
}
I also want to override some antD styles using SCSS. and it's converting all the classes with funny names even though they are not scss modules. It's extracting out a single file with all of my classes renamed. I was expecting only scss modules classes to be renamed.

NPM package component gives an error if reexported in another library

I have a component library and one of our components uses react-toggle library. When I try to use our component in another app I get the error Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. I am using rollup as a bundler, here's the configuration.
import path from 'path';
import babel from '#rollup/plugin-babel';
import resolve from '#rollup/plugin-node-resolve';
import commonjs from '#rollup/plugin-commonjs';
import image from '#rollup/plugin-image';
import filesize from 'rollup-plugin-filesize';
import localResolve from 'rollup-plugin-local-resolve';
import { terser } from 'rollup-plugin-terser';
import copy from 'rollup-plugin-copy';
import pkg from './package.json';
const SOURCE_DIR = path.resolve(__dirname, 'src');
const INPUT_FILE_PATH = `${SOURCE_DIR}/index.ts`;
const OUTPUT_NAME = 'InPlayerUI';
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
const GLOBALS = {
react: 'React',
'react-dom': 'ReactDOM',
'styled-components': 'styled-components',
};
const PLUGINS = [
image(),
resolve({
mainFields: ['module', 'main', 'jsnext:main', 'browser'],
extensions,
}),
commonjs({ include: ['node_modules/**'] }),
babel({
include: ['src/**/*'],
exclude: 'node_modules/**',
babelHelpers: 'bundled',
extensions,
}),
localResolve(),
terser(),
filesize(),
copy({
targets: [{ src: './index.d.ts', dest: 'dist' }],
}),
];
const EXTERNAL = ['react', 'react-dom', 'styled-components'];
const OUTPUT_DATA = [
{
file: pkg.browser,
format: 'umd',
},
{
file: pkg.main,
format: 'cjs',
},
{
file: pkg.module,
format: 'es',
},
];
const config = OUTPUT_DATA.map(({ file, format }) => ({
input: INPUT_FILE_PATH,
output: {
file,
format,
name: OUTPUT_NAME,
globals: GLOBALS,
},
external: EXTERNAL,
plugins: PLUGINS,
}));
export default config;
and the package.json
{
"name": "#inplayer-org/inplayer-ui",
"sideEffects": false,
"version": "2.0.4",
"author": "InPlayer",
"description": "InPlayer React UI Components",
"main": "dist/inplayer-ui.cjs.js",
"module": "dist/inplayer-ui.esm.js",
"browser": "dist/inplayer-ui.umd.js",
"jsnext:main": "dist/inplayer-ui.esm.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/inplayer-org/inplayer-ui"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/inplayer-org/inplayer-ui/issues"
},
"homepage": "https://github.com/inplayer-org/inplayer-ui#readme",
"scripts": {
"start": "yarn run storybook",
"storybook": "start-storybook -p 3001",
"build:storybook": "build-storybook -c .storybook -o docs",
"clean:dist": "rimraf ./dist",
"build": "yarn run clean:dist && npx rollup -c",
"lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
"lint:watch": "esw -w src/**",
"prepublishOnly": "yarn build",
"lint:style": "stylelint -- \"./src/**/*.js\""
},
"dependencies": {
"react-toggle": "^4.1.1"
},
"peerDependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1",
"styled-components": "^5.1.1"
},
"devDependencies": {
"#babel/cli": "^7.10.5",
"#babel/core": "^7.10.5",
"#babel/plugin-proposal-class-properties": "^7.10.4",
"#babel/plugin-proposal-private-methods": "^7.10.4",
"#babel/plugin-transform-classes": "^7.10.4",
"#babel/preset-env": "^7.10.4",
"#babel/preset-react": "^7.10.4",
"#babel/preset-typescript": "^7.10.4",
"#rollup/plugin-babel": "^5.1.0",
"#rollup/plugin-commonjs": "^14.0.0",
"#rollup/plugin-image": "^2.0.5",
"#rollup/plugin-node-resolve": "^8.4.0",
"#storybook/addon-docs": "^5.3.19",
"#storybook/addon-info": "^5.3.19",
"#storybook/addon-knobs": "^5.3.19",
"#storybook/react": "^5.3.19",
"#types/dompurify": "^2.0.2",
"#types/lodash": "^4.14.157",
"#types/react": "^16.9.43",
"#types/react-dates": "^17.1.13",
"#types/react-dom": "^16.9.8",
"#types/react-toggle": "^4.0.2",
"#types/styled-components": "^5.1.1",
"#typescript-eslint/eslint-plugin": "3.7.0",
"#typescript-eslint/parser": "3.7.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"dompurify": "^2.0.12",
"eslint": "^7.5.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-react-app": "^5.2.1",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.8",
"eslint-watch": "^7.0.0",
"html-react-parser": "^0.13.0",
"lodash-es": "^4.17.15",
"moment": "^2.27.0",
"polished": "^3.6.5",
"prettier": "^2.0.5",
"rc-progress": "^3.0.0",
"react": "^16.13.1",
"react-addons-shallow-compare": "^15.6.2",
"react-dates": "^21.8.0",
"react-dom": "^16.13.1",
"react-icons": "^3.10.0",
"react-paginate": "^6.3.2",
"rimraf": "^3.0.2",
"rollup-plugin-copy": "^3.3.0",
"rollup-plugin-filesize": "^9.0.2",
"rollup-plugin-local-resolve": "^1.0.7",
"rollup-plugin-terser": "^6.1.0",
"styled-components": "^5.1.1",
"styled-components-modifiers": "^1.2.5",
"styled-tools": "^1.7.2",
"stylelint": "^13.6.1",
"stylelint-config-standard": "^20.0.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-processor-styled-components": "^1.10.0",
"typescript": "^3.9.7"
}
}
This is the component
import React, { ChangeEvent } from 'react';
import styled from 'styled-components';
import Toggle from 'react-toggle';
import SwitchWrapper from './SwitchWrapper';
import Label from '../Label';
type SwitchProps = {
/**
* Whether the switch is checked or not
*/
checked: boolean;
/**
* Disable switch
*/
disabled?: boolean;
/**
* Id
*/
id: string;
/**
* Switch label
*/
label: string;
/**
* Function executed when the switch value changes
*/
onChange: (checked: boolean) => void;
};
const MarginLeftLabel = styled(Label)`
margin-right: 0.5rem;
`;
const Switch = ({ id, checked, label, disabled = false, onChange }: SwitchProps) => {
const onToggleChange = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target) {
onChange(e.target.checked);
}
};
return (
<SwitchWrapper>
<MarginLeftLabel disabled={disabled} htmlFor={id}>
{label}
</MarginLeftLabel>
<Toggle
id={id}
disabled={disabled}
checked={checked}
onChange={onToggleChange}
icons={false}
/>
</SwitchWrapper>
);
};
export default Switch;
I have seen some suggestions that the import could be wrong but I've made sure it isn't and if I use react-toggle directly in another app it works.
Note: I've tried using different npm packages and reexport components from them, it works fine, so I suppose it has something to do with react-toggle itself.

watch changes for incremental build using webpack and gulp for angular 5 app - AOT

In order to compile my angular app AOT, I'm using webpack and gulp.
I noticed that the watch step of webpack is not working so well, sometimes work and sometimes not, and when it work the files are not being updated on the site.
Please see the code bellow and tell me if there is anything I can do with minimum changes? or should I have to write something new?
packages.json
{
"name": "my-app",
"version": "1.2.0",
"scripts": {
"start": "gulp build:dev",
"test": "gulp test",
"build": "gulp build",
"postinstall": "typings install"
},
"engines": {
"node": "6.10.3",
"npm": "4.0.5"
},
"license": "LicenseRef-LICENSE",
"private": true,
"repository": {
"url": "git+ssh://gitolite#my-app"
},
"dependencies": {
"#angular/animations": "5.0.2",
"#angular/common": "5.0.2",
"#angular/compiler": "5.0.2",
"#angular/compiler-cli": "5.0.2",
"#angular/core": "5.0.2",
"#angular/forms": "5.0.2",
"#angular/http": "5.0.2",
"#angular/platform-browser": "5.0.2",
"#angular/platform-browser-dynamic": "5.0.2",
"#angular/platform-server": "5.0.2",
"#angular/router": "5.0.2",
"#ngx-translate/core": "8.0.0",
"#ngx-translate/http-loader": "2.0.0",
"#types/file-saver": "1.3.0",
"#types/jasmine": "2.8.2",
"angular2-infinite-scroll": "0.3.4",
"core-js": "2.4.1",
"file-saver": "1.3.3",
"jasmine": "2.8.0",
"jstz": "1.0.9",
"moment": "2.18.1",
"moment-timezone": "0.5.13",
"ngx-bootstrap": "2.0.0-beta.8",
"reflect-metadata": "0.1.10",
"rxjs": "5.5.2",
"xlsx": "0.11.7",
"zone.js": "0.8.5"
},
"devDependencies": {
"#ngtools/webpack": "1.8.0",
"autoprefixer": "6.7.6",
"bootstrap-sass": "3.3.7",
"custom-tslint-formatters": "2.1.1",
"del": "2.2.2",
"enhanced-resolve": "3.3.0",
"gulp": "3.9.1",
"gulp-add-src": "0.2.0",
"gulp-cache-bust": "1.1.0",
"gulp-exec": "2.1.3",
"gulp-htmlmin": "3.0.0",
"gulp-if": "2.0.2",
"gulp-ignore": "2.0.2",
"gulp-imagemin": "3.1.1",
"gulp-jsonminify": "1.0.0",
"gulp-postcss": "6.3.0",
"gulp-preprocess": "2.0.0",
"gulp-sass": "3.1.0",
"gulp-sourcemaps": "2.4.1",
"gulp-svg-sprite": "1.3.6",
"gulp-tslint": "7.1.0",
"gulp-util": "3.0.8",
"jasmine-core": "2.8.0",
"json-loader": "0.5.4",
"karma": "1.5.0",
"karma-chrome-launcher": "2.0.0",
"karma-ie-launcher": "1.0.0",
"karma-jasmine": "1.1.0",
"karma-mocha-reporter": "2.2.2",
"karma-sourcemap-loader": "0.3.7",
"karma-typescript": "3.0.8",
"karma-typescript-es6-transform": "1.0.2",
"karma-webpack": "2.0.6",
"postcss-loader": "1.3.3",
"postcss-scss": "0.4.1",
"precss": "1.4.0",
"raw-loader": "0.5.1",
"run-sequence": "1.2.2",
"sass-loader": "6.0.6",
"ts-loader": "2.0.1",
"tslint": "5.8.0",
"typescript": "2.4.2",
"webpack": "2.2.1"
}
}
gulp.js - the main tasks
var gulp = require('gulp'),
addsrc = require('gulp-add-src'),
config = require('./gulp.config.js'),
del = require('del'),
tslint = require('gulp-tslint'),
gulpif = require('gulp-if'),
preprocess = require('gulp-preprocess'),
htmlmin = require('gulp-htmlmin'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
runSequence = require('run-sequence'),
webpack = require('webpack'),
webpackConfig = config.webpack,
webpackCompiler = webpack(webpackConfig),
karmaServer = require('karma').Server,
cachebust = require('gulp-cache-bust'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer'),
imagemin = require('gulp-imagemin'),
svgSprite = require('gulp-svg-sprite'),
gulpIgnore = require('gulp-ignore'),
jsonminify = require('gulp-jsonminify'),
exec = require('child_process').exec;
gulp.task('build:dev', function (callback) {
runSequence(
'clean',
'copy:assets',
['html:index', 'sass:styles', 'tslint', 'typescript:dev'],
['watch'],
callback
)
});
gulp.task("typescript:dev", function(callback) {
var initialBuild = true;
webpackCompiler.watch(null, function(err, stats) {
if(err)
{
throw new gutil.PluginError("typescript:dev", err);
}
if (stats.hasErrors()) {
console.log(stats.toString("errors-only"));
}
if (initialBuild)
{
initialBuild = false;
// notify gulp that the initial task is done (now watching for changes)
callback();
}
else
{
console.log("typescript updated");
}
});
});
webpack.config.js
var webpackConfig = {
entry: {
'polyfills': './my-app/polyfills.ts',
'vendor': './my-app/vendor.ts',
'main': './my-app/main.ts'
},
output: {
path: __dirname + '/../dist',
filename: "[name].bundle.js"
},
resolve: {
extensions: ['.js', '.ts', '.json', '.html', '.scss'],
enforceExtension: false
},
module: {
rules: [
{ test: /\.ts$/, loaders: ['#ngtools/webpack'] },
{ test: /\.html$/, loader: "raw-loader", options: { exclude: /\.async\.html$/} },
{
test: /\.scss$/,
use:[
{loader:"raw-loader"},
{loader:"postcss-loader", options:{syntax:"postcss-scss", plugins: postcssConfig}},
{loader:"sass-loader", options:{outputStyle:"expanded"}}
]
}
],
noParse: [/angular2\/bundles\/.+/]
},
plugins: [
new AotPlugin({tsConfigPath: 'my-app/tsconfig.json', entryModule: __dirname + '/../my-app/my-app/app.module#AppModule', debug: true}),
new webpack.optimize.CommonsChunkPlugin({name: ['main', 'vendor', 'polyfills']}),
new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/, "doesnotexists")
]
};
when I run npm start I expect that webpack will be watch any changes in ts files and rebuild only those that changed.
Again thank you

Resources