Seems like a truly stupid question that must have an answer somewhere, but I've searched for hours to no avail. I'm new to ReactJS and building with Webpack, build configs in general. I'm using Webpack to link and bundle my entire project, including ReactJS. It works great, but I cannot figure out any way to get the bundle to come out un-minified so that I can debug issues when they arise.
Here is my Webpack config:
var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, 'public/js');
var APP_DIR = path.resolve(__dirname, 'build-source/js');
var config = {
entry: APP_DIR + '\\main.js',
output: {
path: BUILD_DIR,
filename: 'build.js' // want this output file to end un-minified
},
module: {
loaders: [
{
test: /\.jsx?/,
include: APP_DIR,
loader: 'babel'
}
]
}
};
module.exports = config;
I run the bundling execution with either npm run dev or npm run build which call upon the following from my package.json:
{
/* blah blah */,
"scripts": {
"start": "node ./bin/www",
"dev": "webpack -d --watch",
"build": "webpack -p"
},
"dependencies": {
"babel-core": "^6.16.0",
"babel-loader": "^6.2.5",
"babel-preset-react": "^6.16.0",
"body-parser": "~1.15.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
"helmet": "^3.1.0",
"morgan": "~1.7.0",
"mysql": "^2.11.1",
"querystring": "^0.2.0",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"request": "^2.75.0",
"serve-favicon": "~2.3.0",
"webpack": "^1.13.2"
}
}
What do I need to change to get un-minified JavaScript bundles out of my Webpack execution?
Why don't simply use:
module: {
// ....
},
optimization: {
minimize: false
},
It is a late answer but maybe helps someone else.
When you set mode: 'development' you will get a non minified bundle.
Webpack is using terser plugin by default for javascript minification in production mode even if you don't use it explicitly.
Also for debugging devtool option is a must.
As an example :
const config = {
...
mode: development,
devtool: 'source-map',
...
};
When you use the -p flag for webpack's cli, you are telling webpack to use the UglifyJSPlugin (behind the scenes)
So instead, I would have a separate build task that runs webpack without the -p flag and instead passes the following in your config instead.
var webpack = require('webpack');
module.exports = {
plugins: [
new webpack.optimize.UglifyJsPlugin({
options: {
compress: {drop_debugger: false}
}
})
]
};
Additionally, you can see that I've passed a custom option to the UglifyJsPlugin (which just corresponds to UglifyJs's compression options).
You should add to your webpack.build.js file
devtool: 'inline-source-map',
Related
What I want to do
I have a React Typescript project and I want to setup a debug configuration in Rider, which fulfills the following criteria:
a dev server is started with hot reloading, so when I change files, the application gets updated automatically
a javascript debugger gets attached to the running application, so I can set breakpoints in the jsx files inside of Rider (not in Chrome DevTools) and the application actually stops at the breakpoint
I prefer to use webpack directly and not indirectly through create-react-app
What's working
I currently run my application on the webpack dev server with webpack serve for development purposes. The dev server is running and I can debug the typescript code in Chrome DevTools successfully as you can see here.
The problem
As mentioned above, now I want to attach a debugger from inside Rider, so I can set breakpoints directly in my IDE - and that's where I failed.
What I've tried
In the Jetbrains documentation for debugging a webpack application (https://www.jetbrains.com/help/rider/Using_Webpack.html#debug_application_that_uses_webpack) I was told that the debugging should work the same as for React applications that were setup with create-react-app. So I followed the instructions here: https://blog.jetbrains.com/webstorm/2017/01/debugging-react-apps/?_ga=2.129883279.2614435.1634130690-1852059688.1626293073.
I ran yarn start from within the run configuration in debug mode. This executed webpack serve as defined in my package.json.
The page was available at http://localhost:9000 and I got the following output in the process console:
/usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js run start --scripts-prepend-node-path=auto
Debugger listening on ws://127.0.0.1:42631/294d3b20-969f-486e-917e-22c6350d23e4
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
> applicationName#1.0.0 start
> webpack serve
Debugger listening on ws://127.0.0.1:33159/3b5cb2c1-674a-4d9c-888f-b3bdf6f3d3a6
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:9000/
[...]
However, if I ctrl+shift+click on the http://localhost:9000/ link from the console, I get the following error.
My client app folder is located inside of a sub folder of a C# project (SolutionName/AppliationName/ClientApp), which I use as a backend. Can this maybe cause the problem?
I'm kinda stuck here, so I'm happy for all help. :)
Below you will find further information about my system and the relevant files.
My environment
OS: Ubuntu 20.04.2
IDE: Rider 2021.2.2
versions of the dependencies are listed in the package.json below
Files
package.json
{
[...]
"scripts": {
"start": "webpack serve",
"watch": "webpack --watch",
"build": "tsc && NODE_ENV=production webpack",
"build-dev": "webpack"
},
"dependencies": {
"#types/react": "^17.0.21",
"#types/react-dom": "^17.0.9",
"#types/typescript": "^2.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"#babel/core": "^7.15.8",
"#babel/preset-env": "^7.15.8",
"#babel/preset-react": "^7.14.5",
"#babel/preset-typescript": "^7.15.0",
"#webpack-cli/generators": "^2.4.0",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0",
"webpack-dev-server": "^4.3.1",
"workbox-webpack-plugin": "^6.3.0",
"babel-loader": "^8.2.2",
"css-loader": "^6.4.0",
"file-loader": "^6.2.0",
"style-loader": "^3.3.0",
"ts-loader": "^9.2.6",
"html-webpack-plugin": "^5.3.2",
"mini-css-extract-plugin": "^2.4.2",
"prettier": "^2.4.1",
"typescript": "^4.4.3"
}
}
webpack.config.js
const path = require("path")
const HtmlWebpackPlugin = require('html-webpack-plugin')
let mode = "development";
if (process.env.NODE_ENV === "production") {
mode = "production";
}
module.exports = {
mode: mode,
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
cacheDirectory: true,
presets: [
["#babel/preset-env", { targets: { node: "8" } }],
"#babel/preset-typescript",
"#babel/preset-react"
]
}
}
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
]
},
plugins: [new HtmlWebpackPlugin({ template: './public/index.html' })],
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: [".tsx", ".ts", ".jsx", ".js", "..."],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
devServer: {
static: {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 9000,
open: true,
hot: true
},
// generate source maps to debug the initial source files
devtool: "source-map"
}
The reason for the problems was that chromium was installed with snap. This doesn't work, but if you install the chromium packages directly from the debian repository everything works perfectly.
More details here: https://rider-support.jetbrains.com/hc/en-us/community/posts/4409573673746-Javascript-Debugging-not-working-in-Rider
I have this > 5 years old Angular 1.5.8 project developed by someone else, using webpack 2.7.0. It currently fails building. The error seems to be encountered at the very first .css file, which happens to be angular-material.css:
[96] ./~/angular-material/angular-material.css 1.04 kB {0} [built] [failed] [1 error]
Further down that line I get two warnings:
WARNING in DedupePlugin: This plugin was removed from webpack. Remove it from your configuration.
WARNING in webpack: Using NoErrorsPlugin is deprecated.
Use NoEmitOnErrorsPlugin instead.
... and then a bunch of similar errors (more than 500 lines), of which I only present the first one:
ERROR in ./src/styles/main.less
Module build failed: ModuleBuildError: Module build failed: LoaderRunnerError: Module 'D:\sgn\www\_g\test\node_modules\less\index.js' is not a loader (must have normal or pitch function)
at loadLoader (D:\sgn\www\_g\test\node_modules\loader-runner\lib\loadLoader.js:43:20)
at iteratePitchingLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at iteratePitchingLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:165:10)
at D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:176:18
at loadLoader (D:\sgn\www\_g\test\node_modules\loader-runner\lib\loadLoader.js:47:3)
at iteratePitchingLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at iteratePitchingLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:165:10)
at D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:176:18
at loadLoader (D:\sgn\www\_g\test\node_modules\loader-runner\lib\loadLoader.js:47:3)
at iteratePitchingLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at runLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:365:2)
at NormalModule.doBuild (D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModule.js:179:3)
at NormalModule.build (D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModule.js:268:15)
at Compilation.buildModule (D:\sgn\www\_g\test\node_modules\webpack\lib\Compilation.js:146:10)
at D:\sgn\www\_g\test\node_modules\webpack\lib\Compilation.js:433:9
at D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModuleFactory.js:253:5
at D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModuleFactory.js:99:14
at D:\sgn\www\_g\test\node_modules\tapable\lib\Tapable.js:268:11
at NormalModuleFactory.<anonymous> (D:\sgn\www\_g\test\node_modules\webpack\lib\CompatibilityPlugin.
js:52:5)
at NormalModuleFactory.applyPluginsAsyncWaterfall (D:\sgn\www\_g\test\node_modules\tapable\lib\Tapab
le.js:272:13)
at D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModuleFactory.js:74:11
at D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModuleFactory.js:205:8
at processTicksAndRejections (internal/process/task_queues.js:79:11)
at D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModule.js:192:19
at D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:367:11
at D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:172:11
at loadLoader (D:\sgn\www\_g\test\node_modules\loader-runner\lib\loadLoader.js:43:11)
at iteratePitchingLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at iteratePitchingLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:165:10)
at D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:176:18
at loadLoader (D:\sgn\www\_g\test\node_modules\loader-runner\lib\loadLoader.js:47:3)
at iteratePitchingLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at iteratePitchingLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:165:10)
at D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:176:18
at loadLoader (D:\sgn\www\_g\test\node_modules\loader-runner\lib\loadLoader.js:47:3)
at iteratePitchingLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at runLoaders (D:\sgn\www\_g\test\node_modules\loader-runner\lib\LoaderRunner.js:365:2)
at NormalModule.doBuild (D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModule.js:179:3)
at NormalModule.build (D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModule.js:268:15)
at Compilation.buildModule (D:\sgn\www\_g\test\node_modules\webpack\lib\Compilation.js:146:10)
at D:\sgn\www\_g\test\node_modules\webpack\lib\Compilation.js:433:9
at D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModuleFactory.js:253:5
at D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModuleFactory.js:99:14
at D:\sgn\www\_g\test\node_modules\tapable\lib\Tapable.js:268:11
at NormalModuleFactory.<anonymous> (D:\sgn\www\_g\test\node_modules\webpack\lib\CompatibilityPlugin.
js:52:5)
at NormalModuleFactory.applyPluginsAsyncWaterfall (D:\sgn\www\_g\test\node_modules\tapable\lib\Tapab
le.js:272:13)
at D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModuleFactory.js:74:11
at D:\sgn\www\_g\test\node_modules\webpack\lib\NormalModuleFactory.js:205:8
at processTicksAndRejections (internal/process/task_queues.js:79:11)
# ./src/app/app.js 41:0-30
The first thing I tried was to remove all the ^ combinators from all dependencies in package.json, which looks like this:
{
"name": "***",
"version": "1.0.0",
"description": "***",
"main": "app.js",
"scripts": {
"build": "webpack --progress --profile",
"dev": "webpack-dev-server --inline --open --progress --colors --watch"
},
"author": "Dovydas Martusevicius",
"license": "MIT",
"dependencies": {
"ajv": "^4.11.2",
"angular": "1.5.8",
"angular-animate": "1.5.8",
"angular-aria": "1.5.8",
"angular-chart.js": "1.1.1",
"angular-chartjs": "0.0.5",
"angular-material": "^1.1.0",
"angular-material-data-table": "0.10.9",
"angular-messages": "1.5.8",
"angular-sanitize": "1.5.8",
"angular-ui-bootstrap": "2.4.0",
"angular-ui-router": "0.3.1",
"animate.css": "3.5.1",
"babel-polyfill": "6.13.0",
"less": "^3.9.0",
"moment": "2.17.1",
"normalize.css": "4.2.0"
},
"devDependencies": {
"autoprefixer-loader": "^3.2.0",
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015-native-modules": "^6.9.4",
"css-loader": "^0.24.0",
"extract-text-webpack-plugin": "^2.0.0-beta.3",
"file-loader": "^0.9.0",
"html-loader": "^0.4.3",
"html-webpack-plugin": "^2.22.0",
"less-loader": "^2.2.3",
"source-map-loader": "^0.1.5",
"style-loader": "^0.13.1",
"webpack": "^2.7.0",
"webpack-dev-server": "^1.15.0"
}
}
...and, frankly, I was expecting it to build when I made sure those exact versions of its dependencies are used. But the error persists.
The second thing I tried was to downgrade node. I attempted building it with 13.11.0 (initially), 12.18.3, 8.11.3 and 5.12.0.
I'm not great with webpack in general, but when it comes to v2.* I'm totally lost.
Here's the webpack config:
'use strict';
//Modules
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
//Environment
const env = process.env.npm_lifecycle_event;
var isTest = env === 'test' || env === 'test-watch';
var isProd = env === 'build';
module.exports = {
devtool: 'source-map',
entry: {
app: './src/app/app.js'
},
devServer: {
outputPath: path.join(__dirname, 'src'),
contentBase: "./src"
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: isProd ? '' : 'http://localhost:8080/',
filename: isProd ? 'js/[name].[hash].js' : 'js/[name].bundle.js',
chunkFilename: isProd ? 'js/[name].[hash].js' : 'js/[name].bundle.js'
},
resolve: {
// you can load named modules from any dirs you want.
// attempts to find them in the specified order.
modules: [
'./src/lib',
'node_modules'
]
},
module: {
loaders: [
//HTML Files
{
test: /\.html$/,
loader: 'html-loader'
},
//Transpile ES6 to ES5
{
test: /\.js$/,
include: path.join(__dirname, 'src'),
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: [
["es2015", {"module": false}]
]
}
},
//Extract Normal CSS
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('css-loader?sourceMap!autoprefixer')
},
//Bundle Less into CSS Code
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('css-loader?sourceMap!autoprefixer!less?sourceMap')
},
//Images
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/,
loader: 'file-loader'
}
]
},
plugins : (() => {
let plugins = [];
//Render Index.html, Extract CSS
plugins.push(
new HtmlWebpackPlugin({
template: './src/index.html',
inject: 'body'
}),
// Write out CSS bundle to its own file:
new ExtractTextPlugin({
filename: 'css/styles.css',
allChunks: true})
);
//If prod do extra stuff
if (isProd) {
plugins.push(
// Only emit files when there are no errors
new webpack.NoErrorsPlugin(),
// Dedupe modules in the output
new webpack.optimize.DedupePlugin(),
// Minimize JS
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false
},
sourceMap: true
})
/*new CopyWebpackPlugin([{
from: __dirname + '/src/public'
}])*/
)
}
return plugins;
})()
};
I've spent considerable time reading github issues related to webpack and its loaders but haven't come across anything that would hint me into the right direction.
Thanks for your time looking into this and any suggestions you might have.
If the issue is solely related to a particular module then you can do following things,
1 - Reinstall that particular module ( delete followed by install ).
2 - Try upgrading or downgrading the module version.
Considering that the project is 5 years old at this point, I guess changing the version might solve your issue.
I need a bit of help with initial setup of webpack to serve my app with hot reloading. I've followed this guide to set up React+Webpack with Typescript, but I'd like to know how I can go about setting it up so I can call "npm start" and have it compile and host the app, with hot reloading.
My webpack.config.js looks like the following:
module.exports = {
mode: "production",
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx"]
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader"
}
]
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: "pre",
test: /\.js$/,
loader: "source-map-loader"
}
]
},
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
"react": "React",
"react-dom": "ReactDOM"
}
};
And my package.json looks like this:
{
"name": "client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "test"
},
"author": "DMW",
"license": "ISC",
"devDependencies": {
"#types/react": "^16.9.15",
"#types/react-dom": "^16.9.4",
"source-map-loader": "^0.2.4",
"ts-loader": "^6.2.1",
"typescript": "^3.7.3",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
},
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
"keywords": []
}
I'd really appreciate it if someone could link me to something to get this working. I'm a bit intimidated by the search results I've found.
EDIT: I ended up using npx create-react-app app --template typescript instead, as detailed here: https://create-react-app.dev/docs/adding-typescript/
Welcome to the community.
Regarding the settings for webpack try adding this to your package.json
"scripts": {
"start": "webpack-dev-server --mode development --open --hot"
},
When you do npm start, start will be taken from this script and would run app as webpack. Also --hot will ensure that hot reload is true, i.e. reload on any changes that you do to the app automatically.
Be sure to change the mode to production when pushing the app to production so that you don't get all the errors and warnings in the production. Hope it helps !!
I am having a big issue with my react project with dotnet core 2.0 and webpack. I use dotnet run command in the terminal and shows some info like this. In the Chrome console, some information keeps producing, just like what is shown in the picture below. This information is produced by the webpack module in the react node_module directory and can someone point out how I can fix this problem? Thanks!
here are some information I can offer:
terminal information
chrome console output
The package.json file:
{ "name": "dotnetcore", "private": true, "version": "0.0.0", "homepage": "/app/canteen/employee", "devDependencies": {
"#types/history": "4.6.0",
"#types/react": "15.0.35",
"#types/react-dom": "15.5.1",
"#types/react-hot-loader": "3.0.3",
"#types/react-router": "4.0.12",
"#types/react-router-dom": "4.0.5",
"#types/webpack-env": "1.13.0",
"aspnet-webpack": "^2.0.1",
"aspnet-webpack-react": "^3.0.0",
"awesome-typescript-loader": "3.2.1",
"bootstrap": "3.3.7",
"css-loader": "0.28.4",
"event-source-polyfill": "0.0.9",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "0.11.2",
"isomorphic-fetch": "2.2.1",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"react": "15.6.1",
"react-dom": "15.6.1",
"react-hot-loader": "3.0.0-beta.7",
"react-router-dom": "4.1.1",
"style-loader": "0.18.2",
"typescript": "2.4.1",
"url-loader": "0.5.9",
"webpack": "2.5.1",
"webpack-hot-middleware": "2.18.2",
"babel-core": "^6.3.26",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"moment": "^2.18.1",
"react-datetime": "^2.10.1",
"react-mobile-datepicker": "^3.0.6",
"react-mobile-picker": "^0.1.10",
"react-redux": "^5.0.6",
"react-router": "^4.2.0",
"react-scripts": "1.0.13",
"react-time": "^4.3.0",
"redux": "^3.7.2" } }
The webpack.config.js file
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const bundleOutputDir = './wwwroot/dist';
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
return [{
stats: { modules: false },
// entry: { 'main': './ClientApp/index.js' },
entry: { 'main': './ClientApp/boot.tsx' },
resolve: { extensions: ['.js', '.jsx', '.ts', '.tsx'] },
output: {
path: path.join(__dirname, bundleOutputDir),
filename: '[name].js',
publicPath: 'dist/'
},
module: {
rules: [
{ test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' },
{ test: /\.css$/, use: isDevBuild ? ['style-loader', 'css-loader'] : ExtractTextPlugin.extract({ use: 'css-loader?minimize' }) },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
{ test: /\.js?$/, loader: 'babel-loader', exclude: /node_modules/,
query:
{
presets:['react','es2015']
}
},
]
},
plugins: [
new CheckerPlugin(),
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(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin()
// new webpack.optimize.UglifyJsPlugin(),
// new ExtractTextPlugin('site.css')
])
}];
};
I had the same problem and almost the same webpack setup (we're both using the dotnet core starting template).
I cannot explain what causes the constant reloading but I was able to resolve it by "cleaning" my build files before or on each run of dotnet run. It appears that dotnet run is running the basic webpack command once when it fires. This means your front end files get built again (in ClientApp/dist and wwwroot/dist). If you delete all these files before running dotnet run, then the problem goes away. (warning: don't delete the vendor.* files as the main webpack config file will not rebuild those. You need the webpack.config.vendor.js script for those and that does not get autorun when you run dotnet run).
You can automate this deleting/cleaning process with the clean-webpack-plugin. Here's a snippet of what my webpack.config.js looks like using that plugin:
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = (env) => {
const clientBundleOutputDir = './wwwroot/dist';
const serverBundleOutputDir = './ClientApp/dist';
const cleanOptions = {
options: {
exclude: ['vendor.js', 'vendor.css', 'vendor-manifest.json'],
verbose: true,
},
pathsToClean: [clientBundleOutputDir, serverBundleOutputDir],
};
//.....
const clientBundleConfig = {
// ... some webpack settings ...
plugins: [
//.... array of some plugins....,
new CleanWebpackPlugin(cleanOptions.pathsToClean, cleanOptions.options),
],
// ... some more webpack settings ...
}
// ....
return [clientBundleConfig];
}
One caveat with this approach - I have found using this technique suffers in that dotnet run will run through the webpack script (which deletes your files and rebuilds them) and fires up the kestrel server and browser to run your app. Kestrel kicks in and the page attempts to load before webpack finishes rebuilding your files so the first page you see in your browser see will complain that it can't find your app's JS files. So you have to wait a few seconds for webpack to finish and then reload the page. It's not ideal but at least the constant reloading is gone.
Instead of modifying Webpack to clean all files every time, you can just apply this solution when you spot that Webpack enters into this Hot Module Replacement (HMR) loop. I noticed that this happens when you rename files, causing the HMR mechanism gets confused. You can apply the solution from my answer here.
My solution to a constant rebuild was to 'rm -rf node_modules' and 'npm install' again.
I'm currently trying to use this library http://roylee0704.github.io/react-flexbox-grid/ with my react JS app.
I've currently got my webpack setup and I followed the instructions on flexbox-grid's Github.
However, every time I try to run my app, I get that I don't have an appropriate loader to handle this file type. I've already installed webpack css-loader as well so I'm not sure what else I could be missing.
webpack.config.js
var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, 'src/client/public');
var APP_DIR = path.resolve(__dirname, 'src/client/app');
var config = {
entry: APP_DIR + '/App.jsx',
output: {
path: BUILD_DIR,
filename: 'bundle.js'
},
module : {
loaders : [
{
test : /\.jsx?/,
include : APP_DIR,
loader : 'babel'
},
{
test: /\.css$/,
loader: 'style!css!postcss',
include: path.join(__dirname, 'node_modules'), // this also includes flexboxgrid
exclude: /flexboxgrid/, // so we are excluding it
}
]
}
};
module.exports = config;
Here is my package.json
{
"name": "PokerSiteMaterial",
"version": "1.0.0",
"description": "Poker Site",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack -d --watch",
"build": "webpack -p"
},
"author": "Kai Mou",
"license": "ISC",
"dependencies": {
"babel-core": "^6.9.1",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"react": "^15.1.0",
"react-dom": "^15.1.0",
"webpack": "^1.13.1"
},
"devDependencies": {
"css-loader": "^0.23.1"
}
}
Try adding this to your webpack config, in addition to your current css rule, as stated in the react-flexbox-grid README...
{
test: /\.css$/,
loader: 'style!css?modules',
include: /flexboxgrid/,
}
You only did part 1 of the process. You told your css loader, which uses postcss and is therefore incompatible with flexboxgrid, to ignore flexboxgrid, but you did not create a new loader for it.
Basically, flexboxgrid needs to be loaded with only the css loader. Since, you are using postcss, you need to tell your main css rule to ignore it and add the above rule to handle it