Giter VIP home page Giter VIP logo

mohamedlamineallal / laravel-mix-webpack-config Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 146 KB

A laravel mix extension that allow us to get the webpack config as an object and with a second argument that provide the circularStringify function that help with stringification. So we do whatever we want with it. Including writing to files. Unlike dump() component. The extension does patch dump() and dumpWebpackConfig() as well to take that callback as well.

JavaScript 4.90% TypeScript 95.10%
dump laravel-mix laravel-mix-extension string webpack-config

laravel-mix-webpack-config's Introduction

Laravel mix WebpackConfig extension

A laravel mix extension that allow us to get the webpack config as a string. So we do whatever we want with it.
Including writing to files. Unlike .dump() component that only print to console.

Also the extension does patch .dump() and dumpWebpackConfig() to take a callback that return the config.

// without dumping the config
mix.getWebpackConfig((config, stringify) => {
  fs.writeFileSync('webpackConfig.output.js', stringify(config));
});

// with dumping the config (patched)
mix.dump((config, stringify) => {
  fs.writeFileSync('webpackConfig.output.js', stringify(config));
});

// or
mix.dumpWebpackConfig((config, stringify) => {
  fs.writeFileSync('webpackConfig.output.js', stringify(config));
});

Links

npmjs: https://www.npmjs.com/package/laravel-mix-webpack-config
laravel-mix extensions: https://laravel-mix.com/extensions/webpack-config

Installation:

I suggest using pnpm

pnpm

pnpm add laravel-mix-webpack-config -D

npm

npm install laravel-mix-webpack-config -D

yarn

yarn add laravel-mix-webpack-config -D

Usage Example:

const mix = require('laravel-mix');
const fs = require('fs');

require('laravel-mix-webpack-config');

const public_dir = 'public';

mix
  .setPublicPath(`${public_dir}`)
  .js(`${public_dir}/src/app.js`, `${public_dir}/dist`)
  .vue()
  .version([`${public_dir}/src/index.js`])
  .extract(['vue'], `dist/v.js`)
  .getWebpackConfig((config, stringify) => {
    fs.writeFileSync('webpackConfig.output.js', stringify(config));
  });

You can see it allow us to write the config to a file:

mix.getWebpackConfig((config, stringify) => {
  fs.writeFileSync('webpackConfig.output.js', stringify(config));
});

Take a callback as a param. With signature:

(
  webpackConfig: WebpackDomain.Configuration,
  stringify: DumpWebpackConfig['circularStringify'],
) => void;

webpackConfig: the final webpack config as an object.
stringify: Same circular stringify function that is implemented in the Dump component (when you use .dump()). So you expect to get the same string as the one used by .dump() logging component.

Giving this structure. You can do whatever you want with the object. Including something involving stringify like writing to a file.

Patching dump() and dumpWebpackConfig()

dump() and dumpWebpackConfig() are patched. So they take the same callback. With the same signature. They keep working as before. Plus that callback as an extra part of the patch.
dump(), dumpWebpackConfig() => dump the config to the console + can get the config as well to do something with it. Like writing to a file.

Aliases

You can use any of the bellow Aliases in place of getWebpackConfig().

.getWebpackConfig()
.listenWebpackConfig()
.lwc()

laravel-mix-webpack-config's People

Contributors

mohamedlamineallal avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.