アプリケーションは開発モードで正常に動作します。ただし、ビルド後に Index.html は空で、何も表示されません。
ここに私の App.jsxがあります
function App() {
return (
<Router>
<Header />
<Switch>
<Route path="/" exact component={Register} />
{/* <Register />
</Route> */}
<Route path="/register" exact>
<Register />
</Route>
<Route path="/login" exact>
<Login />
</Route>
<Route path="/admin" exact>
<Dashboard />
</Route>
<Route exact path="/:admin/all" component={AllEvents} />
<Route exact path="/event/book" render={(props) => <BookAppointment {...props} />} />
</Switch>
</Router>
);
}
export default App;
Webpack.common.js
const ESLintPlugin = require('eslint-webpack-plugin');
const path = require('path');
module.exports = {
entry: './src/index.jsx',
plugins: [new ESLintPlugin()],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: path.resolve(__dirname, 'node_modules'),
use: ['babel-loader'],
},
{
test: /\.html$/,
use: ['html-loader'],
},
{
test: /\.(svg|png|jpg|jpeg|gif)$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[hash].[ext]',
ouputPath: 'images',
},
},
},
],
},
resolve: {
extensions: ['.js', '.jsx'],
},
};
Webpack.dev.js
const common = require('./webpack.common');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { merge } = require('webpack-merge');
module.exports = merge(common, {
devtool: 'source-map',
mode: 'development',
output: {
publicPath: '/',
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
}),
],
module: {
rules: [
{
test: /\.scss$/, // regular expression /regex/
use: [
'style-loader', // 3. Injects styles into the dom
'css-loader', //2. compiles css into javascript
'sass-loader', //1. compiles sass to css
// it's basically style-loader(css-loader(sass-loader))
],
},
],
},
devServer: {
open: true,
overlay: true,
historyApiFallback: true,
proxy: {
'/api': {
target: 'http://localhost:5000/',
pathRewrite: { '^/api': '' },
},
},
},
});
webpack.prod.js
const path = require('path');
const common = require('./webpack.common');
const { merge } = require('webpack-merge');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserWebpackPlugin = require('terser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = merge(common, {
mode: 'production',
output: {
// where and in what name webpack bundle the code
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'build'),
publicPath: '/',
},
optimization: {
minimizer: [
new OptimizeCssAssetsPlugin(),
new TerserWebpackPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
minify: {
removeAttributeQuotes: true,
collapseWhitespace: true,
removeComments: true,
},
}),
],
},
module: {
rules: [
{
test: /\.scss$/, // regular expression /regex/
use: [
MiniCssExtractPlugin.loader, // 3. spits a new file
'css-loader', //2. compiles css into javascript
'sass-loader', //1. compiles sass to css
// basically style-loader(css-loader(sass-loader))
],
},
],
},
plugins: [
new MiniCssExtractPlugin({ filename: '[name].[contenthash].css' }),
new CleanWebpackPlugin({ verbose: true }),
],
});
ビルド後の index.html は次のとおりです。
<!DOCTYPE html><html lang=en>
<head>
<meta charset=UTF-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<link rel=icon href="data:;base64,iVBORw0KGgo="><title>The Scheduling App</title>
<link href=/main.e69f506daaac63b46b38.css rel=stylesheet></head>
<body>
<div id=app></div>
<script src=/main.5dcc8eebb9a160f1b5e4.js>
</script>
</body>
</html>
これが私のpackage.jsonです
{
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/eslint-parser": "^7.11.5",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.10.4",
"babel-loader": "^8.1.0",
"babel-plugin-styled-components": "^1.11.1",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^5.0.0",
"eslint": "^7.11.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.21.4",
"eslint-plugin-react-hooks": "^4.1.2",
"eslint-webpack-plugin": "^2.1.0",
"file-loader": "^6.1.1",
"html-loader": "^1.3.2",
"html-webpack-plugin": "^4.5.0",
"mini-css-extract-plugin": "^1.0.0",
"node-sass": "^4.14.1",
"optimize-css-assets-webpack-plugin": "^5.0.4",
"sass-loader": "^10.0.3",
"style-loader": "^2.0.0",
"webpack": "^5.1.0",
"webpack-cli": "^4.0.0",
"webpack-dev-server": "^3.11.0",
"webpack-merge": "^5.2.0"
},
"dependencies": {
"axios": "^0.20.0",
"core-js": "^3.6.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"regenerator-runtime": "^0.13.7"
}
}
私は何を間違っていますか?依存関係の問題ですか?ビルドしようとするとWebpackがこの警告を表示します
** [DEP_WEBPACK_COMPILATION_OPTIMIZE_CHUNK_ASSETS] DeprecationWarning: optimizeChunkAssets は非推奨です (代わりに Compilation.hook.processAssets を使用し、ステージ オプションとして Compilation.PROCESS_ASSETS_STAGE_* のいずれかを使用します) (node --trace-deprecation ...
警告が作成された場所を示すために使用します) (ノード:160318) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets は今後凍結され、すべての変更は廃止されます。
**
ありがとう!