【问题标题】:Build webpack on travis ci在 travis ci 上构建 webpack
【发布时间】:2016-10-22 13:56:05
【问题描述】:

我想通过这个命令为生产运行 webpack 构建:

"prod": "webpack -p --config webpack.production.config.js"

我的.travis.yml 文件:

language: node_js
node_js:
  - "6.9.1"

install:
  - npm i -g yarn && yarn

before_script:
  - yarn prod

deploy:
  provider: s3
  local-dir: public
  on:
    branch: cloudfront

但是这个脚本没有加载正确的文件,在 prod 网站上我看到了ENV=dev

我也试过这些命令:

before_deploy

script

但它没有帮助

webpack.production.config.js:

output: {
  path: path.join(__dirname, 'public'),
  filename: 'index.js',
  publicPath: '/'
},
new webpack.DefinePlugin({
 'process.env': {
   'BASE_URL': JSON.stringify('url'),
   'NODE_ENV': JSON.stringify('production')
 }
})

travis.log:

The command "npm test" exited with 0.
before_deploy
9.54s$ webpack -p --config webpack.production.config.js
Hash: 4aa1139f3ef3381f91ec
Version: webpack 1.13.2
Time: 9133ms
       Asset       Size  Chunks             Chunk Names
    index.js     176 kB       0  [emitted]  main
index.js.map  151 bytes       0  [emitted]  main
   [0] multi main 28 bytes {0} [built]
    + 255 hidden modules
dpl.2
Preparing deploy
dpl.3
Deploying application
uploading "index.html" with {:content_type=>"text/html"}
uploading "index.js.map" with {:content_type=>""}
uploading "index.js" with {:content_type=>"application/javascript"}
# HEAD detached at 8a81ecb
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   public/index.js
#
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (593621bc433e8223b3b5c32751122c23297b202e)
Done. Your build exited with 0.

【问题讨论】:

    标签: node.js travis-ci yarnpkg


    【解决方案1】:

    需要将此行添加到 .travis.yml:

    skip_cleanup: true
    

    对我有帮助

    【讨论】:

      【解决方案2】:

      即使您的 web pack 正在为生产生成一个捆绑包,这也不会改变您服务器上的环境。 ENV 在哪里设置?

      【讨论】:

      • 在 webpack 文件中,在 new webpack.DefinePlugin({ 中。如果我在本地机器上运行这个命令,一切正常
      • Webpack 仅在构建 bundle.js 时设置“环境”。在您的服务器上运行时,环境可能是服务器想要的任何东西。因此,当它为您的应用提供服务时,如果它将 ENV 设置为 dev,那么这就是您的环境将显示的内容。
      • 我在 ci 上构建,带有 -p 参数,所以在生产配置中我设置了这个变量
      • 你能显示它说 ENV 是 dev 的地方吗?你只是把它记录到控制台还是什么的?
      • link,在控制台中。问题是它需要从 repo 构建,而不是 ci
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      相关资源
      最近更新 更多