我有一个当前的网站,通过常规的Visual Studio(而不是VS代码)生成多个版本 .
我们基本上做:
module.exports = {
context: __dirname + "/Scripts",
entry: {
build1: './Layout/functionality1.jsx',
build2: './Layout/functionality2.jsx',
...
},
...
然后,对于特定的index.cshtml文件,我包括:
<script src="@Url.Content("~/Scripts/Build/build1.js")"></script>
这样可以正常工作,但缺点是使用webpack在开发周期之间每次构建 . 我一直在使用Visual Studio Code(非常规的Visual Stuido)玩Create React App,它使用npm start来创建构建 . 同样,在更新和保存Create React App附带的App.js文件时,它会自动更新localhost . 这绝对是非常棒的 .
我想在我当前的网站上实现这一点,但是在研究创建反应应用程序如何将app.js文件导入我们的html时,它对我来说变得不那么有意义了 . 不在index.html文件的内部,我们称之为任何类型的build.js . 事实上,我找不到这个html文件中任何地方的js文件的引用 .
这些文件在哪里以及如何链接到创建反应应用程序? html在哪里调用js? index.html根本没有参考 .
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
...
-->
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
...
-->
</body>
</html>
但我可以看到index.js在index.html中引用root元素的位置 .
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
如果我理解这是如何发生的,那么我的印象是我可以弄清楚如何将三个不同的主文件连接到这个Visual Studio代码项目然后使用我以前的构建文件基本上就像这样
http://localhost:3000/functionality1
http://localhost:3000/functionality2
http://localhost:3000/functionality3 ...
编辑:
这是我的配置文件:
{
"version": "0.2.0",
"configurations": [
{
"name": "Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}/src",
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}
}
]
}