【问题标题】:Customize build directory in 'npm start' command在“npm start”命令中自定义构建目录
【发布时间】:2018-03-28 22:13:11
【问题描述】:

我在 Tomcat 网络服务器上使用 npm 和 web-pack 构建了 Angular 应用程序。

命令npm run build将所有JS文件构建到项目的/build目录中,但npm start使用/out目录。

有没有办法强制npm start 也使用/build 目录?

为什么我需要这个: 目前 JS 内容与用 Java 编写的后端一起提供,生产运行和开发运行之间没有区别(都使用相同的构建文件夹)。在前端也可以很方便。

更新:我通过增强 webpack 配置解决了这个问题

npm start 在后台运行 webpack,通过 .js 脚本配置。

我已更新部分:

output: {
    path: helpers.root('../build'),
    publicPath: '/',
    filename: '[name].js',
    chunkFilename: '[id].chunk.js'
}

指向./build 目录。

【问题讨论】:

    标签: javascript npm webpack npm-install npm-start


    【解决方案1】:

    您可以为此使用concurrently,在您的packages.json 中使用类似:

    "scripts": {
      "client": "cd build && npm start",
      "server": "cd out && npm start",
      "start": "concurrent \"npm run client\" \"npm run server\"",
    },
    "devDependencies": {
      "concurrently": "^3.5.0"
    }
    

    【讨论】:

    • 谢谢,我已经通过配置webpack解决了这个问题。在问题中找到我的更新。
    • @OleksandrShpota 您应该将其作为答案单独发布。
    猜你喜欢
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 2018-11-25
    • 2018-06-20
    • 1970-01-01
    • 2018-01-19
    • 2019-09-11
    • 1970-01-01
    相关资源
    最近更新 更多