Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.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/4/webpack/2.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 网页包未重新导出值_Javascript_Webpack - Fatal编程技术网

Javascript 网页包未重新导出值

Javascript 网页包未重新导出值,javascript,webpack,Javascript,Webpack,刚开始直接使用Webpack,我很难将导入的代码包含到包中。为了测试,我有两个文件 index.js: export const stringFromIndex = 'string-abc'; export { somestring } from './testModule.js' testModule.js: export const someString = 'string-123'; 当我运行webpack时,“string abc”在创建的包中,但“string-123”不在。我的

刚开始直接使用Webpack,我很难将导入的代码包含到包中。为了测试,我有两个文件

index.js:

export const stringFromIndex = 'string-abc';

export { somestring } from './testModule.js'
testModule.js:

export const someString = 'string-123';
当我运行webpack时,“string abc”在创建的包中,但“string-123”不在。我的webpack.config.js如下:

const path = require('path');

require ('script-loader');

module.exports = {
  mode: 'development',
    entry: './index.js',
    output: {
        filename: 'output.js',
        path: path.resolve(__dirname),
    },
    module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: 'script-loader'
          }
        ]
      }
    ]
  }
}
我是配置webpack错误,还是我误解了捆绑包中的内容?如果我使用的是使用webpack的东西(主要是Vue CLI),而没有分块/延迟加载,那么所有内容都会进入创建的JS文件中。这就是我在这里努力实现的目标

Web包运行的输出为:

Hash: 6e6474a0bc8438c6fdd8
Version: webpack 4.41.2
Time: 83ms
Built at: 03/07/2020 12:25:02 PM
    Asset      Size  Chunks             Chunk Names
output.js  5.71 KiB    main  [emitted]  main
Entrypoint main = output.js
[./index.js] 231 bytes {main} [built]
[./node_modules/script-loader/node_modules/raw-loader/index.js!./index.js] ./node_modules/script-loader/node_modules/raw-loader!./index.js 115 bytes {main} [built]
    + 1 hidden module

我有一个要点:

您的testModule.js中有一些字符串,但是您导入了一些字符串(没有camelCase)。你能试着在两个地方使用相同的名称吗?修复了这个问题,但在重新运行webpack后output.js中仍然没有“string-123”。你为什么要使用脚本加载器?因为我是webpack的新手,认为每个文件都需要一个加载器类型。删除脚本加载器可以使它完美地工作。谢谢