Javascript 在React项目的index.html中引用基于环境的脚本
我试图在react项目中的index.html文件上使用自定义脚本文件。我不能直接将其称为基于环境的。因此,对于开发环境,我想在index.html文件中使用customFunc.dev.js,对于prod环境,我想使用customFunc.test.js。我们可以通过网页包配置动态插入脚本标记吗 下面是我用来从我的index.html所在的公用文件夹中为bundle.js提供服务的网页包配置Javascript 在React项目的index.html中引用基于环境的脚本,javascript,reactjs,webpack,Javascript,Reactjs,Webpack,我试图在react项目中的index.html文件上使用自定义脚本文件。我不能直接将其称为基于环境的。因此,对于开发环境,我想在index.html文件中使用customFunc.dev.js,对于prod环境,我想使用customFunc.test.js。我们可以通过网页包配置动态插入脚本标记吗 下面是我用来从我的index.html所在的公用文件夹中为bundle.js提供服务的网页包配置 var webpack = require('webpack'); var path
var webpack = require('webpack');
var path = require('path');
module.exports = {
context : path.resolve('src'),
entry: ["babel-polyfill", './index.js'],
output: {
path : path.resolve('build/js'),
filename: 'bundle.js',
publicPath : '/public/assets/js/'
},
externals: {
'Config': JSON.stringify(require("./config.prod.json"))
},
devServer: {
historyApiFallback: true,
disableHostCheck: true,
contentBase : 'public'
}
}
Index.html
演示工程
我想将自定义脚本文件注入index.html页面。我对网页有点陌生。任何帮助都将不胜感激
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description">
<title>Demo Project</title>
</head>
<body>
<div id="appContainer"></div>
<script type="text/javascript" src="/public/assets/js/bundle.js"></script>
</body>
</html>