webpack-dev-server:“找不到script.js 404”

时间:2019-11-14 07:36:05

标签: javascript webpack

// public/index.html

<h1 id="headline">testing serving an index.html file</h1> // renders
<script src="testScript.js"></script>  // GET http://localhost:3000/public/testScript.js net::ERR_ABORTED 404 (Not Found)

testScript.js也在公共文件夹中,因此我不确定为什么开发服务器可以找到并呈现index.html而不是它的依赖脚本。有人知道为什么吗?这是我的全部  webpack.config.js

  

项目在http://localhost:3000/「wds」中运行:webpack输出   从/「wds」提供:非webpack的内容从   / home / owner / PhpstormProjects / app / buyUsed / public

const webpack = require("webpack");
const dotEnvWebpack = require("dotenv-webpack");
const path = require("path");

const webpackConfiguration = {
  entry : {
    productFlow : "./frontEnd/productFlow/index.tsx"
    , adminArea : "./adminArea/index.tsx"
  }
  , output : {
    filename : "public/[name].output.js"
    , path : path.resolve(__dirname, "")
  }
  , watch : true
  // , watchOptions : { aggregateTimeout : 300 }
  , devtool : 'inline-source-map'
  , mode : "development"
  , devServer : {
    port: 3000
    , contentBase : [path.join(__dirname, 'public')]
    , hot : true
    , historyApiFallback : true
  }
  , plugins : [
    new webpack.HotModuleReplacementPlugin(),
    new dotEnvWebpack
  ]
  , node : {
    fs: "empty" // needed for dotenv to work correctly
  }
  , resolve : { extensions : ['.ts', '.tsx', '.js'] }
  , module : {
      rules : [
        {
        test : /\.ts(x?)$/
        , use : {
          loader: 'awesome-typescript-loader'
        }
        , exclude : [/node_modules/, /outputScripts/, /\.dependabot/, /\.next/, /\.idea/, /lib/, /pages/, /\.dependabot/]
      }, {
        enforce : 'pre'
          , test : /\.js$/
          , loader : 'source-map-loader'
        }
      ]
  }
};

module.exports = webpackConfiguration;

0 个答案:

没有答案