Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在React项目的index.html中引用基于环境的脚本_Javascript_Reactjs_Webpack - Fatal编程技术网

Javascript 在React项目的index.html中引用基于环境的脚本

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

我试图在react项目中的index.html文件上使用自定义脚本文件。我不能直接将其称为基于环境的。因此,对于开发环境,我想在index.html文件中使用customFunc.dev.js,对于prod环境,我想使用customFunc.test.js。我们可以通过网页包配置动态插入脚本标记吗

下面是我用来从我的index.html所在的公用文件夹中为bundle.js提供服务的网页包配置

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>