Getting 404 on angular application load - http-status-code-404

I have upgraded my angular application from version 12 to 14. I'm using custom Webpack. In MVC view I have added the main.js script. But on page load I'm getting 404 for all the HTML & CSS pages. I need to generate 2 output files main.js & main.bo.js. Based on the user role I'm loading corresponding MVC page. One view is for front end application where I'm registering main.js & another view is for back office where I'm registering main.bo.js.
When the application is loading I'm getting 404 for all the html pages & css.
Tried many options but not able to resolve the issue. Any help will be appreciated.
Error Details
I'm using custom webpack because I need 2 entry point main.js and main.bo.bundle.js. Based on the creds I'm registering either main.js or main.bundle.bo in my mvc application.
This is how I'm registering script from MVC view.
Scripts
Wepback.config.js
"use strict";
const path = require('path');
const webpack = reiuire('webpack');
const CssMinimizer = require('css-minimizer-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require("terser-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
mode: "development", // "production" | "development" | "none"
entry: {
//'polyfills': './angular/src/polyfills.ts',
'vendor': './angular/src/vendor.ts',
'app': './angular/src/main.ts',
'bo': './angular/src/main.bo.ts'
},
output: {
path: path.resolve(__dirname, '../dist'),
filename: '[name].bundle.js',
libraryTarget: 'umd',
clean: true
},
module: {
rules: [
{
test: /\.m?js$/,
use: {
loader: 'babel-loader',
options: {
plugins: ['#angular/compiler-cli/linker/babel'],
compact: false,
cacheDirectory: true,
}
}
},
{
test: /src\/.*\.js$/,
use: [
{
loader: 'babel-loader',
options: {
sourceMaps: false,
cacheDirectory: true,
cacheCompression: false
}
},
...(
[{ loader: 'source-map-loader' }]
)
],
exclude: [/(node_modules|bower_components)/]
},
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
onlyCompileBundledFiles: true
}
}
],
exclude: [/node_modules/, /test/]
},
{
test: /\.(html)$/,
use: 'html-loader'
},
{
test: /src\/app\/.*\.css$/,
use: [
'style-loader',
'css-loader'
]
},
]
},
resolve: {
extensions: ['.mjs', '.ts', '.js', '.css', '.html'],
fallback: {
crypto: "crypto-browserify",
http: "stream-http",
https: "https-browserify",
os: "os-browserify/browser",
path: "path-browserify",
stream: "stream-browserify",
process: "process/browser",
zlib: "browserify-zlib",
url: "url/",
},
},
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
devtool: 'source-map',
target: "web",
plugins: [
new webpack.ContextReplacementPlugin(
/\#angular(\\|\/)core(\\|\/)esm5/,
'./angular',
{}
),
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin(),
new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map',
exclude: ['vendor.ts']
})
],
optimization: {
minimize: false,
minimizer: [
new TerserPlugin({
exclude: /assets/,
extractComments: false
})
]
}
}
Package.json
"devDependencies": {
"#angular-builders/custom-webpack": "^14.0.0",
"#angular-builders/dev-server": "^7.3.1",
"#angular-devkit/build-angular": "^14.0.0",
"#angular/cli": "^14.0.0",
"#angular/compiler-cli": "^14.0.0",
"#babel/plugin-proposal-decorators": "^7.18.9",
"#ngtools/webpack": "11.0.7",
"#types/jasmine": "~4.0.0",
"#types/jest": "^27.4.1",
"#webpack-cli/serve": "^1.6.1",
"babel-loader": "^8.2.5",
"css-loader": "^5.2.7",
"css-minimizer-webpack-plugin": "^4.0.0",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^6.2.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^5.5.0",
"jasmine-core": "~4.1.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-html-detailed-reporter": "^1.1.20",
"karma-jasmine": "~5.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.4",
"lodash": "^4.17.21",
"mini-css-extract-plugin": "^2.6.1",
"phantomjs": "^1.9.19",
"raw-loader": "^4.0.2",
"style-loader": "^2.0.0",
"terser-webpack-plugin": "^5.3.3",
"to-string-loader": "^1.2.0",
"ts-loader": "^9.3.1",
"typescript": "~4.7.2",
"uglifyjs-webpack-plugin": "^1.1.2",
"url": "^0.11.0",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.9.3",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"#angular/animations": "^14.0.0",
"#angular/cdk": "^14.0.0",
"#angular/cli": "14.0.0",
"#angular/common": "^14.0.0",
"#angular/compiler": "^14.0.0",
"#angular/core": "^14.0.0",
"#angular/forms": "^14.0.0",
"#angular/material": "^14.0.0",
"#angular/platform-browser": "^14.0.0",
"#angular/platform-browser-dynamic": "^14.0.0",
"#angular/router": "^14.0.0",
"#babel/core": "^7.18.9",
"#babel/preset-env": "^7.18.9",
"#ng-idle/core": "^11.1.0",
"#ng-idle/keepalive": "^11.0.3",
"#types/node": "14.17.3",
"#types/webrtc": "^0.0.30",
"angular2-template-loader": "^0.6.2",
"assert": "^2.0.0",
"browserify-zlib": "^0.2.0",
"canvg": "^3.0.7",
"classlist.js": "^1.1.20150312",
"codelyzer": "^0.0.28",
"core-js": "^3.23.5",
"crypto-browserify": "^3.12.0",
"enhanced-resolve": "3.3.0",
"font-awesome": "^4.7.0",
"html2canvas": "1.0.0-alpha.9",
"https-browserify": "^1.0.0",
"ie-shim": "^0.1.0",
"jspdf": "^2.4.0",
"ng2-material-dropdown": "^0.11.0",
"ng2-pdf-viewer": "^3.0.8",
"ngx-bootstrap": "^6.2.0",
"ngx-toastr": "^14.2.1",
"node": "^18.5.0",
"node-fetch": "^2.6.1",
"oidc-client": "^1.10.1",
"os-browserify": "^0.3.0",
"pdfjs-dist": "^2.14.305",
"primeng": "^14.0.0-rc.1",
"rxjs": "~7.5.0",
"rxjs-compat": "^6.6.7",
"rxjs-tslint": "^0.1.8",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"tsconfig-paths-webpack-plugin": "^4.0.0",
"tslib": "^2.3.0",
"typescript-base64-arraybuffer": "^0.1.0",
"web-animations-js": "^2.3.1",
"yarn": "^1.22.17",
"zone.js": "^0.10.3"
},
"-vs-binding": {
"ProjectOpened": [
"test"
]
},
"browser": {
"zlib": false
}
TSConfig -
{
"compileOnSave": false,
"buildOnSave": false,
"compilerOptions": {
"baseUrl": "./",
// "outDir": "./dist",
// "forceConsistentCasingInFileNames": false,
"strict": false,
//"noImplicitOverride": true,
//"noPropertyAccessFromIndexSignature": true,
//"noImplicitReturns": false,
"noImplicitAny": false,
"strictPropertyInitialization": false,
//"noFallthroughCasesInSwitch": true,
"strictNullChecks": false,
"sourceMap": true,
"declaration": false,
//"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
//"importHelpers": true,
"target": "es5",
"module": "esnext",
"lib": [
"ES6",
"dom"
],
"paths" : {
"crypto": ["./node_modules/crypto-browserify"],
"stream": ["./node_modules/stream-browserify"],
"assert": ["./node_modules/assert"],
"http": ["./node_modules/stream-http"],
"https": ["./node_modules/https-browserify"],
"os": ["./node_modules/os-browserify"],
"zlib": ["./node_modules/browserify-zlib"]
},
},
"angularCompilerOptions": {
"compilationMode": "partial"
}
}
Index.html file from dist folder.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Webpack App</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1"><script defer src="vendor.bundle.js"></script><script defer src="app.bundle.js"></script><script defer src="bo.bundle.js"></script></head>
<body>
</body>
</html>

Related

How to use common dependencies between multiple modules in React micro frontend

Hey I am using react microfrontend in my react project with webpack module federation.
After changing folder structure as per microfrontend structure facing some difficulties to handle common dependencies of modules.
Getting Following Error:
ERROR in resolving fallback for shared module react
Module not found: Error: Can't resolve 'react' in '/Users/admin/Desktop/guru/project/microfrontend/modules/metronic/layout/components/subheader/components'
ERROR in resolving fallback for shared module react
Module not found: Error: Can't resolve 'react-router-dom' in '/Users/admin/Desktop/guru/project/microfrontend/modules/metronic/layout/components/subheader/components'
Here I am sharing my code structure
webpack
package.json
folder structure
Webpack:
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
require('dotenv').config({ path: '../.env' });
module.exports = {
// the output bundle won't be optimized for production but suitable for development
mode: 'development',
// the app entry point is /src/index.js
entry: path.resolve(__dirname, 'src', 'index.js'),
output: {
// the output of the webpack build will be in /dist directory
path: path.resolve(__dirname, 'dist'),
// the filename of the JS bundle will be bundle.js
filename: 'bundle.js',
publicPath: '/'
},
devServer: {
historyApiFallback: true,
},
resolve: {
extensions: ['', '.js', '.jsx'],
},
module: {
rules: [
{
// for any file with a suffix of js or jsx
test: /\.jsx?$/,
// ignore transpiling JavaScript from node_modules as it should be that state
exclude: /node_modules/,
// use the babel-loader for transpiling JavaScript to a suitable format
loader: 'babel-loader',
options: {
// attach the presets to the loader (most projects use .babelrc file instead)
presets: ["#babel/preset-env", "#babel/preset-react"]
}
},
{
// test: /\.s[ac]ss$/i,
test: /\.(sa|sc|c)ss$/,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
},
{
test: /\.(woff(2)?|ttf|eot|svg|png)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}
]
}
]
},
// add a custom index.html as the template
plugins: [
new ModuleFederationPlugin({
name: "app_container",
remotes: {
banners: "banners#http://localhost:3002/remoteEntry.js",
newDashboard: "newDashboard#http://localhost:3008/remoteEntry.js",
baggageService: "baggageService#http://localhost:3016/remoteEntry.js",
},
// shared: [ "react", "react-dom"]
shared: {
"react-router-dom": { singleton: true, eager: true, requiredVersion: "^5.1.2" },
"#manaflair/redux-batch":{ singleton: true, eager: true, requiredVersion: "1.0.0" },
"#reduxjs/toolkit":{ singleton: true, eager: true, requiredVersion: "1.3.6" },
"react-redux":{ singleton: true, eager: true, requiredVersion: "7.1.3" },
"redux":{ singleton: true, eager: true, requiredVersion: "4.0.5" },
"redux-logger":{ singleton: true, eager: true, requiredVersion: "^3.0.6" },
"redux-persist":{ singleton: true, eager: true, requiredVersion: "6.0.0" },
"redux-saga":{ singleton: true, eager: true, requiredVersion: "1.1.3" },
"react": { singleton: true, eager: true, requiredVersion: "^17.0.2" },
"#fortawesome/fontawesome-free": { singleton: true, eager: true, requiredVersion: "5.13.0" },
"react-dom": { singleton: true, eager: true, requiredVersion: "^17.0.2" },
"lodash": { singleton: true, eager: true, requiredVersion: "4.17.21" },
"lodash.debounce": { singleton: true, eager: true, requiredVersion: "^4.0.8" },
}
}),
new HtmlWebpackPlugin({
template: "./public/index.html"
}),
new webpack.DefinePlugin({
"process.env": JSON.stringify(process.env)
})
]
};
In our project have common utils and components that is being used in different micro frontend modules
how to handle that dependencies.
package.json:
{
"name": "microfrontend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --open",
"build": "webpack --config webpack.prod.config.js --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"#amcharts/amcharts3-react": "^3.0.0",
"#babel/core": "^7.17.5",
"#babel/preset-env": "^7.16.11",
"#babel/preset-react": "^7.16.7",
"#date-io/date-fns": "^1.3.11",
"#formatjs/intl-pluralrules": "1.3.5",
"#fortawesome/fontawesome-free": "^5.13.0",
"#manaflair/redux-batch": "1.0.0",
"#material-ui/core": "^4.10.2",
"#material-ui/icons": "4.9.1",
"#material-ui/pickers": "^3.3.10",
"#material-ui/styles": "4.9.14",
"#reduxjs/toolkit": "1.3.6",
"#tanem/svg-injector": "8.0.50",
"#wojtekmaj/react-daterange-picker": "^3.3.0",
"apexcharts": "3.24.0",
"axios": "0.21.2",
"axios-mock-adapter": "1.18.1",
"babel-loader": "^8.2.3",
"bootstrap": "4.5.0",
"bootstrap-daterangepicker": "^3.1.0",
"clipboard-copy": "3.1.0",
"clsx": "1.1.0",
"cp-cli": "2.0.0",
"css-mediaquery": "0.1.2",
"date-fns": "2.8.1",
"downshift": "3.4.2",
"fg-loadcss": "2.1.0",
"file-loader": "^6.2.0",
"formik": "2.1.4",
"highcharts": "^9.0.0",
"highcharts-react-official": "^3.0.0",
"html-react-parser": "^0.13.0",
"html-webpack-plugin": "^5.5.0",
"html2canvas": "^1.3.2",
"http-service": "file:../modules/http-service",
"i": "^0.3.7",
"json2mq": "0.2.0",
"jss-rtl": "^0.3.0",
"lodash": "4.17.21",
"lodash.debounce": "^4.0.8",
"material-picker-4.0": "npm:#material-ui/pickers#^4.0.0-alpha.12",
"material-ui-popup-state": "1.4.1",
"metronic": "file:../modules/metronic",
"npm": "^6.14.6",
"object-path": "0.11.8",
"perfect-scrollbar": "1.5.0",
"prop-types": "15.7.2",
"quill-emoji": "^0.1.7",
"react-beautiful-dnd": "^13.1.0",
"react-bootstrap": "1.0.1",
"react-bootstrap-daterangepicker": "^7.0.0",
"react-bootstrap-table-next": "4.0.2",
"react-bootstrap-table2-paginator": "2.1.2",
"react-copy-to-clipboard": "^5.0.2",
"react-data-table-component": "^6.9.3",
"react-datepicker": "2.16.0",
"react-draggable": "4.4.2",
"react-highcharts": "^16.1.0",
"react-hooks-helper": "^1.6.0",
"react-html-parser": "^2.0.2",
"react-image-crop": "^8.6.12",
"react-inlinesvg": "1.2.0",
"react-intl": "3.6.2",
"react-is": "16.13.1",
"react-pdf": "^5.7.0",
"react-perfect-scrollbar": "1.5.8",
"react-portal": "4.2.0",
"react-qr-reader": "^2.2.1",
"react-quill": "^1.3.5",
"react-redux": "7.1.3",
"react-router-dom": "5.1.2",
"react-router-last-location": "^2.0.1",
"react-rte": "^0.16.1",
"react-scripts": "3.2.0",
"react-select": "3.1.0",
"react-star-ratings": "^2.3.0",
"react-swipeable-views": "0.13.9",
"react-syntax-highlighter": "12.2.1",
"react-table-hoc-fixed-columns": "^2.3.4",
"react-toastify": "^6.0.6",
"react-window": "1.8.5",
"reactstrap": "^8.5.1",
"redux": "4.0.5",
"redux-logger": "^3.0.6",
"redux-persist": "6.0.0",
"redux-saga": "1.1.3",
"sass": "^1.49.9",
"sass-loader": "^12.6.0",
"socicon": "3.0.5",
"styled-components": "^5.1.1",
"sweetalert2": "^10.12.6",
"sweetalert2-react-content": "^3.2.2",
"common-gui-components": "file:../modules/common-gui-components",
"common-store": "file:../modules/common-store",
"common-utils": "file:../modules/common-utils",
"uuid": "^8.3.2",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4",
"yup": "0.29.0"
}
}
My folder structure:

Styled components: babel-plugin-styled-components not working

I've been trying to get the babel-plugin-styled-components plugin to work with my webpack/babelrc configuration but I have not been able to do so. I am using babel-loader and no matter what I try I can't get the plugin to be recognised.
I am using Typescript 4 and Webpack 4.
I've searched and tried a number of proposed solutions but none have worked. I even tried the typescript-styled-components-plugin solution (https://github.com/Igorbek/typescript-plugin-styled-components), but no matter what it seems that the plugin is not recognised and the settings do not work.
I can only imagine that it's an issue with my configuration. Webpack is still a bit of a mystery to me in general.
My webpack.common.js file looks like this:
module.exports = [
{
context,
cache: local,
devtool: 'inline-source-map',
mode: 'development',
resolve: {
symlinks: false,
alias: {
'app.veams$': `${context}/app.veams.tsx`,
env: envFile
},
extensions: ['.ts', '.tsx', '.js']
},
// Entry point for webpack
entry: {
app: `${context}/app.tsx`
},
// Output directory and filename
output: {
filename: 'scripts/[name].bundle.js',
chunkFilename: 'scripts/[name].chunk.js',
path: outputPath,
pathinfo: !local // Performance #2: Garbage Collection
},
// Tell webpack to run babel on every file it runs through
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
babelrc: true,
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
// Let's add babel presets ...
presets: [
'#babel/preset-react',
[
'#babel/preset-env',
{
targets: {
browsers: ['last 2 versions', 'ie >= 11']
}
}
]
],
// ... and plugins.
plugins: [
'#babel/plugin-proposal-function-bind',
// Stage 2
[
'#babel/plugin-proposal-decorators',
{
legacy: true
}
],
[
'#babel/plugin-proposal-class-properties',
{
loose: false
}
]
]
}
}
]
},
scriptRule(configContext),
styleRule(),
assetsRule()
]
},
plugins: [].concat(scriptPlugins(configContext), stylePlugins(configContext)),
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
},
// Turn off performance hints during development because we don't do any
// splitting or minification in interest of speed. These warnings become
// cumbersome.
performance: {
hints: false
},
optimization: {
minimizer: optimizerPlugins(),
removeAvailableModules: false, // Performance #1: Do not optimize so much in incremental builds
removeEmptyChunks: false, // Performance #1: Do not optimize so much in incremental builds
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
priority: 10,
enforce: true
}
} // Performance #1: Do not optimize so much in incremental builds
}
},
devServer: {
contentBase: outputPath,
compress: false,
port: 3000,
proxy: {
'/': 'http://localhost:2999'
},
overlay: {
warnings: true,
errors: true
}
}
}
];
The scriptRule file looks like this:
module.exports = function() {
return {
test: /\.tsx?$/,
use: [
{
loader: 'cache-loader'
},
{
loader: 'babel-loader',
options: {
babelrc: true,
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
// Let's add babel presets ...
presets: [
'#babel/preset-react',
[
'#babel/preset-env',
{
targets: {
browsers: ['last 2 versions', 'ie >= 11']
}
}
]
],
// ... and plugins.
plugins: [
'#babel/plugin-proposal-function-bind',
// Stage 2
[
'babel-plugin-styled-components',
{
displayName: true
}
],
[
'#babel/plugin-proposal-decorators',
{
legacy: true
}
],
[
'#babel/plugin-proposal-class-properties',
{
loose: false
}
]
]
}
},
{
loader: 'thread-loader',
options: {
// there should be 1 cpu for the fork-ts-checker-webpack-plugin
workers: require('os').cpus().length - 1
}
},
{
loader: 'ts-loader',
options: {
transpileOnly: true, // Performance #3 :: Limit amount of modules to transpile at a time per iteration
experimentalWatchApi: true,
happyPackMode: true // IMPORTANT! use happyPackMode mode to speed-up compilation and reduce errors
// reported to webpack
}
}
]
};
};
.babelrc looks like this:
{
"env": {
"client": {
"presets": [
[
"#babel/preset-env",
{
"targets": {
"browsers": ["last 2 versions", "ie >= 11"]
}
}
],
"#babel-preset-react"
],
"plugins": [
"#babel/plugin-proposal-function-bind",
[
"babel-plugin-styled-components",
{
"displayName": true
}
],
[
"#babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"#babel/plugin-proposal-class-properties",
{
"loose": false
}
]
]
},
"server": {
"presets": ["#babel/preset-env"],
"plugins": [
"#babel/plugin-proposal-function-bind",
"#babel/plugin-proposal-export-default-from",
"#babel/plugin-proposal-logical-assignment-operators",
[
"#babel/plugin-proposal-optional-chaining",
{
"loose": false
}
],
[
"#babel/plugin-proposal-pipeline-operator",
{
"proposal": "minimal"
}
],
[
"#babel/plugin-proposal-nullish-coalescing-operator",
{
"loose": false
}
],
"#babel/plugin-proposal-do-expressions",
[
"#babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"#babel/plugin-proposal-function-sent",
"#babel/plugin-proposal-export-namespace-from",
"#babel/plugin-proposal-numeric-separator",
"#babel/plugin-proposal-throw-expressions",
"#babel/plugin-syntax-dynamic-import",
"#babel/plugin-syntax-import-meta",
[
"#babel/plugin-proposal-class-properties",
{
"loose": false
}
],
"#babel/plugin-proposal-json-strings",
"#babel/plugin-transform-runtime"
]
}
}
}
And finally the package.json looks like this:
"dependencies": {
"#veams/core": "^1.0.0",
"#veams/helpers": "^1.2.8",
"#veams/http-service": "^1.0.2",
"c3": "0.7.20",
"carbon-components": "^9.66.3",
"carbon-components-react": "^6.74.1",
"carbon-icons": "^7.0.7",
"connected-react-router": "6.8.0",
"cors": "2.8.5",
"downshift": "3.1.5",
"express-http-proxy": "1.6.2",
"file-saver": "2.0.2",
"history": "4.7.2",
"html-to-react": "1.4.5",
"immutable": "4.0.0-rc.12",
"json5": "2.1.3",
"query-string": "6.13.7",
"react": "17.0.1",
"react-c3js": "0.1.20",
"react-d3-cloud": "0.7.0",
"react-dom": "17.0.1",
"react-excel-workbook": "0.0.4",
"react-redux": "7.2.2",
"react-router-config": "4.4.0-beta.6",
"react-router-dom": "5.2.0",
"redux": "4.0.5",
"redux-devtools-extension": "2.13.8",
"redux-immutable": "4.0.0",
"redux-immutable-state-invariant": "2.1.0",
"redux-observable": "1.2.0",
"reselect": "4.0.0",
"rxjs": "6.6.3",
"styled-components": "5.2.1",
"tslib": "2.0.3",
"xlsx": "0.16.8"
},
"devDependencies": {
"#babel/core": "^7.0.0",
"#babel/plugin-proposal-class-properties": "^7.0.0",
"#babel/plugin-proposal-decorators": "^7.0.0",
"#babel/plugin-proposal-do-expressions": "^7.0.0",
"#babel/plugin-proposal-export-default-from": "^7.0.0",
"#babel/plugin-proposal-export-namespace-from": "^7.0.0",
"#babel/plugin-proposal-function-bind": "^7.0.0",
"#babel/plugin-proposal-function-sent": "^7.0.0",
"#babel/plugin-proposal-json-strings": "^7.0.0",
"#babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
"#babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"#babel/plugin-proposal-numeric-separator": "^7.0.0",
"#babel/plugin-proposal-optional-chaining": "^7.0.0",
"#babel/plugin-proposal-pipeline-operator": "^7.0.0",
"#babel/plugin-proposal-throw-expressions": "^7.0.0",
"#babel/plugin-syntax-dynamic-import": "^7.0.0",
"#babel/plugin-syntax-import-meta": "^7.0.0",
"#babel/plugin-transform-runtime": "^7.0.0",
"#babel/preset-env": "^7.0.0",
"#babel/preset-react": "^7.0.0",
"#babel/register": "^7.0.0",
"#babel/runtime": "^7.0.0",
"#types/history": "^4.6.2",
"#types/jest": "^23.3.12",
"#types/node": "^10.12.18",
"#types/react": "16.9.56",
"#types/react-dom": "16.9.9",
"#types/react-redux": "7.1.11",
"#types/react-router": "4.4.3",
"#types/react-router-config": "1.0.7",
"#types/react-router-dom": "5.1.6",
"#types/redux-immutable-state-invariant": "2.1.1",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.4.2",
"babel-loader": "^8.0.5",
"babel-plugin-styled-components": "1.11.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.16.0",
"babel-preset-stage-1": "^6.24.1",
"babel-register": "^6.26.0",
"babel-runtime": "^6.26.0",
"body-parser": "^1.18.1",
"browser-sync": "^2.24.4",
"cache-loader": "^2.0.1",
"case-sensitive-paths-webpack-plugin": "^2.1.1",
"chalk": "^2.0.1",
"command-line-args": "^4.0.7",
"command-line-usage": "^4.0.2",
"compression-webpack-plugin": "^2.0.0",
"connect-browser-sync": "^2.1.0",
"copy-webpack-plugin": "^4.3.1",
"cross-env": "^5.0.5",
"css-loader": "^2.1.0",
"deep-extend": "^0.6.0",
"eslint": "^5.12.0",
"eslint-config-prettier": "^3.4.0",
"eslint-plugin-prettier": "^3.0.1",
"express": "^4.16.3",
"fork-ts-checker-webpack-plugin": "^0.5.2",
"globby": "^9.0.0",
"husky": "^1.0.0-rc.8",
"include-media": "^1.4.8",
"jshint-stylish": "^2.0.0",
"lint-staged": "^8.1.5",
"lodash": "^4.17.4",
"mini-css-extract-plugin": "^0.5.0",
"node-sass": "^4.7.2",
"node-sass-magic-importer": "^5.0.3",
"nodemon": "^1.14.0",
"npm-run-all": "^4.1.1",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"postcss": "^7.0.11",
"postcss-cssnext": "^3.1.0",
"postcss-loader": "^3.0.0",
"prettier": "^1.13.4",
"react-dev-utils": "^7.0.1",
"request": "^2.81.0",
"rimraf": "^2.6.2",
"sass-loader": "^7.0.2",
"style-loader": "^0.23.1",
"stylelint": "^9.2.0",
"stylelint-config-prettier": "^5.0.0",
"stylelint-prettier": "^1.0.6",
"thread-loader": "^2.1.1",
"ts-jest": "^23.10.5",
"ts-loader": "^5.3.3",
"tslint": "^5.12.0",
"tslint-config-airbnb": "^5.9.2",
"tslint-config-prettier": "^1.13.0",
"tslint-plugin-prettier": "^2.0.1",
"tslint-react": "^3.6.0",
"typescript": "4.0.5",
"uglifyjs-webpack-plugin": "^2.1.1",
"webpack": "^4.10.2",
"webpack-cli": "^3.0.1",
"webpack-dev-server": "^3.1.14",
"winston": "^2.3.1"
},
I didn't originally write this webpack config and have tried moving the order of the plugin etc. to no avail.
I hope someone can help...
Cheers!
It seems you may need to add "babel-plugin-macros" before it in your plugins array. I was trawling the web for ages trying to get babel-plugin-styled-components working for Twin in Create React App (which also uses Webpack). I was using CRACO to add babel plugins, but nothing I was doing was working.
I finally stumbled upon this absolutely perfect example repo twin.examples/webpack-styled-components-typescript which contained literally everything I wanted. Here is the .babelrc file it used:
{
"presets": [
[
"#babel/preset-react",
{ "runtime": "automatic" }
],
"#babel/preset-typescript"
],
"plugins": [
"babel-plugin-twin",
"babel-plugin-macros",
"babel-plugin-styled-components"
]
}
The plugins part was what I needed, so I just copied it across and everything worked perfectly.
To check it applied to situations without babel-plugin-twin, I removed it from the plugins list and tested my setup using the alternative method for using Twin (adding import "twin.macro" at the top of the file I was styling in). The setup worked, but not if I removed babel-plugins-macro, supporting my theory.
What seems odd is CRA already loads babel-plugins-macro from babel-preset-react-app. I think actually babel-plugins-macro needs to be specifically loaded just before babel-plugin-styled-components, as I tried swapping the order of just those two and it silently broke the styling.
Hope my findings help you or someone else out there!

React js babel transform and minification in asp.net core

I have a asp.net core 2.0 application and I am using react.js also. I have some jsx files in that.
I want to minify those jsx files and then use. For js & css minification,
I defined rules in bundleconfig.json but wiring rules for jsx throws errors.
Can anyone help me how I can minify jsx in asp.net core application.
Update
Below is my project structure
below is webpack.config file
const path = require("path");
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const WebpackShellPlugin = require('webpack-shell-plugin');
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
process.traceDeprecation = true;
module.exports = {
entry: {
home: "./wwwroot/js/v2/userdefined/home.page.js"
},
output: {
path: path.resolve(__dirname, "wwwroot/dist"),
filename: "[name].js",
publicPath: "/dist/"
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: false,
extractComments: 'all',
uglifyOptions: {
compress: true,
output: null
}
}),
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
safe: true,
discardComments: {
removeAll: true,
},
},
})
]
},
plugins: [
new webpack.ContextReplacementPlugin(/\.\/locale$/, 'empty-module', false, /jsx$/),
new webpack.LoaderOptionsPlugin({
options: {}
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
Popper: ['popper.js', 'default']
}),
new CompressionPlugin({
test: /\.(js|css)/
}),
new UglifyJsPlugin(),
new WebpackShellPlugin({
onBuildStart: ['echo "Starting postcss command"'],
onBuildEnd: ['postcss --dir wwwroot/dist wwwroot/dist/*.css']
})
],
resolve: {
modules: [
path.resolve('./node_modules')
]
},
module: {
rules: [{
test: /\.scss$/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
minimize: true,
sourceMap: true
}
},
{
loader: "sass-loader"
}
]
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: ["babel-loader", "eslint-loader"]
},
{
test: /\.(jpe?g|png|gif)$/i,
loader: "file-loader"
},
{
test: /\.(woff|ttf|otf|eot|woff2|svg)$/i,
loader: "file-loader"
}
]
}
};
below is Gruntfile.js
/// <binding AfterBuild='cleanup' />
module.exports = function(grunt) {
require("jit-grunt")(grunt);
grunt.initConfig({
clean: ["./Modules/*"],
copy: {
main: {
expand: true,
src: [
"../Modules/**/bin/Debug/**/**/*.*",
"../Modules/**/wwwroot/**",
],
dest: "./Modules/"
},
css: {
expand: true,
cwd: "../Modules/AwesomeCMSCore.Modules.Frontend/wwwroot/dist",
src: ["cmscore.css"],
dest: "./wwwroot/dist/"
},
js: {
expand: true,
cwd: "../Modules/AwesomeCMSCore.Modules.Frontend/wwwroot/dist",
src: ["*.js"],
dest: "./wwwroot/dist/"
},
static: {
expand: true,
cwd: "../Modules/AwesomeCMSCore.Modules.Frontend/wwwroot/dist",
src: ["**"],
dest: "./wwwroot/dist/"
}
},
watch: {
css: {
files: ["../Modules/**/wwwroot/dist/*.css"],
tasks: ["copy:css"],
options: {
reload: true,
spawn: false
}
},
js: {
files: ["../Modules/**/wwwroot/dist/*.js"],
tasks: ["copy:js"],
options: {
reload: true,
spawn: false
}
}
}
});
grunt.registerTask("default", ["watch"]);
grunt.registerTask("cleanup", [
"clean",
"copy:main",
"copy:static"
]);
};
below is my package.json
{
"name": "ProjV2",
"version": "1.0.0",
"main": "index.js",
"author": "JitendraPancholi",
"license": "",
"scripts": {
"prod": "webpack -p --mode=production --config webpack.prod.js",
"start": "webpack --mode=development --config webpack.dev.js",
"lint:js": "eslint \"wwwroot/js/react/src/**/*.{js,jsx}\" --color",
"lint:style": "stylelint \"wwwroot/css/**/*.scss\" --syntax scss"
},
"devDependencies": {
"babel-cli": "6.26.0",
"babel-core": "6.26.3",
"babel-eslint": "8.2.6",
"babel-loader": "7.1.5",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-es2015-destructuring": "6.23.0",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-preset-es2015": "6.24.1",
"babel-preset-react": "6.24.1",
"babel-preset-stage-0": "6.24.1",
"compression-webpack-plugin": "1.1.11",
"css-loader": "1.0.0",
"cssnano": "^4.1.7",
"empty-module": "^0.0.2",
"eslint": "^5.0.0",
"eslint-loader": "2.0.0",
"eslint-plugin-react": "7.10.0",
"file-loader": "1.1.11",
"grunt": "1.0.3",
"grunt-contrib-clean": "1.1.0",
"grunt-contrib-copy": "1.0.0",
"grunt-contrib-watch": "1.1.0",
"jit-grunt": "0.10.0",
"jshint": "2.9.5",
"jshint-loader": "0.8.4",
"mini-css-extract-plugin": "^0.4.4",
"node-sass": "^4.11.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"sass-loader": "7.0.3",
"style-loader": "0.21.0",
"stylelint": "9.3.0",
"stylelint-config-recommended": "2.1.0",
"stylelint-config-recommended-scss": "3.2.0",
"stylelint-config-standard": "18.2.0",
"stylelint-scss": "3.1.3",
"uglify-js": "^3.4.9",
"uglifyjs-webpack-plugin": "1.2.7",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-merge": "^4.2.1",
"webpack-shell-plugin": "^0.5.0"
},
"dependencies": {
"#aspnet/signalr": "^1.1.0",
"#tinymce/tinymce-react": "^2.2.5",
"axios": "^0.18.0",
"bootstrap": "^4.1.1",
"chart.js": "^2.7.2",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"moment": "^2.22.2",
"popper.js": "^1.14.1",
"prop-types": "^15.6.0",
"react": "^16.4.1",
"react-bootstrap-table": "^4.3.1",
"react-dom": "^16.4.1",
"react-select": "^1.2.1",
"react-values": "^0.2.4",
"reactstrap": "^6.3.0",
"toastr": "^2.1.4"
}
}
All my fils jsx files are as per below
You cant do that. React has to transform into js file in order to run in the browser
Normally you will need module bundle tool like webpack
You can view my full config here
Let me know if you need any more help
Update: Here is how I transform jsx into js
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: ["babel-loader", "eslint-loader"]
},

PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR ReferenceError: Can't find variable: Map

I have used "MVC ASP.NET Core with Angular" template.
I am trying to include phantomJS and run the tests, but i get the following errors:
ERROR in [at-loader] ..\\node_modules\zone.js\dist\zone.js.d.ts:122:11 TS2451: Cannot redeclare block-scoped variable 'Zone'.
ERROR in [at-loader] ..\\node_modules\zone.js\ dist\zone.js.d.ts:363:14 TS2300: Duplicate identifier 'HasTaskState'.
ERROR in [at-loader] ..\\node_modules\zone.js\ dist\zone.js.d.ts:372:14 TS2300: Duplicate identifier 'TaskType'.
ERROR in [at-loader] ..\\node_modules\zone.js\ dist\zone.js.d.ts:458:15 TS2451: Cannot redeclare block-scoped variable 'Zone'.
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR ReferenceError: Can't find variable: Map at ../wwwroot/dist/vendor.js:12460
Below are the node module version i have been using(package.json):
"dependencies": {
"#angular/animations": "4.1.2",
"#angular/common": "4.1.2",
"#angular/compiler": "4.1.2",
"#angular/core": "4.1.2",
"#angular/forms": "4.1.2",
"#angular/http": "4.1.2",
"#angular/platform-browser": "4.1.2",
"#angular/platform-browser-dynamic": "4.1.2",
"#angular/platform-server": "4.1.2",
"#angular/router": "4.1.2",
"#types/node": "7.0.18",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^2.0.5",
"aspnet-webpack": "^1.0.29",
"awesome-typescript-loader": "3.1.3",
"bootstrap": "3.3.7",
"css": "2.2.1",
"css-loader": "0.28.1",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.9",
"expose-loader": "0.7.3",
"extract-text-webpack-plugin": "2.1.0",
"file-loader": "0.11.1",
"html-loader": "0.4.5",
"isomorphic-fetch": "2.2.1",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"preboot": "4.5.2",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.10",
"rxjs": "5.4.0",
"style-loader": "0.17.0",
"to-string-loader": "1.1.5",
"typescript": "2.3.2",
"url-loader": "0.5.8",
"webpack": "2.5.1",
"webpack-hot-middleware": "2.18.0",
"webpack-merge": "4.1.0",
"zone.js": "0.8.10"
},
"devDependencies": {
"#types/chai": "3.5.2",
"#types/jasmine": "2.5.47",
"chai": "3.5.0",
"istanbul-instrumenter-loader": "^3.0.0",
"jasmine-core": "2.6.1",
"karma": "1.7.0",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.1.1",
"karma-cli": "1.0.1",
"karma-coverage-istanbul-reporter": "^1.3.0",
"karma-htmlfile-reporter": "^0.3.5",
"karma-jasmine": "1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.4",
"karma-webpack": "2.0.3",
"phantomjs-prebuilt": "^2.1.15"
}`
and the tsconfig.json is as follows:
`{
"compilerOptions": {
"moduleResolution": "node",
"target": "es5",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipDefaultLibCheck": true,
"lib": [ "es6", "dom" ],
"types": [ "node" ]
},
"exclude": [
"bin",
"node_modules"
],
"atom": { "rewriteTsconfig": false }
}`
and the webpack.config.js code is :
`const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
module.exports = (env) => {
// Configuration in common to both client-side and server-side bundles
const isDevBuild = !(env && env.prod);
const sharedConfig = {
stats: { modules: false },
context: __dirname,
resolve: {
extensions: ['.js', '.ts'],
modules: [path.join(__dirname, "node_modules")]
},
output: {
filename: '[name].js',
publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
},
module: {
rules: [
{ test: /\.ts$/, include: /ClientApp/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] },
{ test: /\.html$/, use: 'html-loader?minimize=false' },
{ test: /\.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
]
},
plugins: [new CheckerPlugin()]
};
// Configuration for client-side bundle suitable for running in browsers
const clientBundleOutputDir = '..//wwwroot/dist';
const clientBundleConfig = merge(sharedConfig, {
entry: { 'main-client': '..//ClientApp/boot-client.ts' },
output: { path: path.join(__dirname, clientBundleOutputDir) },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('..//wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin()
])
});
return [clientBundleConfig];
};
`
How can i solve the errors mentioned above? I have tried solutions mentioned in https://github.com/monounity/karma-typescript/issues/83. Nothing worked.
Any help would be appreciated!
Looking forward for some answer.
Thanks.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
Solution to include chrome headless:
included "puppeteer" in package.json under dev dependencies.
Configured in Karma.config.js:
const ChromiumRevision = require('puppeteer/package.json').puppeteer.chromium_revision;
const Downloader = require('puppeteer/utils/ChromiumDownloader');
const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision);
module.exports = function (config) {
config.set({ ...
browsers: ['ChromeHeadless'],
..
});
};
phantomJS and run the tests, but i get the following errors:
PhantomJS is old and doesn't support ES6 features like Map. You can try to get it to work with core-js but you are essentially trying to lift a dead tech to modern standards.
More
The replacement for phantomjs is chrome headless.

Unable to configure Jest in my React App

I'm just starting with tests right now, trying to set up the Jest with my project, but it has been painful.. I am trying to do the React App tutorial, with the Webpack Tutorial, and I'm facing if this error:
C:\Users\myuser\Desktop\myapp\__tests__\Link.test.js:2
import React from 'react';
^^^^^^
SyntaxError: Unexpected token import
at transformAndBuildScript (node_modules\jest-runtime\build\transform.js:320:12)
I'm using Node v7.5.0 and Webpack 2. I installed all the necessary dependencies and I also tried to sort with jest configuration, but it didn't sort my problem.
My package.json looks like this:
{
"name": "myapp",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"jest": {
"modulePaths": ["<rootDir>/src/"],
"moduleDirectories": ["node_modules"],
"transform": {
"^.+\\.jsx?$": "babel-jest"
},
"transformIgnorePatterns": [
"<rootDir>/(node_modules)/"
]
},
"scripts": {
"start": "webpack-dev-server --progress --watch",
"build": "webpack --progress",
"test": "jest --verbose"
},
"devDependencies": {
"babel-core": "^6.22.1",
"babel-eslint": "^7.1.1",
"babel-jest": "^18.0.0",
"babel-loader": "^6.2.10",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.0",
"babel-polyfill": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.26.1",
"eslint": "^3.15.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-import-resolver-webpack": "^0.8.1",
"eslint-loader": "^1.6.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jest": "^1.0.2",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.9.0",
"extract-text-webpack-plugin": "^1.0.1",
"html-webpack-plugin": "^2.28.0",
"jest": "^18.1.0",
"jest-cli": "^19.0.2",
"node-sass": "^4.5.0",
"react-hot-loader": "3.0.0-beta.6",
"react-test-renderer": "^15.4.2",
"sass-loader": "^5.0.1",
"style-loader": "^0.13.1",
"url-loader": "^0.5.8",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.3.0"
},
"dependencies": {
"chart.js": "^2.5.0",
"classnames": "^2.2.5",
"file-loader": "^0.11.1",
"flexboxgrid": "^6.3.1",
"google-map-react": "^0.22.3",
"intl": "^1.2.5",
"intl-locales-supported": "^1.0.0",
"lodash": "^4.17.4",
"material-ui": "^0.17.0",
"moment": "^2.17.1",
"node-schedule": "^1.2.1",
"normalize.css": "^5.0.0",
"re-base": "^2.6.0",
"react": "^15.4.2",
"react-chartjs-2": "^2.0.5",
"react-dom": "^15.4.2",
"react-flexbox-grid": "^0.10.2",
"react-router-dom": "^4.0.0",
"react-scrollbar": "^0.5.1",
"react-tap-event-plugin": "^2.0.1",
"webpack": "^2.2.1"
}
}
My .babelrc file looks like this:
{
"presets": [
["es2015", {"modules": false}],
"stage-2",
"react"
],
"plugins": [
"react-hot-loader/babel"
],
"env": {
"test": {
"plugins": ["transform-es2015-modules-commonjs"]
}
}
}
I also set the environment to test, but it didn't make any effect.
My Webpack file looks like this:
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const plugins = [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './src/index.html'),
inject: true,
favicon: path.resolve(__dirname, './src/images/favicon.ico'),
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('dev'),
},
}),
];
module.exports = {
devtool: 'cheap-eval-source-map',
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index.jsx',
],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'public'),
publicPath: '/',
},
context: path.resolve(__dirname, 'src'),
resolve: {
modules: [path.resolve(__dirname, './src'), path.resolve(__dirname, './node_modules')],
extensions: ['.js', '.jsx'],
},
devServer: {
hot: true,
port: 3000,
contentBase: path.resolve(__dirname, 'public'),
historyApiFallback: true,
publicPath: '/',
},
module: {
rules: [
{
test: /(\.js|\.jsx)$/,
enforce: 'pre',
exclude: /node_modules/,
use: {
loader: 'eslint-loader',
options: {
failOnWarning: false,
failOnError: false,
},
},
},
{
test: /(\.js|\.jsx)$/,
use: ['babel-loader'],
exclude: /node_modules/,
},
{
test: /(\.scss|\.css)$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: true,
},
},
{ loader: 'sass-loader' },
],
},
{
test: /\.(png|jpg|)$/,
use: ['url-loader?limit=200000'],
},
],
},
plugins: plugins,
};
Can someone help me with this issue? Thanks!

Resources