我有一个没有index.html页面的React。我的第一个反应应用程序,所以请考虑我的专业水平。
这里有很多答案,但当没有索引html入口点时就没有答案了。
我已经成功地在XAMPP上的apache上运行了这个应用程序,以便在本地主机上开发:7000(没有index.html)。这很好,因为我的webpack在内存中加载了一个包js。我使用命令"server": "node app.js",来运行热加载的本地服务器。
这是我webpack配置的一部分。
module.exports = {
entry: './src/main.js',
output: {
path: join(__dirname, '/dist/js/'),
filename: 'bundle.js',
publicPath: '/',
},到目前为止我所拥有的是:
下面是我为Dev工作的目录结构:
config
dist
node_modules
routes (contains all routes for the App)
src (Has all components and entry is main.js)
styles (Has scss but it gets compiled into a single dist/styles/style.css)
views (Has all handle bar files for views)
-app.js (Main entry with express and webpack config references)
-app-routes (routes for the app)
-env,js(Has environment variables such as database connection details, port)
-webpack.config.js
-nodemon.json
-package.json在yarn run prod之后,我得到一个dist文件夹,如下所示
images (all images for app)
js (contains bundle.js file)
styles (contains compiled style.css)我应该向htdocs根文件夹添加哪些文件?
发布于 2018-09-18 04:25:45
在插件中的webpack.config.js中添加以下内容
在最上层的某个地方做这个。
var HtmlWebpackPlugin = require('html-webpack-plugin');在您的插件中添加以下内容
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
filename: './index.html'
}),
],这将创建一个index.html文件并将您的.js & .css文件(如果有的话)注入到html文件中。
您可以阅读更多有关webpack插件的内容,以生成动态index.html文件Webpack HTML插件文档。
https://stackoverflow.com/questions/52378546
复制相似问题