Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

midascodebreaker's avatar

Guide: Add webpack to Your Laravel-Elixir Ext for Vue Js Components

Since the majority of VueJS developers and Creator Even You are using Webpack...

And most of us Laravel developers are acquainted with Laravel Elixir as a Wrapper of Gulp....

We Find Trouble Using Webpack... But Not Anymore.

;) Grin...

Here is my Documented Step by Step Guide From Zero To Hero!

1.) Setting Up ENV Machine (Im Using Latest)

Node v5.10.1

npm v3.8.3

2.) Install Globally Gulp and Webpack

(Gulp version 3.9.1)

npm install --global gulp 

(Webpack 1.13.0)

npm install --global webpack

3.) Update Your Package.json File

and add the following dependencies

Note: vuestrap-theme-loader is optional only if you need to use kzim vuestrap components library

if you intend to use .vue file extension you need 3 dependencies

vue-loader vue-html-loader vue-style-loader

{
  "name": "run-webpack-inside-laravel-elixir",
  "version": "1.0.0",
  "description": "Dependencies to Use Webpack Extension inside Laravel Elixir",
  "license": "MIT",
  "private": true,
  "scripts": {
    "prod": "gulp --production",
    "dev": "gulp watch"
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "laravel-elixir": "^5.0.0"
  },
  "dependencies": {
    "laravel-elixir-webpack-ex": "0.0.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-stage-2": "^6.5.0",
     "babel-plugin-transform-runtime": "^6.8.0",
    "autoprefixer-loader": "^3.1.0",
    "babel-core": "^6.7.7",
    "babel-eslint": "^6.0.4",
    "babel-loader": "^6.2.4",
    "css-loader": "^0.23.1",
    "html-loader": "^0.4.3",
    "sass-loader": "^3.2.0",
    "style-loader": "^0.13.1",
    "vuestrap-theme-loader": "^0.1.2",
   "vue-loader": "^8.3.1",
    "vue-html-loader": "^1.2.2",
    "vue-style-loader": "^1.0.0"
  }
}

4.) Create .babelrc file

Add this inside .babelrc in your root folder

{
  "presets": ["es2015", "stage-2"],
  "plugins": ["transform-runtime"],
  "comments": false
}

5.) Update gulpfile.js

Note if You Dont Need Much Configuration You Dont Need to Pass in webpack.config.js first param (file to compile) 2nd param optional (webpack config) 3rd param optional (output folder) 4th param entry point folder

var elixir = require('laravel-elixir');
require('laravel-elixir-webpack-ex');

elixir(function(mix) {
        mix.webpack('vuestrap.js', require('./webpack.config.js'), 'resources/assets/js', 'resources/assets/webpack');

});

6.) Create webpack.config.js (if you need more configuration)

Note that Since We will be Using laravel elixir webpack extension We Need to Remove Entry Point and Output Inside webpack.config.js

Since we know laravel elixir webpack ext is using

Entry point Default

./resource/assets/js

Output Folder

./public/js

You can easily change this inside gulpfile.js as the third and 4th param Also if You Need More Power in your laravel-elixir-webpack extension

You can pass in the webpack.config.js as third param

for example , Im using a themeloader in my project (vuestrap) by kzima i can add it here ...

if i will simple use mix.webpack i cannot passon that themeloader object...

See the themeloader and the vuestraploader below

var path = require('path');

module.exports = {
  resolve: {
    root: path.resolve('./')
  },
  themeLoader: {
    themes: ['./resources/assets/sass/theme.scss', './node_modules/vuestrap/theme/bootstrap.scss'],
  },
  module: {
    loaders: [{
      test: /\.vue$/,
      loader: 'vue'
    }, {
      test: /\.js$/,
      loader: 'babel'
    }, {
      test: /\.html$/,
      loader: 'html'
    }, {
      test: /\.scss$/,
      loader: 'style-loader!css-loader!autoprefixer-loader!sass-loader!vuestrap-theme-loader'
    }]
  }
};

7.) in your App.js ...

The Usual Vue JS Dependencies

import Vue from 'vue'
import VueResource from 'vue-resource'
import VueRouter from 'vue-router';
// Import VueStrap Core That has the Core Sass Files of Boostrap Add What you Need
import 'vuestrap/core'
...
// Import The Components for Vuestrap Base Bootsrap 4
import navbar from 'vuestrap-base-components/src/components/navbar'
...
//import GritCode Components
import toast from 'gritcode-components/src/components/toast'
...
//import view components for Router
import default_view from '../components/default.vue'

// Use Vue Router
Vue.use(VueRouter)
// Use Vue Resource
Vue.use(VueResource)

var router = new VueRouter({})
router.map({
'*': {
          component: default_view
      }
})
var App = Vue.extend()

router.start(App, '#app')

new Vue({
el: '#app',
data: { },
components: {
'vs-navbar': navbar
}
 })

8.) Run Gulp ...

If you Love this Guide Show , Ill add more ... in the Future THANKS >;D

0 likes
16 replies
vincentveyrat's avatar

I was really hoping you post would save my life, but I fail using laravel, vue-strap and gritcode-components. All I got is a $export is not a function from babel-runtime :(

midascodebreaker's avatar

have you really follow from step 1? because mine is from fresh install.... maybe try to upgrade your installation ... please let me know , what you did...

Presto's avatar

Thanks for writing this tut. @midascodebreaker, after following your steps, when I run gulp, I don't get any errors, in terminal but I get the following error in Chrome DevTools:

app.js:55 Uncaught SyntaxError: Unexpected token import

On line 55 in app.js:

import Vue from 'vue';
Presto's avatar

Ok I tweeked my webpack.config.js file and got past that error now I'm getting the same error as @phoenixcorp is getting. @phoenixcorp were you able to get it working?

Currently getting the following error:

Uncaught TypeError: $export is not a function

On line 2164:

  $export(
    $export.S + $export.F * !__webpack_require__(34), 
    'Object', {
      defineProperty: __webpack_require__(30).f
    }
  );
midascodebreaker's avatar

change .babelrc file from

{
  "presets": ["es2015", "stage-2"],
  "plugins": ["transform-runtime"],
  "comments": false
}

to

{
"presets": ["es2015"]
}

Problem could be from this configuation, but i really wonder why this is happening...

maybe the nodejs already have this transformer on the run...

but i have other installation that dont haave problem with the transformer turn on...

For now do this... fix

mehrancodes's avatar

Thanks @midascodebreaker for your tut!

I followed it step by step and even fixed some errors but still had 1 more error!

So While I was googling for that error, I found a GitHub repo (Also thanks to dolbex) that has guided me how to successfully integrate vue-cli with my Laravel project!! Yea that works perfectly!

1 like
davestewart's avatar

Has anyone noticed any speed differences between Webpack and Browserify / Elixir?

I'm finding the compilation times in BS/E to be quite frustrating. Waiting 2 or 3 seconds after each change is pretty tiresome; I would love to get back to a setup where I can see results almost instantly.

1 like
EmilMoe's avatar

Webpack + Rollup.js is supposedly faster

davestewart's avatar

Oh brilliant; another build system to get my head around! Thanks Emil.

mehrancodes's avatar

@EmilMoe Do ya have any article/guide about how to use Rollup.js and Webpack For laravel ? Or we should wait until Jeffrey will release a new version of elixir?

EmilMoe's avatar

I haven't unfortunately.

I saw Evan You writing on Twitter that this combination is faster and Jeffrey asked for advices on Twitter and I linked him to Evans update and it seems Webpack is gonna be default from v6 of Elixir, so my assumption is that Jeffrey is going to make a similar setup.

1 like
erikwestlund's avatar

@miran, I'm using it now. I just updated my package.json to 6.0.0.0 and things more or less just work. working out some webpack bugs but so far so good!

Please or to participate in this conversation.