简体   繁体   English

webpacker在heroku上无法正常工作

[英]webpacker not working correctly on heroku

I'm in the middle of upgrading an app from rails 3.2 to rails 4.2 using webpacker gem everything works fine in localhost I have compiled my assets and run 我正在使用webpacker gem将应用程序从Rails 3.2升级到Rails 4.2,在本地主机上一切正常,我已经编译了资产并运行

RAILS_ENV=production rails s RAILS_ENV =生产导轨

but I have errors when pushing to heroku it compiles all assets even the packs but generates errors in js, I use angular in many parts of the app and the error is related with dependency injection 但是当推送到heroku时我出错,它编译所有资源,甚至是包,但是在js中生成错误,我在应用程序的许多部分中使用angular,并且该错误与依赖项注入有关

check link 检查链接

The main problem here was the unglifier gem I had to coment the uglifier 这里的主要问题是我必须对丑化器进行注释的未发育成宝石的宝石

#config.assets.js_compressor = :uglifier

The next part was the configuration for webpack in production that look like this: 下一部分是生产中Webpack的配置,如下所示:

const webpack = require('webpack')
const { basename, dirname, join, relative, resolve } = require('path')
const merge = require('webpack-merge')
const CompressionPlugin = require('compression-webpack-plugin')
const sharedConfig = require('./shared.js')
const { env, settings, output, loadersDir } = require('./configuration.js')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const ManifestPlugin = require('webpack-manifest-plugin')

module.exports = merge(sharedConfig, {
  output: { filename: '[name]-[chunkhash].js' },
  devtool: false,//'source-map',
  stats: 'normal',

  plugins: [
    new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
    new ExtractTextPlugin({
      filename: '[name]-[hash].css',
      allChunks: true
    }),
    new ManifestPlugin({
      publicPath: output.publicPath,
      writeToFileEmit: true
    })
  ],

  resolve: {
    extensions: settings.extensions,
    modules: [
      resolve(settings.source_path),
      'node_modules'
    ],
    alias: {
     'vue$': 'vue/dist/vue.esm.js' // 'vue/dist/vue.common.js' for webpack 1
   }
  },

  resolveLoader: {
    modules: ['node_modules']
  }
})

Now I can deploy and the assets are working. 现在我可以部署并且资产正在运行。

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

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