简体   繁体   English

无法将两个文件与Webpack捆绑在一起

[英]Can not bundle two files with webpack

I have the following webpack configuration file, where I'm trying to make two bundle files for two separate projects: 我有以下webpack配置文件,在这里我试图为两个单独的项目制作两个捆绑文件:

var webpack = require('webpack');
var path = require('path');

var INDEX_BUILD_DIR = path.resolve(__dirname, 'src/client/app/public');
var INDEX_APP_DIR = path.resolve(__dirname, 'src/client/app/');
var RESULTS_BUILD_DIR = path.resolve(__dirname, 'src/client/results/public');
var RESULTS_APP_DIR = path.resolve(__dirname, 'src/client/results/');

var config = {
  entry: {
    INDEX_BUILD_DIR: INDEX_APP_DIR,
    RESULTS_BUILD_DIR: RESULTS_APP_DIR
  },
  output: {
    path: './',
    filename: '[name].js'
  },
  module : {
    loaders : [
      {
        test : /\.jsx?/,
        include : [INDEX_APP_DIR, RESULTS_APP_DIR],
        loader : 'babel'
      }
    ]
  }
};

module.exports = config;

I made this structure after looking here: 在查看以下内容后,我制作了以下结构:

https://github.com/webpack/webpack/issues/1189 https://github.com/webpack/webpack/issues/1189

However, I am getting this issue: 但是,我得到这个问题:

ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' path/to/project/src/client/app in /path/to/project

I can't understand where the issue originates from. 我不明白问题的根源。

Also, only one file is created named "RESULTS_BUILD_DIR.js" which means that a variable is interpreted literally. 同样,仅创建一个名为“ RESULTS_BUILD_DIR.js”的文件,这意味着将按字面意义解释变量。

What causes these problems? 是什么原因导致这些问题?

There are 2 things: 有两件事:

  1. Error in entry: you're pointing a path to module, so you have to have an index.js file in path/to/project/src/client/app as well as in src/client/results/ 输入错误:您指向模块的路径,因此必须在path / to / project / src / client / app以及src / client / results /中都有一个index.js文件
  2. RESULTS_BUILD_DIR.js yes, this notation filename: '[name].js' says "put the name of the entry and add dot and js - and this would be a result filename" RESULTS_BUILD_DIR.js是的,此表示法文件名:'[name] .js'说“输入条目名称并添加点和js-这将是结果文件名”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM