Skip to content

Specify output filename in production build using webpack. #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
williamsharkey opened this issue Jun 18, 2017 · 1 comment
Closed

Specify output filename in production build using webpack. #501

williamsharkey opened this issue Jun 18, 2017 · 1 comment

Comments

@williamsharkey
Copy link

williamsharkey commented Jun 18, 2017

I want to specify the filename for a production build of a vue.js project that uses webpack, so that the bundled js file is not dynamically named client.[hash].js, but helloworld.js.

I created the project using vue init

Currently it outputs the following:

  • index.html
  • client.c4113ffa.js
  • client.c4113ffa.js.map

I used the command:
vue build src/main.js --prod

My webpack.config.js file is listed below. I added the a line near the end, expecting that it would output helloworld.js, but it had no effect. I saw an issue that I think address this issue, but I am unsure of how to take advantage of it ( #326 )

I apologize if I am posting this issue in the wrong place, perhaps it is an issue with UglifyJS?


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

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'

//ADDED THIS START
  module.exports.output.filename= 'helloworld.js'
//ADDED THIS END



    // http://vue-loader.vuejs.org/en/workflow/production.html
    module.exports.plugins = (module.exports.plugins || []).concat([
      new webpack.DefinePlugin({
        'process.env': {
          NODE_ENV: '"production"'
        }
      }),
      new webpack.optimize.UglifyJsPlugin({
        sourceMap: true,
        compress: {
          warnings: false
        }
      }),
      new webpack.LoaderOptionsPlugin({
        minimize: true
      })
    ])
}

@posva
Copy link
Member

posva commented Jul 11, 2017

You can already do this by modifying the webpack conf. There's nothing to be added on vue-cli end because this is something that can be customised in the template itself.

@posva posva closed this as completed Jul 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants