4

I want to use a webpack plugin in Vue using vue-cli but I don't want to install webpack, because Vue handles this...

Using this example, I try to use the Environment plugin from webpack.

module.exports = {
  configureWebpack: {
    plugins: [
      new EnvironmentPlugin([
        'HEROKU_RELEASE_VERSION']),
    ],
  },
};

But because we use vue-cli, I get :

EnvironmentPlugin is not defined

When I include the webpack requirement

const webpack = require('webpack')

module.exports = {
  configureWebpack: {
    plugins: [
      new webpack.EnvironmentPlugin([
        'HEROKU_RELEASE_VERSION']),
    ],
  },
};

I get :

Webpack should be listed in the project's dependencies. run npm install ....

2 Answers 2

12

The answer above is good. I got another one here, with building condition control.

const webpack = require('webpack');
module.exports = {
 configureWebpack: (config) => {
   if(process.env.VUE_APP_BUILD !== 'development'){
     // do something...
   }
   config.plugins = [
     ...config.plugins, // this is important !
     new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/) // new plugins...
   ]
 }

};

Sign up to request clarification or add additional context in comments.

2 Comments

This answer is much better as it's lazy and get ENVs injected
Exactly what I needed. Thanks
4

First you need to install webpack as dependency.

npm i --save-dev webpack

After that add the following to your vue.config.js.

const webpack = require('webpack')

module.exports = {
  configureWebpack: {
    plugins: [
      new webpack.EnvironmentPlugin([
        'HEROKU_RELEASE_VERSION',
      ]),
    ]
  }
}

1 Comment

No need to install webpack, it comes with vue-cli by default

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.