Related
When I change the TS file, Webpack doesn't stop refreshing the page.
Console says: #ebpack 5.66.0 compiled successfully
I've googled this and tried different plugins, but they didn't work.
The mild refresh plugin just stopping the refresh and excluding JS files from ts-loader doesn't work at all.
The related issue in git didn't give the result as well.
webpack.config.json:
const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const HTMLInlineCSSWebpackPlugin = require("html-inline-css-webpack-plugin").default;
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
const htmlWebpackPlugin = new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html",
inlineSource: '.(js|css)$',
inject: 'body',
});
module.exports = {
entry: ['./src/index.tsx', './src/main.css'],
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
fallback: {
"path": require.resolve("path-browserify"),
"os": require.resolve("os-browserify/browser"),
"url": require.resolve("url"),
"tty": require.resolve("tty-browserify"),
"minimatch": require.resolve("minimatch"),
"process": require.resolve("process")
},
},
module: {
rules: [{
test: /\.tsx?$/,
exclude: [/node_modules/, /\.js$/, /\.d\.ts$/, /dist/],
loader: 'ts-loader',
options: {
configFile: 'tsconfig.json',
}
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader"
]
}
],
},
output: {
filename: 'bundle.js',
publicPath: '',
},
plugins: [
new webpack.ProvidePlugin({
process: 'process',
}),
new MiniCssExtractPlugin({
filename: "main.css",
chunkFilename: "mainc.css"
}),
htmlWebpackPlugin,
new HTMLInlineCSSWebpackPlugin(),
new InlineChunkHtmlPlugin(HtmlWebPackPlugin, [/bundle/]),
]
};
package.json:
{
"name": "browser",
"version": "0.0.0",
"scripts": {
"build": "webpack --mode development",
"start": "webpack serve --mode development --port 3000"
},
"devDependencies": {
"#types/chrome": "^0.0.163",
"#types/jquery": "^3.5.10",
"#types/node": "^16.11.7",
"#types/react": "^17.0.34",
"#types/react-dom": "^17.0.11",
"#types/vscode": "^1.62.0",
"#types/vscode-webview": "^1.57.0",
"css-loader": "^6.5.1",
"html-inline-css-webpack-plugin": "^1.11.1",
"html-webpack-plugin": "^5.5.0",
"mini-css-extract-plugin": "^2.4.6",
"react-dev-utils": "^12.0.0",
"ts-loader": "^9.2.6",
"typescript": "^4.5.4",
"webpack": "^5.66.0",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.7.3"
},
"dependencies": {
"ace-builds": "^1.4.13",
"axios": "^0.24.0",
"bootstrap": "^5.1.3",
"jquery": "^3.6.0",
"minimatch": "^5.0.1",
"mobx": "^6.3.6",
"mobx-react": "^7.2.1",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"react": "^17.0.2",
"react-ace": "^9.5.0",
"react-bootstrap": "^2.0.2",
"react-dom": "^17.0.2",
"redoc": "^2.0.0-rc.66",
"styled-components": "^5.3.5",
"tty-browserify": "0.0.1",
"url": "^0.11.0",
"uuid": "^8.3.2"
}
}
You better change InlineChunkHtmlPlugin tests from /bundle/ to /runtime/.
Replace
new InlineChunkHtmlPlugin(HtmlWebPackPlugin, [/bundle/])
With
new InlineChunkHtmlPlugin(HtmlWebPackPlugin, [/runtime~.+[.]tsx/])
OR
new InlineChunkHtmlPlugin(HtmlWebPackPlugin, [/runtime/])
I already tried to configure various different optimization methods, but my react-admin bundle size stays huge, at 860KB.
What can I do about it? Is it normal? What can be a possible cause? I will post links with my webpack configs in a minute.
I don't think there's any clever way to do code-splitting for now. I have implemented few resources and they should always be used kind of together.
Link to my common webpack config:
https://pastebin.com/t6uMWiJ6
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
main: './src/components/index.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'static/js/[name].[contenthash:8].js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
options: {
cacheDirectory: true,
cacheCompression: false,
babelrc: true
}
},
{ test: /\.json$/, loader: 'json-loader' },
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
exclude: [/\.(js|jsx)$/, /.html$/, /.css$/, /.json$/],
loader: 'file-loader',
options: {
name: 'static/media/[name].[contenthash:8].[ext]'
}
}
]
},
resolve: {
unsafeCache: true,
extensions: ['.js', '.jsx', '.json', '.css'],
alias: {
actions: path.resolve(__dirname, './src/actions'),
reducers: path.resolve(__dirname, './src/reducers'),
components: path.resolve(__dirname, './src/components'),
lib: path.resolve(__dirname, './src/components/_lib'),
styles: path.resolve(__dirname, './src/styles'),
config: path.resolve(__dirname, './src/config')
}
},
plugins: [
new HtmlWebpackPlugin({
template: './src/public/index.html',
favicon: './src/public/favicon.ico'
}),
new webpack.PrefetchPlugin('react'),
new webpack.PrefetchPlugin('react-dom')
],
optimization: {
usedExports: true
}
};
Here are my dependencies
{
"dependencies": {
"#babel/runtime": "^7.9.2",
"#material-ui/core": "^4.9.13",
"#material-ui/icons": "^4.9.1",
"#material-ui/pickers": "next",
"connected-react-router": "^6.8.0",
"final-form": "^4.19.1",
"jwt-decode": "^2.2.0",
"moment": "^2.25.3",
"prop-types": "^15.7.2",
"ra-core": "^3.5.0",
"ra-data-simple-rest": "^3.2.2",
"react": "^16.12.0",
"react-admin": "^3.1.1",
"react-dom": "^16.12.0",
"react-final-form": "^6.4.0",
"react-redux": "^7.2.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"redux": "^4.0.5",
"redux-saga": "^1.1.3"
},
"devDependencies": {
"#babel/core": "^7.9.6",
"#babel/plugin-syntax-dynamic-import": "^7.8.3",
"#babel/plugin-transform-runtime": "^7.9.0",
"#babel/preset-env": "^7.9.5",
"#babel/preset-react": "^7.9.4",
"babel-loader": "^8.1.0",
"css-loader": "^3.5.2",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^4.3.0",
"style-loader": "^1.2.1",
"webpack": "next",
"webpack-bundle-analyzer": "^3.7.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0",
"webpack-manifest-plugin": "^2.2.0",
"webpack-merge": "^4.2.2"
},
"peerDependencies": {
"history": "^4.10.1",
"immutable": "^4.0.0-rc.12",
"seamless-immutable": "^73.1.4"
},
"sideEffects": [
"*.css"
]
}
Tree shaking is probably what you need to look at. See https://webpack.js.org/guides/tree-shaking/
Note, as they say above, the way you import your modules in your source code is lso important here.
In essence though, it should enable webpack to just bundle the parts of npm packages that are needed.
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'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];
};
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!