Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/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
Webpack 网页包4加载程序规则包括条件不工作_Webpack - Fatal编程技术网

Webpack 网页包4加载程序规则包括条件不工作

Webpack 网页包4加载程序规则包括条件不工作,webpack,Webpack,项目结构 hello-world-imba + dist - index.html + src + backend - server.imba + frontend - client.imba - package.json - webpack.config.js package.json { "name": "hello-world-imba", "version": "1.0.0",

项目结构

hello-world-imba
  + dist
     - index.html

  + src
     + backend
         - server.imba
     + frontend
         - client.imba

  - package.json       
  - webpack.config.js
package.json

{
  "name": "hello-world-imba",
  "version": "1.0.0",
  "description": "Hello World for Imba",
  "scripts": {
    "start": "imba src/backend/server.imba",
    "build": "webpack"
  },
  "keywords": [
    "imba"
  ],
  "author": "Jignesh Gohel",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.4",
    "imba": "^1.4.1",
    "webpack": "^4.29.0"
  },
  "devDependencies": {
    "webpack-cli": "^3.2.1"
  }
}
webpack.config.js

const path = require('path');

module.exports = {
    mode: 'development',
    entry: {
      app: path.resolve(__dirname, 'src/frontend/client.imba')
    },
    module: {
        rules: [
            {
                use: 'imba/loader',

                // Skip any files outside of project's following
                // directories:
                // `src/frontend`
                include: [
                    path.resolve(__dirname, 'src/frontend')
                ],

                // Only run `.imba` files through Imba Loader
                test: /.imba$/
            }
        ]
    },
    resolve: {
        extensions: [".imba",".js", ".json"]
    },
    output: {
        filename: "client.js",
        path: path.resolve(__dirname, 'dist')
    }
}
$ cat /home/jignesh/.npm/_logs/2019-01-25T13_52_15_689Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'build' ]
2 info using npm@6.7.0
3 info using node@v10.14.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle hello-world-imba@1.0.0~prebuild: hello-world-imba@1.0.0
6 info lifecycle hello-world-imba@1.0.0~build: hello-world-imba@1.0.0
7 verbose lifecycle hello-world-imba@1.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle hello-world-imba@1.0.0~build: PATH: <PATHS HERE>
9 verbose lifecycle hello-world-imba@1.0.0~build: CWD: /jwork/imba/hello-world-imba
10 silly lifecycle hello-world-imba@1.0.0~build: Args: [ '-c', 'webpack' ]
11 silly lifecycle hello-world-imba@1.0.0~build: Returned: code: 2  signal: null
12 info lifecycle hello-world-imba@1.0.0~build: Failed to exec build script
13 verbose stack Error: hello-world-imba@1.0.0 build: `webpack`
13 verbose stack Exit status 2
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid hello-world-imba@1.0.0
15 verbose cwd /jwork/imba/hello-world-imba
16 verbose Linux 3.13.0-135-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
18 verbose node v10.14.0
19 verbose npm  v6.7.0
20 error code ELIFECYCLE
21 error errno 2
22 error hello-world-imba@1.0.0 build: `webpack`
22 error Exit status 2
23 error Failed at the hello-world-imba@1.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]
src/backend/server.imba

var express = require 'express'
var server = express()

server.use(express.static('./dist'))

var port = process:env.PORT or 8080

var server = server.listen(port) do
    console.log 'server is running on port ' + port
tag App

    def render
        <self>
            <p> "Hello World"

Imba.mount <App>
src/frontend/client.imba

var express = require 'express'
var server = express()

server.use(express.static('./dist'))

var port = process:env.PORT or 8080

var server = server.listen(port) do
    console.log 'server is running on port ' + port
tag App

    def render
        <self>
            <p> "Hello World"

Imba.mount <App>
详细日志

const path = require('path');

module.exports = {
    mode: 'development',
    entry: {
      app: path.resolve(__dirname, 'src/frontend/client.imba')
    },
    module: {
        rules: [
            {
                use: 'imba/loader',

                // Skip any files outside of project's following
                // directories:
                // `src/frontend`
                include: [
                    path.resolve(__dirname, 'src/frontend')
                ],

                // Only run `.imba` files through Imba Loader
                test: /.imba$/
            }
        ]
    },
    resolve: {
        extensions: [".imba",".js", ".json"]
    },
    output: {
        filename: "client.js",
        path: path.resolve(__dirname, 'dist')
    }
}
$ cat /home/jignesh/.npm/_logs/2019-01-25T13_52_15_689Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'build' ]
2 info using npm@6.7.0
3 info using node@v10.14.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle hello-world-imba@1.0.0~prebuild: hello-world-imba@1.0.0
6 info lifecycle hello-world-imba@1.0.0~build: hello-world-imba@1.0.0
7 verbose lifecycle hello-world-imba@1.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle hello-world-imba@1.0.0~build: PATH: <PATHS HERE>
9 verbose lifecycle hello-world-imba@1.0.0~build: CWD: /jwork/imba/hello-world-imba
10 silly lifecycle hello-world-imba@1.0.0~build: Args: [ '-c', 'webpack' ]
11 silly lifecycle hello-world-imba@1.0.0~build: Returned: code: 2  signal: null
12 info lifecycle hello-world-imba@1.0.0~build: Failed to exec build script
13 verbose stack Error: hello-world-imba@1.0.0 build: `webpack`
13 verbose stack Exit status 2
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid hello-world-imba@1.0.0
15 verbose cwd /jwork/imba/hello-world-imba
16 verbose Linux 3.13.0-135-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
18 verbose node v10.14.0
19 verbose npm  v6.7.0
20 error code ELIFECYCLE
21 error errno 2
22 error hello-world-imba@1.0.0 build: `webpack`
22 error Exit status 2
23 error Failed at the hello-world-imba@1.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]
删除成功生成捆绑包的
npm run build
,并使用
npm run start
运行服务器,我也可以访问该应用程序

有谁能帮我理解问题是什么以及如何解决?假定指定的路径适用于
entry.app
选项,则该路径看起来是正确的。该网站的网页文档称

{include:Condition}:条件必须匹配。公约是 在此处提供字符串或字符串数组,但不强制执行


但它并没有以清晰的方式向我传达任何有意义的信息。请注意,我是基于节点开发的新手,因此如果我的问题听起来很愚蠢,请原谅我。

这里的问题是添加

include: [
  path.resolve(__dirname, 'src/frontend')
],
在加载程序的配置中,您指示它仅处理该目录下的文件。 我理解,这是有道理的,因为您只在那里编写代码,因此这似乎是正确的决定

尽管如您所见,webpack抱怨
/node\u modules/imba/imba.imba
,它不知道如何读取此文件。这是有道理的,因为它需要使用加载器,但我们明确地说,
imba/loader
应该只关心
src/frontend
下的文件,而不是
node_modules

我猜,即使您不直接在项目中导入此
imba库
,加载程序也会将其作为依赖项添加到项目中

最后,您只需输入配置即可

rules: [
            {
                use: 'imba/loader',
                test: /.imba$/
            }
]
这样,无论此文件位于何处,具有
.imba
后缀的每个文件都将通过此加载程序