framework7-cli generated app dev server doesn't update - reactjs

I used the new Framework7-cli to generate a Cordova App with React presets. When everything was finished setting up I ran npm run start and tried changing some code in /pages/home.jsx, but nothing was updated in the browser. Does anyone know why this doesn't work right out of the box?
Here is what webpack.config.js looks like:
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
const path = require('path');
function resolvePath(dir) {
return path.join(__dirname, '..', dir);
}
const env = process.env.NODE_ENV || 'development';
const target = process.env.TARGET || 'web';
const isCordova = target === 'cordova';
module.exports = {
mode: env,
entry: [
'./src/js/app.js',
],
output: {
path: resolvePath(isCordova ? 'cordova/www' : 'www'),
filename: 'js/app.js',
publicPath: '',
hotUpdateChunkFilename: 'hot/hot-update.js',
hotUpdateMainFilename: 'hot/hot-update.json',
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
alias: {
'#': resolvePath('src'),
},
},
devtool: env === 'production' ? 'source-map' : 'eval',
devServer: {
hot: true,
open: true,
compress: true,
contentBase: '/www/',
disableHostCheck: true,
watchOptions: {
poll: 1000,
},
},
optimization: {
minimizer: [new TerserPlugin({
sourceMap: true,
})],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: 'babel-loader',
include: [
resolvePath('src'),
resolvePath('node_modules/framework7'),
resolvePath('node_modules/framework7-react'),
resolvePath('node_modules/template7'),
resolvePath('node_modules/dom7'),
resolvePath('node_modules/ssr-window'),
],
},
{
test: /\.css$/,
use: [
(env === 'development' ? 'style-loader' : {
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../'
}
}),
'css-loader',
'postcss-loader',
],
},
{
test: /\.styl(us)?$/,
use: [
(env === 'development' ? 'style-loader' : {
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../'
}
}),
'css-loader',
'postcss-loader',
'stylus-loader',
],
},
{
test: /\.less$/,
use: [
(env === 'development' ? 'style-loader' : {
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../'
}
}),
'css-loader',
'postcss-loader',
'less-loader',
],
},
{
test: /\.(sa|sc)ss$/,
use: [
(env === 'development' ? 'style-loader' : {
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../'
}
}),
'css-loader',
'postcss-loader',
'sass-loader',
],
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: 'images/[name].[ext]',
},
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac|m4a)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: 'media/[name].[ext]',
},
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: 'fonts/[name].[ext]',
},
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env),
'process.env.TARGET': JSON.stringify(target),
}),
...(env === 'production' ? [
new OptimizeCSSPlugin({
cssProcessorOptions: {
safe: true,
map: { inline: false },
},
}),
new webpack.optimize.ModuleConcatenationPlugin(),
] : [
// Development only plugins
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
]),
new HtmlWebpackPlugin({
filename: './index.html',
template: './src/index.html',
inject: true,
minify: env === 'production' ? {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true
} : false,
}),
new MiniCssExtractPlugin({
filename: 'css/app.css',
}),
new CopyWebpackPlugin([
{
from: resolvePath('src/static'),
to: resolvePath(isCordova ? 'cordova/www/static' : 'www/static'),
},
{
from: resolvePath('src/manifest.json'),
to: resolvePath('www/manifest.json'),
},
]),
...(!isCordova ? [
new WorkboxPlugin.InjectManifest({
swSrc: resolvePath('src/service-worker.js'),
})
] : []),
],
};
And here is package.json
{
"name": "my-app",
"private": true,
"version": "1.0.0",
"description": "My App",
"repository": "",
"license": "UNLICENSED",
"framework7": {
"cwd": "/home/david/test-react",
"type": [
"pwa",
"cordova",
"web"
],
"name": "My App",
"pkg": "io.framework7.myapp",
"framework": "react",
"template": "single-view",
"cssPreProcessor": false,
"bundler": "webpack",
"cordova": {
"folder": "cordova",
"platforms": [
"ios",
"android"
],
"plugins": [
"cordova-plugin-statusbar",
"cordova-plugin-keyboard",
"cordova-plugin-splashscreen",
"cordova-plugin-wkwebview-engine"
]
},
"webpack": {
"developmentSourceMap": true,
"productionSourceMap": true,
"hashAssets": false,
"preserveAssetsPaths": false,
"inlineAssets": true
},
"theming": {
"customColor": false,
"color": "#007aff",
"darkTheme": false,
"iconFonts": true,
"fillBars": false
},
"customBuild": false
},
"scripts": {
"build-dev": "cross-env NODE_ENV=development node ./build/build.js",
"build-prod": "cross-env NODE_ENV=production node ./build/build.js",
"build-cordova-dev": "cross-env TARGET=cordova cross-env NODE_ENV=development node ./build/build.js && cd cordova && cordova build",
"build-cordova-prod": "cross-env TARGET=cordova cross-env NODE_ENV=production node ./build/build.js && cd cordova && cordova build",
"build-cordova-ios-dev": "cross-env TARGET=cordova cross-env NODE_ENV=development node ./build/build.js && cd cordova && cordova build ios",
"build-cordova-ios-prod": "cross-env TARGET=cordova cross-env NODE_ENV=production node ./build/build.js && cd cordova && cordova build ios",
"build-cordova-android-dev": "cross-env TARGET=cordova cross-env NODE_ENV=development node ./build/build.js && cd cordova && cordova build android",
"build-cordova-android-prod": "cross-env TARGET=cordova cross-env NODE_ENV=production node ./build/build.js && cd cordova && cordova build android",
"dev": "cross-env NODE_ENV=development webpack-dev-server --config ./build/webpack.config.js",
"start": "npm run dev",
"postinstall": "cpy './node_modules/framework7-icons/fonts/*.*' './src/fonts/'"
},
"browserslist": [
"Android >= 5",
"IOS >= 9.3",
"Edge >= 15",
"Safari >= 9.1",
"Chrome >= 49",
"Firefox >= 31",
"Samsung >= 5"
],
"dependencies": {
"dom7": "^2.1.3",
"framework7": "^4.5.0",
"framework7-icons": "^2.3.1",
"framework7-react": "^4.5.0",
"prop-types": "^15.7.2",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"template7": "^1.4.2"
},
"devDependencies": {
"#babel/core": "^7.5.5",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/plugin-transform-runtime": "^7.5.5",
"#babel/preset-env": "^7.5.5",
"#babel/preset-react": "^7.0.0",
"#babel/runtime": "^7.5.5",
"babel-loader": "^8.0.6",
"chalk": "^2.4.2",
"copy-webpack-plugin": "^5.0.4",
"cpy-cli": "^2.0.0",
"cross-env": "^5.2.0",
"css-loader": "^3.2.0",
"file-loader": "^4.2.0",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.8.0",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"ora": "^3.4.0",
"postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.7.0",
"rimraf": "^3.0.0",
"style-loader": "^1.0.0",
"terser-webpack-plugin": "^1.4.1",
"url-loader": "^2.1.0",
"webpack": "^4.39.2",
"webpack-cli": "^3.3.7",
"webpack-dev-server": "^3.8.0",
"workbox-webpack-plugin": "^4.3.1"
}
}

I see one little but very important problem here. In Your package.json-->scripts-->start You don't include some commands.
It should look like this:
"start": "npm run — mode development — open — hot",
What is going on here:
When You trigger npm start, webpack-dev-server is going to fire up the application in mode=development.
Then ( — open) displays it in your default browser automatically.
And finally, ( — hot) keeps watching for any changes made to the application.
If it doesn't help You try this one:
"start": "npm run — mode dev — open — hot",
Good luck :)

Related

How to remove source maps from webpack 5 #React.js #webpack 5

The common solution for removing source maps from a CRA build is to add "GENERATE_SOURCEMAPS=false react-scripts build" in package.json build scripts and/or "GENERATE_SOURCEMAPS=false" in the CRA .env file. However, I do not use Create React App. Therefore, "react-scripts build" is not recognized as an internal command, my .env file has no effect on the bundled code, and simply adding "GENERATE_SOURCEMAPS=false" to my build scripts does nothing. I would like to remove source maps from the webpack bundle. Here is my package.json.
{
"name": "reactboilerplate",
"version": "1.0.0",
"description": "boilerplate code",
"main": "index.js",
"presets":
[
"#babel/preset-env",
"#babel/preset-react"
],
"scripts":
{
"build": "cross-env GENERATE_SOURCEMAP=false webpack --watch",
"start": "webpack serve",
"build-prod": "weback -p",
"winBuild": "set \"GENERATE_SOURCEMAP=false\" && build"
},
"keywords": [],
"author": "ziggy",
"license": "NONE",
"devDependencies":
{
"#babel/core": "^7.16.7",
"#babel/preset-env": "^7.16.8",
"#babel/preset-react": "^7.16.7",
"babel-loader": "^8.2.3",
"css-loader": "^6.5.1",
"file-loader": "^6.2.0",
"html-loader": "^3.1.0",
"html-webpack-plugin": "^5.5.0",
"node-polyfill-webpack-plugin": "^1.1.4",
"style-loader": "^3.3.1",
"webpack": "^5.66.0",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.7.3"
},
"dependencies":
{
"#aws-amplify/ui-react": "^2.1.9",
"aws-amplify": "^4.3.12",
"aws-amplify-react": "^5.1.9",
"bootstrap": "^5.1.3",
"pandadoc-node-client": "^4.1.0",
"react": "^17.0.2",
"react-bootstrap": "^2.1.1",
"react-dom": "^17.0.2",
"typewriter-effect": "^2.18.2"
}
}
Here is my webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
module.exports = {
mode: 'development',
entry: './src/index.js',
output:
{
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
resolve:
{
modules: [path.join(__dirname, 'src'), 'node_modules'],
alias: { react: path.join(__dirname, 'node_modules', 'react') }
},
plugins:
[
new NodePolyfillPlugin(),
new HtmlWebpackPlugin({ template: './src/index.html' }),
],
module:
{
rules: [
{
test: /\.css/i,
use: ['style-loader', 'css-loader']
},
{
test: /\.js$/,
exclude: /node_modules/,
use:
{
loader: "babel-loader",
options:
{
presets: ['#babel/preset-env', '#babel/preset-react']
}
}
},
{
test: /\.(png|mp4)$/i,
type: "asset/resource"
},
{
test: /\.txt$/i,
type: 'asset/source'
},
{
test: /\.(woff|woff2|ttf)$/i,
type: "asset/resource"
},
{
test: /\.html$/,
use: ["html-loader"]
},
{
test: /\.(mov|mp4)$/,
use:
[
{
loader: 'file-loader',
options:
{
name: '[name].[ext]'
}
}
]
},
{
test: /\.m?js/,
resolve:
{
fullySpecified: false
}
},
]
}
}

Webpack 5.68 not tree shaking ESM imports

I can't get tree shaking to work correctly on my project running Webpack 5.68 and Babel 7.17.0.
If I import my component like this everything works fine and dandy.
import { InlineNotification } from 'carbon-components-react/es/components/Notification';
If I import like this, the entire library is imported into my bundle.
import { InlineNotification } from 'carbon-components-react';
It is not an issue with carbon-components-react, I was just giving an example. This happens with all libraries.
Below is my code. I'm not sure what I am missing!
// .babelrc
{
"presets": [
[
"#babel/preset-env",
{
"modules": false
}
],
"#babel/preset-react"
],
"plugins": [
"react-hot-loader/babel",
"#babel/plugin-transform-modules-commonjs",
"#babel/plugin-proposal-class-properties"
]
}
// package.json
{
"name": "my app",
"engines": {
"node": "^8.9.0",
"npm": ">= 5.5.0"
},
"main": "index.jsx",
"scripts": {
"dev": "npx foreman --procfile Procfile-dev start",
"build": "npm run build:prod",
"build:dev": "webpack --progress --config webpack.build.dev.js",
"build:prod": "NODE_ENV=production webpack --progress --config webpack.build.prod.js",
},
"devDependencies": {
"#babel/core": "^7.17.0",
"#babel/plugin-proposal-class-properties": "^7.16.7",
"#babel/plugin-transform-modules-commonjs": "^7.16.8",
"#babel/preset-env": "^7.16.11",
"#babel/preset-react": "^7.16.7",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.3",
"webpack": "^5.68.0",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.11.3"
},
"dependencies": {
"#carbon/icons-react": "^10.45.0",
"#carbon/themes": "^10.50.0",
"carbon-components": "^10.52.0",
"carbon-components-react": "^7.52.0",
"css-loader": "^1.0.1",
"foreman": "^3.0.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-hot-loader": "^4.13.0",
"webpack-merge": "^4.2.2"
}
}
// webpack.common.js
const webpack = require('webpack');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const HtmlWebpackPluginConfig = new HtmlWebPackPlugin({
template: './template/index.html',
filename: 'index.html',
inject: 'body'
});
module.exports = {
entry: './index.jsx',
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.scss?/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader', options: {limit: 100000}
}
]
},
plugins: [
HtmlWebpackPluginConfig,
],
resolve: {
fallback: {
fs: false,
net: false,
tls: false
}
}
};
// webpack.build.prod.js
const webpack = require('webpack');
const path = require('path');
const merge = require('webpack-merge');
const common = require('./webpack.common');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = merge(common, {
name: 'build:prod',
mode: 'production',
output: {
filename: 'dist/js/bundles/bundle.[contenthash].js',
path: path.resolve(__dirname, '.')
},
optimization: {
runtimeChunk: {
name: 'manifest',
},
splitChunks: {
chunks: 'all'
}
},
plugins: [
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}), // ignore all of the momentjs timezones
new BundleAnalyzerPlugin({ defaultSizes: 'gzip', generateStatsFile: true }),
]
});
I fixed this, the issue was a plugin in my .babelrc file
#babel/plugin-transform-modules-commonjs. I needed to remove this and ensure all of my imports/exports were using ESM rather than commonJS module.exports.

Why is my basic React app heavy after webpack build?

I have a basic React app (2 small pages and a redux store), which is supposed to be very light. But when building the final bundle, webpack tells me that the bundle is 1.12 MiB, while the recommended limit is 244 KiB. Yet, I have made optimisations, with Terser plugin & code splitting.
Here is my webpack.config.js:
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const Dotenv = require("dotenv-webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = () => {
const env = require("dotenv").config({ path: __dirname + "/.env" });
return {
mode: "development",
entry: "./src/Index.js",
output: {
path: path.join(__dirname, "./dist"),
filename: "[name].[hash].bundle.js",
publicPath: "/",
},
resolve: {
extensions: [".js", "jsx", ".json"],
alias: {
components: path.resolve(__dirname, "src/components/"),
pages: path.resolve(__dirname, "src/pages/"),
store: path.resolve(__dirname, "src/store/"),
src: path.resolve(__dirname, "src/"),
},
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: { loader: "babel-loader" },
},
{ test: /\.css$/, use: ["style-loader", "css-loader"] },
{ test: /\.(png|svg|jpg|gif)$/, use: ["file-loader"] },
{ test: /\.html$/, use: [{ loader: "html-loader" }] },
],
},
devServer: {
historyApiFallback: true,
port: 3000,
hot: true,
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
}),
new Dotenv(),
],
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
splitChunks: { chunks: "all" },
},
};
};
And here is my package.json:
{
"name": "app",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "webpack-dev-server --mode development --open --hot",
"build": "webpack --mode production",
},
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.0",
"react-router-dom": "^5.2.0",
"redux": "^4.0.5"
},
"devDependencies": {
"#babel/core": "^7.10.3",
"#babel/plugin-transform-runtime": "^7.10.3",
"#babel/preset-env": "^7.10.3",
"#babel/preset-react": "^7.10.1",
"babel-loader": "^8.1.0",
"dotenv-webpack": "^1.8.0",
"html-loader": "^1.1.0",
"html-webpack-plugin": "^4.3.0",
"terser-webpack-plugin": "^3.0.6",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
}
}
How to fix this?

Babel requiring module that isn't used?

I'm new to React, webpack, Babel.... all of it. Trying to setup a vanilla project where I want to utilize Salesforce Lightning Design System for React. npm run start shows the following error:
ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: [BABEL] /Users/brandor/test/react_tut/src/index.js: Cannot find module 'babel-preset-env'
Require stack:
- /Users/brandor/test/react_tut/node_modules/#salesforce/babel-preset-design-system-react/index.js
I'm not sure why it's stating that 'babel-preset-env' is required. Shouldn't that have been installed when I installed the slds modules with the following?
$ npm install #salesforce-ux/design-system #salesforce/design-system-react
If I do install the module (along with one other it complains about) then I get something that seems to be related to this issue, but I'm using what looks like the correct presets in my babel.config.js file.
The other error is:
TypeError: /Users/brandor/test/react_tut/src/components/App.js: Cannot read property 'bindings' of null which
Not sure if this is an issue with webpack config, babel, or incorrect version of something.
package.json
{
"name": "react_tut",
"version": "1.0.0",
"description": "Boilerplate stuff",
"main": "index.js",
"scripts": {
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open --hot"
},
"license": "MIT",
"dependencies": {
"#salesforce-ux/design-system": "^2.11.6",
"#salesforce/design-system-react": "^0.10.18",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-export-extensions": "^6.22.0",
"core-js": "^3.6.4",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
"devDependencies": {
"#babel/cli": "^7.8.4",
"#babel/core": "^7.8.4",
"#babel/preset-env": "^7.8.4",
"#babel/preset-flow": "^7.8.3",
"#babel/preset-react": "^7.8.3",
"babel-loader": "^8.0.6",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"css-loader": "^3.4.2",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.9.0",
"url-loader": "^4.0.0",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
}
}
webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
entry: './src/index.js',
resolve: {
modules: ['src', 'node_modules'],
extensions: ['.js', '.jsx']
},
output: {
path: path.join(__dirname, '/dist'),
filename: 'index_bundle.js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.jsx?$/,
include: [
path.join(__dirname, 'src/js'),
path.join(__dirname, 'node_modules/#salesforce/design-system-react'),
],
exclude: [
path.join(
__dirname,
'node_modules/#salesforce/design-system-react/node_modules',
),
],
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
],
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.(svg|gif|jpe?g|png)$/,
loader: 'url-loader?limit=10000'
},
{
test: /\.(eot|woff|woff2|ttf)$/,
loader: 'url-loader?limit=30&name=assets/fonts/webfonts/[name].[ext]'
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src', 'index.html'),
}),
],
};
babel.config.js
'use strict';
const presets = ['#babel/preset-react', '#babel/preset-flow', '#salesforce/babel-preset-design-system-react'];
module.exports = {
presets: [
...presets,
[
'#babel/preset-env',
{
modules: false,
corejs: '3',
useBuiltIns: 'usage',
},
],
],
env: {
test: {
presets: [
...presets,
[
'#babel/preset-env',
{
targets: { node: 'current' },
corejs: '3',
useBuiltIns: 'usage',
},
],
],
},
},
};

Errors cause webpack to not build

I'm using Webpack to compile the front end of a website created in React.
For the development environment, in Windows's cmd.exe I run the yarn dev instruction and the webpack correctly produces the bundles in the /dist folder.
For the production environment, in Windows's cmd.exe I run the yarn production instruction but it does not produce any bundles due to some errors in my .ts files. Is it possible to ignore these errors and complete bundles production?
package.json:
{
"name": "prtj",
"version": "1.0.0",
"description": "",
"main": "entry.js",
"scripts": {
"dev": "webpack --env=development",
"production": "webpack --env=production"
},
"author": "PRG",
"license": "ISC",
"dependencies": {
"i18next": "^14.0.1",
"moment": "^2.24.0",
"react": "^16.4.0",
"react-day-picker": "^7.4.0",
"react-dom": "^16.4.0",
"react-i18next": "^9.0.10",
"react-idle-timer": "^4.2.3",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.85.0"
},
"devDependencies": {
"#types/node": "^10.12.12",
"#types/react": "^16.7.13",
"css-loader": "^2.0.0",
"file-loader": "^2.0.0",
"style-loader": "^0.23.1",
"ts-loader": "^5.3.3",
"typescript": "^2.5.3",
"url-loader": "^0.5.9",
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3",
"webpack-dev-server": "^3.2.1"
}
}
webpack.config.js:
const path = require('path');
const config = require('../common/config.js');
const webpackConfig = env => {
return {
mode: env === "development" ? "development" : "production",
entry: ["./src/Index.tsx"],
output: {
filename: "tfsBundle.js",
path: path.join(__dirname, "dist/")
},
devtool: env === "development" ? "cheap-eval-source-map" : false,
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.ts', '.tsx', '.js', '.jsx'],
modules: [
path.resolve('./node_modules/'),
path.resolve('./src')
]
},
module: {
rules: [
{
test: /\.(jsx|tsx|js|ts)$/,
loader: "ts-loader",
options: {
compilerOptions: {
target: env === "development" ? "ES6" : "es5"
}
},
exclude: /node_modules/
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000'
}
]
},
devServer: {
host: "localhost",
contentBase: path.join(__dirname, "dist/")
},
externals: {
'Config': config.getConfig(env),
}
}
};
You can opt out using transpileOnly for .ts errors.
In your webpack.
{
test: /\.(tsx|ts)$/,
loader: "ts-loader",
options: {
transpileOnly: true
compilerOptions: { target: env === "development" ? "ES6" : "es5" } }
}

Resources