I’m running npm server on http://localhost:9000/ to use cytoscape module. But my server can’t find my json file. What’s wrong with my code?
my index.js file source code.
import './favicon.ico';
import '../model/data.json';
fetch('../model/data.json', { mode: 'no-cors' })
.then(function (res) {
return res.json();
})
.then(function (data) {
console.log(data);
});
my webpack.config.js file source code.
const path = require("path");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
module.exports = {
entry: "./src/index.js",
output: {
filename: "bundle.js",
path: path.resolve(__dirname + "/build")
},
devServer: {
static: {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 9000,
},
mode: "none",
module: {
rules: [
{
test: /.(js|jsx)$/,
exclude: "/node_modules",
use: ['babel-loader'],
},
{
test: /.html$/,
use: [
{
loader: "html-loader",
options: { minimize: true }
}
]
},
{
test: /.css$/,
use: [MiniCssExtractPlugin.loader,'css-loader']
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: './public/index.html',
filename: 'index.html'
}),
new MiniCssExtractPlugin({
filename: 'style.css'
}),
new CleanWebpackPlugin()
]
};
I want my server to find data.json file…