Giter VIP home page Giter VIP logo

laravel-mix-wp-blocks's Introduction

Laravel Mix WP Blocks

Maintainability npm version

About

Laravel mix extension to transpile WordPress block scripts.

Installation

npm install @tinypixelco/laravel-mix-wp-blocks --save-dev
yarn add -D @tinypixelco/laravel-mix-wp-blocks

Usage

In webpack.config.js:

require("@tinypixelco/laravel-mix-wp-blocks");

mix.block("resources/assets/scripts/blocks.js", "scripts");

By doing so you'll find that you can now utilize all @wordpress scoped dependencies using ECMAScript 6 import syntax. Example:

import { RichText } from "@wordpress/block-editor";

These packages are included as webpack externals, so there is no reason to add them to your package file.

You will also find a php manifest file accompanying each script in your distribution directory. This file declares an array of dependencies based on what you've used in your scripts. Require it and you're set.

Additional Dependency Extraction Webpack Plugin options maybe be provided as a third argument to mix.block():

mix.block("resources/assets/scripts/blocks.js", "scripts", {
  outputFormat: "json",
});

Besides the plugin options there is a special flag for the common use case of turning off @babel/runtime/regenerator handling by wp-polyfill.

mix.block("resources/assets/scripts/blocks.js", "scripts", {
  disableRegenerator: true,
});

laravel-mix-wp-blocks's People

Contributors

joshuafredrickson avatar kellymears avatar oxyc avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-mix-wp-blocks's Issues

Requiring external library breaks all blocks on development

Hello,

we're trying to use Sage 10 in a new project which includes this dependency in their Laravel Mix configuration. Sadly though, requiring an external library breaks everything (silently, so I'm not even sure how to debug it).

I have forked Sage 10 and in this commit it everything works as expected:
2020-03-02-181712_667x221_scrot

then basically this was added (in this commit):

import classNames from 'classnames'

2020-03-02-181824_665x307_scrot

and now all blocks are broken. No error message in the console or anything.

This happens to only happen for development build, while production builds are not affected.

Issue with Babel

When using Laravel Mix mix.combine() method in the same project as laravel-mix-wp-blocks I get the following error:

[webpack-cli] Error: [BABEL] unknown: Preset /* your preset */ requires a filename to be set when babel is called directly,
babel.transform(code, { filename: 'file.ts', presets: [/* your preset */] });

Here is my webpack.mix.js file:

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

require('@tinypixelco/laravel-mix-wp-blocks');

mix.blocks('src/blocks.js', 'dist');

mix.combine('src/vendor', 'dist/vendors.js', true);

Here is my package.json:

{
  "name": "mix-new",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.mix.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@tinypixelco/laravel-mix-wp-blocks": "^1.1.0",
    "@wordpress/babel-preset-default": "^6.4.1",
    "@wordpress/dependency-extraction-webpack-plugin": "^3.2.1",
    "laravel-mix": "^6.0.39"
  }
}

I've tried it on two versions of Node I have installed (12.18.3 and 15.12.0) and I get the error on both of them. The only way I don't get the error is when I remove the third argument from mix.combine() which disables Babel. Using mix.babel() causes the same error.

Hope you can help.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/publish.yml
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json

  • Check this box to trigger a request for Renovate to run again on this repository

TypeError: Cannot set property 'bundlingJavaScript' of undefined

I get the following error in my project (based on the roots/sage 10.x branch):

โ†’ npx mix
[webpack-cli] TypeError: Cannot set property 'bundlingJavaScript' of undefined
    at Block.register (node_modules/laravel-mix/src/components/JavaScript.js:36:41)
    at Block.register (node_modules/@tinypixelco/laravel-mix-wp-blocks/index.js:51:11)
    at Object.components.<computed> [as blocks] (node_modules/laravel-mix/src/components/ComponentRegistrar.js:163:49)
    at Object.<anonymous> (webpack.mix.js:32:4)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)

My settings in the webpack.mix.js file are identical to roots/sage settings (again, 10.x branch).

In the devDependencies I'm using the latest version of your package and the latest version of Laravel Mix:

"devDependencies": {
  "@tinypixelco/laravel-mix-wp-blocks": "^1.1.0",
  "laravel-mix": "^6.0.19"
}

I've tried to compile it on two different versions of Node (v14.15.4 and v16.14.0) and I get the same error on both of them.

Hope you can help!

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.