Related
I'm trying to Unit test my React component which imports another component that contains .png file. Because of this image, my test suits are failing to run.
I tried all the possible solutions with the below configuration, still no luck.
Please suggest, this is my project configuration.
This is my jest.config.json
{
"testRegex": "((\\.|/*.)(spec))\\.js?$"
}
My package.json
{
"name": "Application name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --config ./webpack.config.js --mode development",
"test": "jest"
},
"jest": {
"moduleNameMapper": {
".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "identity-obj-proxy"
}
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.8.7",
"#babel/polyfill": "^7.10.1",
"#babel/preset-env": "^7.10.2",
"#babel/preset-react": "^7.8.3",
"axios-mock-adapter": "^1.18.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"css-loader": "^3.5.3",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^2.5.0",
"file-loader": "^6.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^26.0.1",
"prettier": "^2.0.5",
"react-hot-loader": "^4.12.19",
"redux-mock-store": "^1.5.4",
"style-loader": "^1.2.1",
"url-loader": "^4.1.0",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
},
"dependencies": {
"#material-ui/core": "^4.10.2",
"#material-ui/icons": "^4.9.1",
"#material-ui/lab": "^4.0.0-alpha.56",
"axios": "^0.19.2",
"core-js": "^3.6.5",
"d3-sankey-diagram": "^0.7.3",
"husky": "^4.2.5",
"prop-types": "^15.7.2",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-google-charts": "^3.0.15",
"react-intl": "^4.6.3",
"react-redux": "^7.2.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-test-renderer": "^16.13.1",
"redux": "^4.0.5",
"redux-saga": "^1.1.3",
"regenerator-runtime": "^0.13.5"
}
}
My Webpack.config.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: ['./src/index.js', '#babel/polyfill'],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.css$/i,
exclude: /node_modules/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
},
},
],
},
{
test: /\.(jpe?g|gif|png|svg)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
},
},
],
},
{
test: /\.(gif|png|jpe?g)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/images/',
},
},
],
},
],
// loaders: [{ test: /\.jsx?$/, loader: 'babel' }],
},
devServer: {
historyApiFallback: true,
},
resolve: {
extensions: ['*', '.js', '.jsx'],
},
output: {
path: path.join(__dirname, '/dist'),
filename: 'bundle.js',
publicPath: '/',
},
plugins: [new webpack.HotModuleReplacementPlugin()],
devServer: {
contentBase: './dist',
hot: true,
},
};
My .babelrc file
{
"presets": ["#babel/preset-env", "#babel/preset-react"]
}
Finally my test file:
import React from 'react';
import Enzyme, { shallow, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import MyPackage from '../Components/index';
Enzyme.configure({ adapter: new Adapter() });
describe('Some name', () => {
it('This should be loaded', () => {
const wrapper = shallow(<MyPackage />);
const x= wrapper.find('#selector').debug();
expect(x.prop('length')).toBe(1);
});
});
I tried adding mocks/fileMock.js with
export default '';
and mocks/styleMocks.js
module.exports = {};
still I see this error -
● Test suite failed to run
D:\ReactStuff\folder\myproject\src\assets\images\mylogo.png:1
�PNG
SyntaxError: Invalid or unexpected token
1 | import React from 'react';
> 2 | import { HeaderLogo} from '../assets/images/mylogo.png';
| ^
3 |
4 | const Header = () => {
5 | return (
What am I missing here. Please suggest
I wanna to use GoGO template in React, but i have this problem.
Uncaught Error: Module parse failed: Unexpected token (29:12)
You may need an appropriate loader to handle this file type.
|
| var render = function render() {
> var css = import('./assets/css/sass/themes/gogo.' + color + '.scss').then(function (x) {
| var MainApp = require('./App').default;
|
at eval (index.js:1)
at Object../src/index.js (main.f444d441.js:6169)
at __webpack_require__ (main.f444d441.js:724)
at fn (main.f444d441.js:101)
at eval (webpack:///multi_(:3005/webpack)-dev-server/client?:5:18)
at Object.0 (main.f444d441.js:6180)
at __webpack_require__ (main.f444d441.js:724)
at main.f444d441.js:791
at main.f444d441.js:794
I tried different approuch but I can't solved this problem.
This is a link to source code page.
https://themeforest.net/item/gogo-react-bootstrap-4-admin-dashboard/22544383/comments?page=5
webpack.config.js
'use strict';
/**
* Webpack Config
*/
const path = require('path');
const fs = require('fs');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// Webpack uses `publicPath` to determine where the app is being served from.
// In development, we always serve from the root. This makes config easier.
const publicPath = '/';
// Make sure any symlinks in the project folder are resolved:
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
// plugins
const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
// the path(s) that should be cleaned
let pathsToClean = [
'dist',
'build'
]
// the clean options to use
let cleanOptions = {
root: __dirname,
verbose: false, // Write logs to console.
dry: false
}
module.exports = {
entry: ["babel-polyfill", "react-hot-loader/patch", "./src/index.js"],
output: {
// The build folder.
path: resolveApp('dist'),
// Generated JS file names (with nested folders).
// There will be one main bundle, and one file per asynchronous chunk.
// We don't currently advertise code splitting but Webpack supports it.
filename: 'assets/js/[name].[hash:8].js',
chunkFilename: 'assets/js/[name].[hash:8].chunk.js',
// We inferred the "public path" (such as / or /my-project) from homepage.
publicPath: publicPath,
hotUpdateChunkFilename: 'hot/hot-update.js',
hotUpdateMainFilename: 'hot/hot-update.json'
},
devServer: {
contentBase: './src/index.js',
compress: true,
port: 3005, // port number
historyApiFallback: true,
quiet: true
},
// resolve alias (Absolute paths)
resolve: {
alias: {
Components: path.resolve(__dirname, 'src/components/'),
Containers: path.resolve(__dirname, 'src/containers/'),
Assets: path.resolve(__dirname, 'src/assets/'),
Util: path.resolve(__dirname, 'src/util/'),
Routes: path.resolve(__dirname, 'src/routes/'),
Constants: path.resolve(__dirname, 'src/constants/'),
Redux: path.resolve(__dirname, 'src/redux/'),
Data: path.resolve(__dirname, 'src/data/')
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.html$/,
use: [
{
loader: "html-loader",
options: { minimize: true }
}
]
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
// Scss compiler
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader",
"style-loader",
// "postcss-loader"
]
},
// {
// test: /\.scss$/,
// use: ExtractTextPlugin.extract({
// use: [{
// loader: "css-loader"
// }, {
// loader: "sass-loader"
// }],
// fallback: "style-loader"
// })
// }
// {
// test: /\.scss$/,
// use: [
// 'style-loader',
// 'css-loader',
// 'postcss-loader',
// 'sass-loader',
// 'postcss-loader'
// {
// loader: 'sass-resources-loader',
// options: {
// // Provide path to the file with resources
// resources: 'src/assets/css/sass/themes/gogo.light.purple.scss',
//
// // Or array of paths
// // resources: ['./path/to/vars.scss', './path/to/mixins.scss']
// },
// },
// ],
// },
]
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
compress: false,
ecma: 6,
mangle: true
},
sourceMap: true
}),
new OptimizeCSSAssetsPlugin({})
]
},
performance: {
hints: process.env.NODE_ENV === 'production' ? "warning" : false
},
plugins: [
new CopyWebpackPlugin([
{from:'src/assets/img',to:'assets/img'},{from:'src/assets/fonts',to:'assets/fonts'}
]),
new FriendlyErrorsWebpackPlugin(),
new CleanWebpackPlugin(pathsToClean, cleanOptions),
new HtmlWebPackPlugin({
template: "./public/index.html",
filename: "./index.html",
favicon: './public/favicon.ico'
}),
new MiniCssExtractPlugin({
filename: "assets/css/[name].[hash:8].css"
})
]
};
package.json
{
"name": "gogo-react",
"version": "2.0.2",
"description": "Gogo - React Bootstrap 4 Admin Dashboard Template",
"scripts": {
"start": "webpack-dev-server --mode development --hot --progress --open",
"build": "webpack --mode production"
},
"keywords": [
"reactjs"
],
"author": "Colored Strategies",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.4",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^4.5.2",
"css-loader": "^2.0.0",
"eslint": "^4.19.1",
"eslint-config-react-app": "^2.1.0",
"eslint-plugin-flowtype": "^2.47.1",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.8.2",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.11",
"friendly-errors-webpack-plugin": "^1.7.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.5.0",
"node-sass": "^4.8.3",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-hot-loader": "^4.1.3",
"sass-loader": "^7.1.0",
"uglifyjs-webpack-plugin": "^1.2.5",
"url-loader": "^1.0.1",
"webpack": "^4.27.1",
"webpack-bundle-analyzer": "^2.11.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10"
},
"dependencies": {
"#date-io/moment": "0.0.2",
"availity-reactstrap-validation": "^2.0.4",
"axios": "^0.18.0",
"chart.js": "^2.7.2",
"chartjs-plugin-datalabels": "^0.3.0",
"classnames": "2.2.6",
"draft-js": "^0.10.5",
"fine-uploader": "^5.16.2",
"firebase": "^5.3.0",
"formik": "^1.5.4",
"install": "^0.12.2",
"jalali-moment": "^3.3.1",
"jwt-decode": "^2.2.0",
"material-ui": "^0.20.2",
"material-ui-persian-date-picker-utils": "^0.1.2",
"material-ui-pickers": "^2.0.4",
"moment": "^2.22.2",
"npm": "^6.5.0",
"postcss-loader": "^3.0.0",
"rc-slider": "^8.6.1",
"rc-switch": "^1.6.0",
"react": "^16.4.1",
"react-autosuggest": "^9.3.4",
"react-big-calendar": "^0.19.2",
"react-block-ui": "^1.1.3",
"react-chartjs-2": "^2.7.4",
"react-circular-progressbar": "^1.0.0",
"react-contextmenu": "^2.9.4",
"react-datepicker": "^1.5.0",
"react-dom": "^16.4.1",
"react-fine-uploader": "^1.1.0",
"react-headroom": "^2.2.4",
"react-intl": "2.4.0",
"react-lines-ellipsis": "^0.13.2",
"react-loadable": "5.4.0",
"react-mousetrap": "^0.2.0",
"react-perfect-scrollbar": "^1.1.1",
"react-quill": "^1.3.1",
"react-rater": "^5.0.3",
"react-redux": "5.0.7",
"react-router-dom": "^4.2.2",
"react-scroll-to-component": "^1.0.2",
"react-select": "^2.0.0-beta.7",
"react-sortablejs": "^1.3.6",
"react-table": "^6.8.6",
"react-tagsinput": "^3.19.0",
"react-transition-group": "^1.2.0",
"reactstrap": "^6.5.0",
"redux": "4.0.0",
"redux-saga": "^0.16.0",
"sass-resources-loader": "^2.0.0",
"sortablejs": "^1.6.1",
"style-loader": "^0.23.1",
"sweetalert2": "^8.8.7",
"video.js": "^7.3.0",
"yup": "^0.27.0"
}
}
Please help me, thanks in advance.
If you are using latest version of react then no need to set loader in webpack.config.js file.
You can directly do this,
npm install sass-loader
And you can start using your scss files in the project.
It is about files which start with a dot being hidden by his os and failing to copy them.
In project directory there should be a ”.babelrc” and ”.eslintrc” files and the problem occurs when ”.babelrc” file is missing. Maybe you should also check it when you have time.
I have been through many threads to solve this issue but unfortunately non of them is working.
I am trying to import react-share like this
import {
FacebookShareButton,
GooglePlusShareButton,
TwitterShareButton,
WhatsappShareButton,
FacebookIcon,
TwitterIcon,
WhatsappIcon
} from 'react-share';
"use strict";
require('./../../../assets/styles/components/thread.less');
//var reactShare = require('react-share');
var React = require('react');
var ReactDOM = require('react-dom');
var Fluxxor = require('fluxxor');
var _ = require("lodash");
var FluxMixin = Fluxxor.FluxMixin(React);
var StoreWatchMixin = Fluxxor.StoreWatchMixin;
But i am receiving the error of
syntaxerro: import declarations may only appear at top level of a module
I have installed babel and have performed all the suggestions given in threads but not been able to solve the issue
For the reference my webpack.config.js file looks like this:
var path = require("path");
var webpack = require("webpack");
module.exports = {
cache: true,
devtool: 'hidden-source-map',
entry: {
microaudio: "./reactFrontend/js/main",
notsupported: "./reactFrontend/js/notsupported",
sharerender: "./reactFrontend/js/shareRender",
privacyDeclaration: "./reactFrontend/js/privacyDeclaration",
legal: "./reactFrontend/js/legal"
},
output: {
path: path.join(__dirname, "dist"),
publicPath: "frontend/",
filename: "[name].js",
chunkFilename: "[chunkhash].js"
},
node: {
fs: "empty"
},
module: {
loaders: [{
test: /\.jsx$/,
loader: "jsx-loader?insertPragma=React.DOM&harmony"
}, {
test: /\.json/,
loader: "json-loader"
}, {
test: /\.less/,
loader: "style-loader!css-loader!autoprefixer-loader?{browsers:['last 3 versions', 'Android >= 4', 'safari >= 4']}!less-loader"
}, {
test: /\.tpl/,
loader: "ejs-loader"
}, {
test: /\.woff(\?\S*)?$/,
loader: "url-loader?prefix=/font&limit=1000&mimetype=application/font-woff"
}, {
test: /\.woff2(\?\S*)?$/,
loader: "url-loader?prefix=/font&limit=1000&mimetype=application/font-woff"
}, {
test: /\.ttf(\?\S*)?$/,
loader: "file-loader?prefix=/font"
}, {
test: /\.eot(\?\S*)?$/,
loader: "file-loader?prefix=/font"
}, {
test: /\.svg(\?\S*)?$/,
loader: "url-loader?limit=1000000&mimetype=image/svg+xml"
}, {
test: /\.png$/,
loader: "url-loader?limit=10000&mimetype=image/png"
}, {
test: /\.gif$/,
loader: "url-loader?limit=10000&mimetype=image/gif"
}, {
test: /\.jpg$/,
loader: "url-loader?limit=10000&mimetype=image/jpeg"
}]
},
plugins: [
//setup momentjs context to only include languages we do need!
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /de|en/)
],
resolve: {
extensions: ["", ".webpack.js", ".web.js", ".js", ".jsx"],
alias: {
av: __dirname + "/reactFrontend/js/vendors/aurora/aurora",
"ogg.js": __dirname + "/reactFrontend/js/vendors/aurora/ogg",
"vorbis.js": __dirname + "/reactFrontend/js/vendors/aurora/vorbis"
}
},
babel: {
presets: ['es2015', 'stage-0'],
plugins: ['transform-runtime']
}
};
and my package.json file looks like this
{
"name": "audiyoh-frontend",
"version": "1.0.0",
"main": "./src/js/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test-martin-local": "SET NODE_ENV=development&& SET NODE_APP_INSTANCE=martin&& gulp test-bs",
"test-robert-local": "SET NODE_ENV=development&& SET NODE_APP_INSTANCE=robert&& gulp test-bs",
"wds": "webpack-dev-server --https --inline --hot --color --history-api-fallback"
},
"author": "atroo GbR",
"contributors": [
{
"name": "Martin Foerster",
"email": "martin#atroo.de"
},
{
"name": "Robert Krüger",
"email": "robert#atroo.de"
}
],
"license": "UNLICENSED",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^8.0.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"blanket": "^1.1.6",
"bootstrap-webpack": "0.0.3",
"chai": "^3.3.0",
"coveralls": "^2.11.2",
"css-loader": "^0.7.0",
"ejs-loader": "^0.1.0",
"file-loader": "^0.8.1",
"glob": "^4.3.5",
"gulp": "^3.8.6",
"gulp-debug": "^2.1.2",
"gulp-mocha": "^2.0.0",
"gulp-notify": "^2.2.0",
"gulp-plumber": "^1.0.1",
"gulp-rimraf": "^0.2.0",
"gulp-spawn-mocha": "^2.0.1",
"gulp-util": "^3.0.0",
"i18next-resource-store-loader": "0.0.2",
"imports-loader": "^0.6.5",
"json-loader": "^0.5.1",
"jsx-loader": "^0.12.2",
"less": "^2.2.0",
"less-loader": "^2.0.0",
"mocha": "^2.1.0",
"mocha-lcov-reporter": "^0.0.1",
"node-notifier": "^4.4.0",
"run-sequence": "^1.1.5",
"selenium-webdriver": "^2.47.0",
"sha1": "^1.1.1",
"socket.io": "^1.3.7",
"style-loader": "^0.8.3",
"url-loader": "^0.5.5",
"wasm-loader": "1.1.0",
"webpack": "^1.15.0",
"webpack-dev-server": "^1.14.1",
"webpack-merge": "^4.1.4",
"webpack-stream": "^3.0.1",
"worker-loader": "^0.5.7",
"yargs": "^3.26.0"
},
"dependencies": {
"autoprefixer-loader": "^3.2.0",
"av": "^0.4.9",
"backbone": "^1.1.2",
"backbone.wreqr": "^1.3.1",
"bootstrap": "^3.3.2",
"color": "^0.11.3",
"crypto-js": "^3.1.2-5",
"exports-loader": "^0.6.3",
"flux": "^2.0.0",
"fluxxor": "^1.7.3",
"get-user-media-promise": "^1.1.1",
"i18next-client": "^1.7.7",
"jquery": "^2.1.1",
"keymirror": "~0.1.0",
"less-to-json-loader": "^1.0.0",
"lodash": "^3.8.0",
"modernizr": "^3.3.1",
"modernizr-loader": "0.0.4",
"moment": "^2.9.0",
"node-uuid": "^1.4.2",
"normalize.css": "^3.0.2",
"object-assign": "^1.0.0",
"ogg.js": "^0.1.0",
"promise": "^6.1.0",
"react": "^0.14.5",
"react-bootstrap": "^0.21.2",
"react-dom": "^0.14.5",
"react-router": "^2.3.0",
"react-tools": "^0.12.2",
"scriptjs": "^2.5.8",
"socket.io-client": "^1.4.5",
"tunajs": "^0.4.5",
"velocity-animate": "^1.2.1",
"vorbis.js": "^0.1.1",
"web-audio-daw": "^2.3.1"
}
}
i created a .babelrc file as well (manually in the root where webpack.config.js is)
{
"presets": ["es2015", "stage-0"],
"plugins": ["transform-runtime"],
}
I am new in ReactJs so i am not having a good grasp on the requirements of such. Please help! Thanks
jsx-loader has been deprecated for at least 3 years.
You'll want to actually use babel-loader for JSX files if you need imports and other ES6 syntax implemented in the last three years to work.
I do not have access to the build server, I can only modify the files. So I can't add any flags to the grunt command. The build server seems to simply run "grunt". I have tried all sorts of configurations without success, suggested here and other sources.
From my understanding webpack should by default build a production build but perhaps it was introduced in later versions of webpack only or not supported by grunt-webpack?
Gruntfile.js
const path = require('path');
const BUILD_DIR = path.resolve(__dirname, 'build/');
const APP_DIR = path.resolve(__dirname, 'src/');
module.exports = function config(grunt) {
grunt.option("p"); // attempt to force a -p flag on webpack, doesn't work
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
webpack: {
reactcatalog: {
entry: ['core-js/fn/promise', 'core-js/fn/map', 'formdata-polyfill', 'whatwg-fetch', `${APP_DIR}/index.js`],
output: {
path: BUILD_DIR,
filename: 'react-catalog.js',
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
loaders: [{
test: /\.jsx?$/,
include: APP_DIR,
loader: ['babel-loader', 'eslint-loader'],
},
{
test: /\.css$/,
include: APP_DIR,
loader: 'style-loader!css-loader',
},
{
test: /\.scss$/,
include: APP_DIR,
loaders: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.svg$/,
loader: 'babel-loader!react-svg-loader',
}],
},
stats: {
colors: true,
},
progress: false,
failOnError: false,
},
},
});
grunt.loadNpmTasks('grunt-webpack');
grunt.registerTask('default', ['webpack']);
};
package.json:
{
"name": "react-catalog",
"version": "0.1.0",
"description": "ES based React catalog",
"private": true,
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-proto-to-assign": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2017-node7": "^0.5.2",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-runtime": "^6.26.0",
"breakpoint-sass": "^2.7.1",
"core-js": "^2.5.5",
"css-loader": "^1.0.0",
"formdata-polyfill": "^3.0.10",
"grunt-webpack": "^3.1.1",
"loaders.css": "^0.1.2",
"node-sass": "^4.9.3",
"npm-install": "0.0.1",
"prop-types": "^15.6.1",
"react": "^16.3.0",
"react-device-detect": "^1.3.4",
"react-dom": "^16.3.0",
"react-image-gallery": "^0.8.8",
"react-image-lightbox": "^4.6.0",
"react-infinite-scroller": "^1.1.4",
"react-intl-universal": "^1.10.1",
"react-md-spinner": "^0.2.5",
"react-move": "^2.6.0",
"react-redux": "^5.0.6",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-scroll": "^1.7.9",
"react-skylight": "^0.5.1",
"react-spinners": "^0.2.5",
"react-svg": "^2.2.18",
"react-svg-loader": "^2.1.0",
"react-svg-spinner": "^0.2.0",
"react-tabs": "^2.2.2",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0",
"run": "^1.4.0",
"sass-loader": "^7.0.1",
"sassimple": "^1.3.8",
"style-loader": "^0.20.3",
"susy": "^3.0.5",
"webpack": "^3.11.0",
"whatwg-fetch": "^2.0.4"
},
"devDependencies": {
"babel-eslint": "8.0.1",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-loader": "^2.0.0",
"eslint-plugin-flowtype": "^2.49.3",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.8.2",
"webpack-livereload-plugin": "^1.2.0"
},
"scripts": {
"webpack": "webpack", // does not help to add a -p flag here as it doesn't seem to use this
"webpack:watch": "webpack --watch"
}
}
I have tried all sorts of things without any success.
plugins: [
new webpack.DefinePlugin({
process: {
env: {
NODE_ENV: 'production'
}
}
})
]
becomes:
https://user-images.githubusercontent.com/893783/44646081-34498c00-a9da-11e8-8bd1-66c70b8ba9f5.png
Finally I figured out the solution myself!
const path = require('path');
++ const webpack = require('webpack');
const BUILD_DIR = path.resolve(__dirname, 'build/');
const APP_DIR = path.resolve(__dirname, 'src/');
module.exports = function config(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
webpack: {
reactcatalog: {
// ...
plugins: [
new webpack.DefinePlugin({
process: {
env: {
NODE_ENV: '"production"'
}
}
}),
new webpack.optimize.UglifyJsPlugin()
]
},
},
});
};
I'm trying to use ASP.NET Core 2 with Webpack 4 and React and I would love hot reloading. Problem is; when I try to make a change to one of the files it comes back with this error in Chrome:
:8100/dist/__webpack_hmr Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING.
My package.json:
{
"name": "ui",
"private": true,
"version": "0.1.0",
"license": "UNLICENSED",
"description": "Application",
"devDependencies": {
"#types/history": "4.6.0",
"#types/jquery": "3.3.1",
"#types/jsonwebtoken": "^7.2.6",
"#types/lodash": "4.14.105",
"#types/moment": "2.13.0",
"#types/query-string": "^5.1.0",
"#types/react": "^16.0.40",
"#types/react-dates": "16.0.5",
"#types/react-dom": "^15.5.1",
"#types/react-redux": "^4.4.45",
"#types/react-router": "4.0.12",
"#types/react-router-dom": "4.0.5",
"#types/react-router-redux": "5.0.3",
"#types/webpack": "2.2.15",
"#types/webpack-env": "1.13.0",
"airbnb-prop-types": "2.8.1",
"aspnet-prerendering": "3.0.1",
"aspnet-webpack": "2.0.1",
"aspnet-webpack-react": "3.0.0",
"awesome-typescript-loader": "3.2.1",
"bootstrap": "4.0.0",
"css-loader": "^0.28.11",
"domain-task": "3.0.3",
"event-source-polyfill": "0.0.9",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "1.1.11",
"glob": "^7.1.2",
"history": "4.6.3",
"install": "0.10.4",
"jquery": "3.2.1",
"jquery-mask-plugin": "1.14.15",
"jsonwebtoken": "^8.2.0",
"lodash": "4.17.5",
"moment": "2.21.0",
"muicss": "0.9.38",
"myriad-font": "0.0.2",
"node-noop": "1.0.0",
"node-sass": "^4.7.2",
"numbro": "2.0.5",
"path": "0.12.7",
"popper.js": "1.14.1",
"postcss-cssnext": "^3.1.0",
"postcss-loader": "2.1.1",
"prop-types": "15.6.1",
"query-string": "^6.0.0",
"react": "^16.2.0",
"react-addons-css-transition-group": "15.6.2",
"react-cookie": "^2.1.4",
"react-dom": "^16.2.0",
"react-moment": "0.7.0",
"react-moment-proptypes": "1.5.0",
"react-redux": "^5.0.7",
"react-router-dom": "4.1.1",
"react-router-redux": "^5.0.0-alpha.9",
"redux": "3.7.1",
"redux-thunk": "2.2.0",
"rxjs": "5.5.7",
"sass-loader": "^6.0.7",
"sfcookies": "^1.0.2",
"source-map-loader": "0.2.3",
"style-loader": "^0.18.2",
"tslint": "^5.9.1",
"tslint-react": "^3.5.1",
"typescript": "^2.7.2",
"url-loader": "1.0.1",
"webpack": "^4.2.0",
"webpack-cli": "^2.0.13",
"webpack-hot-middleware": "^2.21.2",
"webpack-merge": "4.1.2"
},
"scripts": {
"compile-vendor": "webpack --config webpack.config.vendor.js",
"compile-client": "webpack --config webpack.config.js"
},
"dependencies": {
"#types/react-hot-loader": "^3.0.6",
"react-hot-loader": "^3.1.1"
}
}
And my webpack.config.js:
"use strict";
const path = require('path');
const webpack = require('webpack');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const merge = require('webpack-merge');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const glob = require('glob');
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
// Configuration in common to both client-side and server-side bundles
const sharedConfig = () => ({
mode: !(env && env.prod) ? 'development' : 'production',
stats: { modules: false },
resolve: { extensions: ['.js', '.jsx', '.ts', '.tsx'] },
output: {
filename: '[name].js',
publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
},
module: {
rules: [
{
test: /\.tsx?$/,
include: /ClientApp/,
use: 'awesome-typescript-loader?silent=false'
},
{
test: /\.(png|jpg|jpeg|gif|svg)$/,
loader: "file-loader",
options: {
limit: 50000,
name: "./img/[name].[ext]"
}
},
{
// Match woff2 in addition to patterns like .woff?v=1.1.1.
test: /\.(woff|woff2|ttf)(\?v=\d+\.\d+\.\d+)?$/,
loader: "file-loader",
options: {
limit: 50000,
name: "./fonts/[name].[ext]"
}
}
]
},
performance: {
hints: false
},
devtool: 'cheap-module-source-map',
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.tsx'].concat(glob.sync('./ClientApp/img/**/*.svg'))
},
module: {
rules: [
{
test: /\.(scss|css)$/,
loader: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader",
options: {
importLoaders: 1
}
},
"postcss-loader"
]
}),
exclude: /node_modules/
}
]
},
output: { path: path.join(__dirname, clientBundleOutputDir) },
plugins: [
new ExtractTextPlugin("site.css"),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
}),
new webpack.NamedModulesPlugin()
]
});
return [clientBundleConfig];
};