Webpack footer.js未执行

qaxu7uf2  于 2023-10-19  发布在  Webpack
关注(0)|答案(1)|浏览(121)

我正在使用webpack来运行我的web应用程序。今天,我的web.js突然停止工作,我想弄清楚为什么。
以下是我的webpack.config.js

const path = require('path');

module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.(js|html)$/, // Use a regex pattern to match both .js and .html files
        enforce: "pre",
        use: ['source-map-loader', 'html-loader'],
      },
    ],
  },
  ignoreWarnings: [/Failed to parse source map/],
  watch: true,
};

以下是我的层次结构:

-public
  -dist
    -bundle.js
  -src
    -index.js
index.html

下面是我的index.html

<html>
  <head></head>
  <body>
    <script src="./dist/bundle.js"></script>
  </body>
</html>

我的index.js

console.log('You won't see this');

即使是一个简单的console.log也不会执行。我做错了什么?
谢谢你,谢谢!

oalqel3c

oalqel3c1#

找到了解决方案:
我将webpack.config.js模块更改为:

module: {
    rules: [
      {
        test: /\.html$/, // This pattern will only apply the loaders to .html files
        use: ['html-loader']
      },
      {
        test: /\.js$/, // This pattern will only apply the loaders to .js files
        enforce: "pre",
        use: ['source-map-loader'],
      },
    ],
  },

相关问题