firebase with react and custom webpack throws export loader error - reactjs

i'm facing an issue with react with custom webpack config while I try to implement firebase
react version: 17+
webpack version: 5+
firebase: 9+
so when i try to import any function from firebase/messaging (also tried other packages from firebase like analytics, same issue happens) it throws an error about exports-loader module that is not installed.
then after installation it throws this error then:
ERROR in ./node_modules/whatwg-fetch/fetch.js (./node_modules/exports-loader/dist/cjs.js?self.fetch!./node_modules/whatwg-fetch/fetch.js)
Module build failed (from ./node_modules/exports-loader/dist/cjs.js):
ValidationError: Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema.
options misses the property 'exports'. Should be:
non-empty string | non-empty string | object { name, syntax?, alias? } | [non-empty string | object { name, syntax?, alias? }, ...] (should not
have fewer than 1 item)
here is my webpack config, is there anything that I'm missing from webpack config or is this issue caused by webpack at all?
module.exports = {
devtool: 'eval',
entry: ['app/app.js'],
loader: { target: 'web' },
mode: 'development',
module: {
strictExportPresence: true,
rules: [
{
test: /\.svg/,
use: {
loader: 'svg-url-loader',
options: {
iesafe: true,
},
},
},
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
loader: 'babel-loader',
include: [PATHS.APP_DIR],
exclude: [/node_modules/],
options: {
...babelConfig,
},
},
{
test: /\.(eot|otf|ttf|woff|woff2)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]',
outputPath: 'fonts',
},
},
],
},
{
test: /\.(gif|png|jpe?g)$/i,
use: [
{
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
quality: 65,
},
// optipng.enabled: false will disable optipng
optipng: {
enabled: false,
},
pngquant: {
quality: [0.65, 0.9],
speed: 4,
},
gifsicle: {
interlaced: false,
},
// the webp option will enable WEBP
webp: {
quality: 75,
},
},
},
{
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]',
outputPath: 'images',
},
},
],
},
{
test: /\.(s*)css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 1,
},
},
],
},
],
},
node: { global: false, __dirname: false, __filename: false },
output: {
path: 'build/',
publicPath: '/',
filename: '[name].js',
chunkFilename: '[name].chunk.js',
},
plugins: [
new WebpackBar({
name: 'CSR',
color: '#FFEB3B',
}),
new webpack.ProvidePlugin({
// make fetch available
fetch: 'exports-loader?self.fetch!whatwg-fetch',
}),
new webpack.DefinePlugin({
'process.env': webpackEnv(),
}),
new LoadablePlugin({
filename: 'loadable-stats.json',
writeToDisk: true,
}),
new CopyPlugin({
patterns: [
{
from: path.join('resources', 'public'),
to: 'build',
},
],
}),
new HtmlWebPackPlugin({
template: `/index.ejs`,
title: 'MY APP',
}),
new webpack.HotModuleReplacementPlugin({
multiStep: false,
}),
new CircularDependencyPlugin({
exclude: /a\.js|node_modules/, // exclude node_modules
failOnError: false, // show a warning when there is a circular dependency
}),
],
resolve: {
modules: ['node_modules'],
alias: {
// my aliases
},
},
stats: { preset: 'minimal', moduleTrace: true, errorDetails: true },
target: 'web',
};

the issue was caused by whatwg-fetch
fetch: 'exports-loader?self.fetch!whatwg-fetch',
by removing this line since it wasn't necessary, the problem has been solved

Related

Use the same port in Module Federated React Application

I've 3 applications which are embedded on the same spring service (built by yarn maven plugin) with the following configuration:
App Shell
module.exports = {
mode: 'production',
entry: './src/index',
cache: false,
devtool: false,
optimization: {
minimize: true,
},
output: {
publicPath: 'http://localhost:8000/gui/shell/',
clean: true,
pathinfo: false,
path: path.resolve(__dirname, 'build/'),
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '.json'],
},
module: {
rules: [
{
test: /\.m?js/,
type: 'javascript/auto',
resolve: {
fullySpecified: false,
},
},
{
test: /\.css$/i,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
},
},
],
},
{
test: /\.(ts|tsx|js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.svg$/,
use: [
{
loader: 'svg-url-loader',
options: {
limit: 10000,
},
},
],
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /\.s[ac]ss$/i,
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)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
},
},
],
},
],
},
plugins: [
new ModuleFederationPlugin({
name: 'frontend_shell',
filename: 'remoteEntry.js',
remotes: {
store: 'store#http://localhost:8000/store/remoteEntry.js',
appOneRemote: 'appOneRemote#http://localhost:8000/appOneRemote/remoteEntry.js',
},
exposes: {
'./translate': './src/utility/i18n/translate.js',
'./useAllUserInfo': './src/hooks/useAllUserInfo.js',
'./useDarkMode': './src/hooks/useDarkMode.js',
},
shared: {
...deps,
react: {
singleton: true,
requiredVersion: deps.react,
eager: true,
},
'react-dom': {
singleton: true,
requiredVersion: deps['react-dom'],
eager: true,
},
},
}),
new HtmlWebPackPlugin({
template: './public/index.html',
inject: 'body',
hash: true,
minify: true,
}),
new ESLintPlugin({
extensions: ['js', 'jsx'],
}),
],
};
App remote 1
module.exports = {
mode: 'production',
entry: './src/index',
cache: false,
devtool: false,
optimization: {
minimize: true,
},
output: {
publicPath: 'http://localhost:8000/appOneRemote/',
clean: true,
pathinfo: false,
path: path.resolve(__dirname, 'build/'),
},
resolve: {
extensions: ['.js', '.mjs', '.jsx', '.css'],
alias: {
events: 'events',
},
},
module: {
rules: [
{
test: /\.m?js/,
type: 'javascript/auto',
resolve: {
fullySpecified: false,
},
},
{
test: /\.css$/i,
use: [
'style-loader', 'css-loader',
],
},
{
test: /\.(ts|tsx|js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.svg$/,
use: ['#svgr/webpack'],
},
{
test: /\.json$/,
loader: 'json-loader',
},
],
},
plugins: [
new ModuleFederationPlugin({
name: 'appOneRemote',
filename: 'remoteEntry.js',
remotes: {
store: 'store#http://localhost:8000/store/remoteEntry.js',
shell: 'frontend_shell#http://localhost:8000/gui/shell/remoteEntry.js',
},
exposes: {
'./ManageUser': './src/pages/ManageUser/ManageUser.jsx',
},
shared: {
...deps,
react: {
singleton: true,
requiredVersion: deps.react,
eager: true,
},
'react-dom': {
singleton: true,
requiredVersion: deps['react-dom'],
eager: true,
},
},
}),
new HtmlWebPackPlugin({
template: './public/index.html',
}),
new ESLintPlugin({
extensions: ['js', 'jsx'],
}),
],
};
App remote 2
module.exports = {
mode: 'production',
entry: './src/index',
cache: false,
devtool: false,
optimization: {
minimize: true,
},
output: {
publicPath: 'http://localhost:8000/store/',
clean: true,
pathinfo: false,
path: path.resolve(__dirname, 'build/'),
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '.json'],
},
module: {
rules: [
{
test: /\.m?js/,
type: 'javascript/auto',
resolve: {
fullySpecified: false,
},
},
{
test: /\.(css|s[ac]ss)$/i,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
{
test: /\.(ts|tsx|js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.json$/,
loader: 'json-loader',
},
],
},
plugins: [
new ModuleFederationPlugin({
name: 'store',
filename: 'remoteEntry.js',
remotes: {},
exposes: { './store': './src/store' },
shared: {
...deps,
react: {
singleton: true,
requiredVersion: deps.react,
},
'react-dom': {
singleton: true,
requiredVersion: deps['react-dom'],
},
'react-redux': {
singleton: true,
},
},
}),
new HtmlWebPackPlugin({
template: './public/index.html',
}),
new ESLintPlugin({
extensions: ['js', 'jsx'],
}),
],
};
This is exactly what I get in the console:
Warning:
Initialization of sharing external failed: ScriptExternalLoadError: Loading script failed.
(error: http://localhost:8000/appOneRemote/remoteEntry.js)
Warning:
Initialization of sharing external failed: ScriptExternalLoadError: Loading script failed.
(error: http://localhost:8000/store/remoteEntry.js)
Error:
Uncaught (in promise) ScriptExternalLoadError: Loading script failed.
(error: http://localhost:8000/store/remoteEntry.js)
while loading "./store" from 83878
at Object.83878 (main.js?1154643655f4125db28e:2:130241)
Also I can retrieve my shell remote entry here: http://localhost:8000/gui/shell/remoteEntry.js, but I got a 404 in the following:
http://localhost:8000/store/remoteEntry.js
http://localhost:8000/appOneRemote/remoteEntry.js
Any ideas?

Webpack will constantly "Compiling successfully" and "Compiling" after touching a file

import path from 'path';
import fs from 'fs';
import webpack from 'webpack';
import chalk from 'chalk';
import { merge } from 'webpack-merge';
import { spawn, execSync } from 'child_process';
import baseConfig from './webpack.config.base';
import CheckNodeEnv from '../scripts/CheckNodeEnv';
import ReactRefreshWebpackPlugin from '#pmmmwh/react-refresh-webpack-plugin';
// When an ESLint server is running, we can't set the NODE_ENV so we'll check if it's
// at the dev webpack config is not accidentally run in a production environment
if (process.env.NODE_ENV === 'production') {
CheckNodeEnv('development');
}
const port = process.env.PORT || 1212;
const publicPath = `http://localhost:${port}/dist`;
const dllDir = path.join(__dirname, '../dll');
const manifest = path.resolve(dllDir, 'renderer.json');
const requiredByDLLConfig = module.parent.filename.includes(
'webpack.config.renderer.dev.dll'
);
/**
* Warn if the DLL is not built
*/
if (!requiredByDLLConfig && !(fs.existsSync(dllDir) && fs.existsSync(manifest))) {
console.log(
chalk.black.bgYellow.bold(
'The DLL files are missing. Sit back while we build them for you with "yarn build-dll"'
)
);
execSync('yarn build-dll');
}
export default merge(baseConfig, {
devtool: 'inline-source-map',
mode: 'development',
target: 'electron-renderer',
entry: [
'core-js',
'regenerator-runtime/runtime',
require.resolve('../../src/renderer/index.tsx'),
],
output: {
publicPath: `http://localhost:${port}/dist/`,
filename: 'renderer.dev.js',
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
plugins: [
require.resolve('react-refresh/babel'),
].filter(Boolean),
},
},
],
},
{
test: /\.global\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [require('tailwindcss'), require('autoprefixer')],
},
}
}
],
},
{
test: /^((?!\.global).)*\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name]__[local]__[hash:base64:5]',
},
sourceMap: true,
importLoaders: 1,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [require('tailwindcss'), require('autoprefixer')],
},
}
}
],
},
// SASS support - compile all .global.scss files and pipe it to style.css
{
test: /\.global\.(scss|sass)$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'sass-loader',
},
],
},
// SASS support - compile all other .scss files and pipe it to style.css
{
test: /^((?!\.global).)*\.(scss|sass)$/,
use: [
{
loader: 'style-loader',
},
{
loader: '#teamsupercell/typings-for-css-modules-loader',
},
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name]__[local]__[hash:base64:5]',
},
sourceMap: true,
importLoaders: 1,
},
},
{
loader: 'sass-loader',
},
],
},
// WOFF Font
{
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff',
},
},
},
// WOFF2 Font
{
test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff',
},
},
},
// OTF Font
{
test: /\.otf(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'font/otf',
},
},
},
// TTF Font
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/octet-stream',
},
},
},
// EOT Font
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
use: 'file-loader',
},
// SVG Font
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'image/svg+xml',
},
},
},
// Common Image Formats
{
test: /\.(?:ico|gif|png|jpg|jpeg|webp)$/,
use: 'url-loader',
},
],
},
plugins: [
requiredByDLLConfig
? null
: new webpack.DllReferencePlugin({
context: path.join(__dirname, '../dll'),
manifest: require(manifest),
sourceType: 'var',
}),
new webpack.NoEmitOnErrorsPlugin(),
/**
* Create global constants which can be configured at compile time.
*
* Useful for allowing different behaviour between development builds and
* release builds
*
* NODE_ENV should be production so that modules do not perform certain
* development checks
*
* By default, use 'development' as NODE_ENV. This can be overriden with
* 'staging', for example, by changing the ENV variables in the npm scripts
*/
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
}),
new webpack.LoaderOptionsPlugin({
debug: true,
}),
new ReactRefreshWebpackPlugin(),
],
node: {
__dirname: false,
__filename: false,
},
devServer: {
disableHostCheck: true,
port,
publicPath,
compress: true,
noInfo: false,
stats: 'errors-only',
inline: true,
lazy: false,
hot: true,
headers: { 'Access-Control-Allow-Origin': '*' },
contentBase: path.join(__dirname, 'dist'),
watchOptions: {
aggregateTimeout: 300,
ignored: /node_modules/,
poll: 100,
},
historyApiFallback: {
verbose: true,
disableDotRule: false,
},
before() {
console.log('Starting Main Process...');
spawn('npm', ['run', 'start:main'], {
shell: true,
env: process.env,
stdio: 'inherit',
})
.on('close', (code) => process.exit(code))
.on('error', (spawnError) => console.error(spawnError));
},
},
});
I use the https://github.com/electron-react-boilerplate/electron-react-boilerplate as the template to do a electron application. After introducing tailwind css and react router, my web devserver will constantly compile like image after touching a file. Does any one has the issue and give me a help? Sorry about too many js code in webpack configuration js, but I think lots of part can be skpied.

Computed Properties not working with Babel preset-env

I'm trying to use computed properties in my Material UI style object, but I've getting an unexpected token error.
Below is the code snippet, error, and babel-webpack config.
const useStyles = makeStyles(theme => {
root: {
[desktop]: {
width: "80%",
}
}
});
//webpack.config.babel.js
...
const config = {
entry: ['#babel/polyfill', './src/components/index.js'],
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
devServer: {
host: '0.0.0.0',
historyApiFallback: {
index: 'index.dev.html',
},
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'main.js',
chunkFilename: '[name].js',
publicPath: '/build/',
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true,
extractComments: true,
}),
new OptimizeCSSAssetsPlugin({}),
],
splitChunks: {
cacheGroups: {
default: false,
vendors: {
// name of the chunk
name: 'vendor',
// sync + async chunks
chunks: 'all',
// import file path containing node_modules
test: /node_modules/,
priority: 20,
},
styles: {
name: 'styles',
test: /\.css$/,
chunks: "all",
enforce: true,
},
common: {
name: 'common',
minChunks: 2,
chunks: 'all',
priority: 10,
reuseExistingChunk: true,
enforce: true,
},
},
},
},
module: {
rules: [
{
test: /\.(js|ts)x?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
'#babel/typescript',
"#babel/preset-env",
'#babel/preset-react',
'#babel/preset-flow',
],
plugins: [
'#babel/plugin-transform-runtime',
'#babel/plugin-proposal-object-rest-spread',
['#babel/plugin-proposal-decorators', {legacy: true}],
['#babel/plugin-proposal-class-properties', {loose: true}],
['#babel/plugin-transform-computed-properties', {loose: true}],
],
},
},
{
test: /\.s?[ac]ss$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
],
},
node: {
fs: 'empty',
},
// First array is dev only, second is production
plugins: devMode
? [
] : [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
],
};
// Exports
module.exports = config;
at Object.raise (/node_modules/#babel/parser/lib/index.js:6931:17)
at Object.unexpected (/node_modules/#babel/parser/lib/index.js:8324:16)
at Object.semicolon (/node_modules/#babel/parser/lib/index.js:8306:40)
at Object.parseExpressionStatement (/node_modules/#babel/parser/lib/index.js:11147:10)
at Object.parseExpressionStatement (/node_modules/#babel/parser/lib/index.js:2072:18)
at Object.parseStatementContent (/node_modules/#babel/parser/lib/index.js:10746:19)
at Object.parseStatement (/node_modules/#babel/parser/lib/index.js:10612:17)
at Object.parseStatement (/node_modules/#babel/parser/lib/index.js:2045:26)
at Object.parseBlockOrModuleBlockBody (/node_modules/#babel/parser/lib/index.js:11188:25)
at Object.parseBlockBody (/node_modules/#babel/parser/lib/index.js:11175:10)
at Object.parseBlock (/node_modules/#babel/parser/lib/index.js:11159:10)
at Object.parseStatementContent (/node_modules/#babel/parser/lib/index.js:10688:21)
at Object.parseStatement (/node_modules/#babel/parser/lib/index.js:10612:17)
at Object.parseStatement (/node_modules/#babel/parser/lib/index.js:2045:26)
at Object.parseLabeledStatement (/node_modules/#babel/parser/lib/index.js:11139:22)
at Object.parseStatementContent (/node_modules/#babel/parser/lib/index.js:10744:19)
Well this was a simple mistake. I didn't enclose my object in parentheses (missing return).
const useStyles = makeStyles((theme) => ({
root: {
[desktop]: {
...
}
}
}));

webpack config not emitting css in build folder

Here is my config for webpack production mode.
const serverConfig = {
//mode: "production",
optimization: {
//minimize: true,
splitChunks: {
chunks: "async",
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "vendor",
chunks: "all",
},
// server: {
// name: "server",
// chunks: "all",
// enforce: true,
// },
// flightsDesktop: {
// name: "flightsDesktop",
// test: (m, c, entry = "flightsDesktop") => m.constructor.name === "CssModule" && recursiveIssuer(m) === entry,
// chunks: "all",
// enforce: true,
// },
},
},
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
compress: true,
ecma: 6,
output: {
comments: false,
},
compess: {
dead_code: true,
drop_console: true,
},
},
sourceMap: false,
}),
],
},
entry: {
server: path.resolve(__dirname, "../script/server_script.js"),
flightsDesktop: cssHelper.getFlightsDesktopHomeCss(__dirname),
hotelsDesktop: cssHelper.getHotelsDesktopHomeCss(__dirname),
homestaysDesktop: cssHelper.getHomestayDesktopHomeCss(__dirname),
holidaysDesktop: cssHelper.getHolidayDesktopHomeCss(__dirname),
flightsAdaptive: cssHelper.getFlightsAdaptiveHomeCss(__dirname),
hotelsAdaptive: cssHelper.getHotelsAdaptiveHomeCss(__dirname),
homestaysAdaptive: cssHelper.getHomestayAdaptiveHomeCss(__dirname),
holidaysAdaptive: cssHelper.getHolidayAdaptiveHomeCss(__dirname),
experiencesDesktop: cssHelper.getExperiencesDesktopHomeCss(__dirname),
experiencesAdaptive: cssHelper.getExperiencesAdaptiveHomeCss(__dirname),
hotelsSEODesktop: cssHelper.getHotelsSEODesktopCss(__dirname),
hotelsSEOAdaptive: cssHelper.getHotelsSEOAdaptiveCss(__dirname),
trainsDesktop: cssHelper.getTrainsDesktopHomeCss(__dirname),
trainsAdaptive: cssHelper.getTrainsAdaptiveHomeCss(__dirname),
},
target: "node",
output: {
// path: path.join(__dirname, "../build"),
// filename: "[name].js",
//libraryTarget: "commonjs2",
path: path.join(__dirname, "../build"),
// 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: "[name].js",
//chunkFilename: "static/js/[name].[hash:8].chunk.js",
// We inferred the "public path" (such as / or /my-project) from homepage.
publicPath,
},
module: {
rules: [
{
exclude: [
/\.html$/,
/\.(js|jsx)$/,
/\.css$/,
/\.json$/,
/\.svg$/,
],
// loader, query and exclude
loader: "url-loader",
options: {
limit: 10000,
name: "/static/media/[name].[hash:8].[ext]",
},
},
{
test: /\.svg$/,
loader: "file-loader",
options: {
name: "/static/media/[name].[hash:8].[ext]",
},
},
{
test: /\.css$/,
use: [
"style-loader",
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
importLoaders: 1,
minimize: true,
},
},
"postcss-loader",
"sass-loader",
],
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
},
{
test: /\.scss$/,
use: [
// MiniCssExtractPlugin.loader,
{
loader: "css-loader/locals",
},
],
},
{
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
loader: "babel-loader",
query: { presets: ["react", "es2016", "es2015"], plugins: ["transform-class-properties"] },
},
],
},
plugins: [
new webpack.DefinePlugin(env),
//new WriteFilePlugin(),
// This helps ensure the builds are consistent if source hasn't changed:
new webpack.optimize.OccurrenceOrderPlugin(),
// Try to dedupe duplicated modules, if any:
// new webpack.optimize.DedupePlugin(),
// Minify the code.
// new webpack.optimize.UglifyJsPlugin({
// compress: {
// screw_ie8: true, // React doesn't support IE8
// warnings: false,
// },
// mangle: {
// screw_ie8: true,
// },
// output: {
// comments: false,
// screw_ie8: true,
// },
// }),
//new UglifyJsPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css",
path: "static/css/",
}),
//new ExtractTextPlugin("static/css/[name].css"),
new webpack.LoaderOptionsPlugin({
options: {
postcss: [
autoprefixer({
browsers: [
">1%",
"last 4 versions",
"Firefox ESR",
"not ie < 9", // React doesn't support IE8 anyway
],
}),
],
},
}),
],
resolve: {
modules: ["src", "node_modules"],
},
}
module.exports = [serverConfig]
I am miising something obvious, what wrong I am doing?

Migrating from web pack v1.15 config to v2.6.1

Updated webpack to the latest version(2.6.1), so the webpack config file, that came with the boilerplate, became outdated...
Looked at the official documentation on migration, but still a bit lost regarding how exactly i need to update my config file:
'use strict';
const path = require('path');
const webpack = require('webpack');
const NODE_ENV = process.env.NODE_ENV;
const SaveAssetsJson = require('assets-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
devtool: '#source-map',
// Capture timing information for each module
profile: false,
// Switch loaders to debug mode
debug: false,
// Report the first error as a hard error instead of tolerating it
bail: true,
entry: [
'babel-polyfill',
'./assets/main.jsx',
],
output: {
path: 'public/dist/',
pathInfo: true,
publicPath: '/dist/',
filename: 'bundle.[hash].min.js',
},
resolve: {
root: path.join(__dirname, ''),
modulesDirectories: [
'web_modules',
'node_modules',
'assets',
'assets/components',
],
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx'],
},
resolveLoader: {
},
plugins: [
new CleanWebpackPlugin(['public/dist'], {
verbose: true,
dry: false,
}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
output: {
comments: false,
},
compress: {
warnings: false,
screw_ie8: true,
},
}),
new SaveAssetsJson({
path: process.cwd(),
filename: 'assets.json',
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
],
query: {presets: ['es2015', 'react'] },
module: {
rules: [
{
use: [
"style-loader",
"css-loader",
"autoprefixer-loader",
]
},
{
test: /\.scss$/, // sass files
loader: 'style!css!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded',
},
{
test: /\.(ttf|eot|svg|woff)(\?[a-z0-9]+)?$/, // fonts files
loader: 'file-loader?name=[path][name].[ext]',
},
{
test: /\.jsx?$/, // react files
exclude: /node_modules/,
loaders: ['babel?presets[]=es2015,presets[]=stage-0,presets[]=react'],
include: path.join(__dirname, 'assets'),
},
],
noParse: /\.min\.js/,
}
};
In the end there were few deletion of the deprecated plugin calls and restructuring some of the fields. Here is the 2.6.1 compatible version, the parts of the file that were changed:
'use strict';
module.exports = {
devtool: '#source-map',
// Capture timing information for each module
profile: false,
// Switch loaders to debug mode
//debug: false,
// Report the first error as a hard error instead of tolerating it
bail: true,
entry: [
'babel-polyfill',
'./assets/main.jsx',
],
output: {
path: '/public/dist/', //This has to be an absolute path
publicPath: '/dist/',
filename: 'bundle.[hash].min.js',
},
resolve: {
//merging root and modules
modules: [
path.join(__dirname, ''),
'web_modules',
'node_modules',
'assets',
'assets/components',
],
extensions: [ '.webpack.js', '.web.js', '.js', '.jsx'], //Removed empty entry
},
resolveLoader: {
},
plugins: [
new CleanWebpackPlugin(['public/dist'], {
verbose: true,
dry: false,
}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
sourceMap: true, //added this
output: {
comments: false,
},
compress: {
warnings: false,
screw_ie8: true,
},
}),
new SaveAssetsJson({
path: process.cwd(),
filename: 'assets.json',
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
],
module: {
//Modules are slightly differently listed now
rules: [
{
test: /\.(css|scss)$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader" // compiles Sass to CSS
}]
},
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015', "stage-0", 'react']
}
}
}
],
noParse: /\.min\.js/,
}
};

Resources