Giter Site home page Giter Site logo

swashata / wp-webpack-script Goto Github PK

View Code? Open in Web Editor NEW
403.0 12.0 56.0 48.08 MB

๐Ÿ’ฅ๐Ÿ”ฅ๐Ÿ“ฆ๐Ÿ‘ฉโ€๐Ÿ’ป An easy to use, pre configured, hackable webpack setup & development server for WordPress themes and plugins.

Home Page: https://wpack.io

License: MIT License

JavaScript 25.84% HTML 1.29% TypeScript 64.87% Less 0.57% SCSS 4.65% Handlebars 2.78%
wordpress-development wordpress babel webpack browser-sync bundler

wp-webpack-script's Introduction


visit our website wpack.io for documentation and usage

wpack.io - Modern JavaScript tooling for WordPress

Backers on Open Collective Sponsors on Open Collective Build Status codecov npm version npm download cypress dashboard

What is wpack.io?

Put simply, wpack.io is a nodejs based build tool to ease up using modern javascript in WordPress Themes and Plugins. It gives a fine Developer Experience (DX) and a single dependency for all your bundling requirement.

It is a fine-tuned webpack/browser-sync configuration made specifically for WordPress Theme and Plugin Development.

With the rise of Gutenberg editor, the usage of modern JavaScript and libraries like react is imminent. The goal of this tooling is to:

  • โœ… Provide out of the box compiling and bundling of all front-end assets.
  • โœ… Give best in class Developer Experience (DX).
    • Hot Module Replacement and Live Reload.
    • Compile files on save.
    • Work on any local development server.
  • โœ… Support modern and useful concepts like modules, tree-shaking, dynamic import etc.

and eliminate the pain points such as:

  • โŒ Boilerplate for setting up your project.
  • โŒ Doing a lot of configuration to setup webpack.
  • โŒ A lot of things to hook webpack with browsersync. We can not safely have webpack dev server because it doesn't reload for PHP files.
  • โŒ A lot of dependencies like babel, webpack loaders and what not.

What is supported out of the box

  • ๐Ÿ‘‰ Have Create React App like developer experience for WordPress Plugin/Theme development.
  • ๐Ÿ‘‰ Consume all the modern packages from npm registry.
  • ๐Ÿ‘‰ Write javascript with modern ES2018 (ES6+) syntax and compile it down to ES5 (or in accordance to your .browserslistrc).
  • ๐Ÿ‘‰ Automatically minify and bundle code with webpack.
  • ๐Ÿ‘‰ Split large files automatically and have PHP library to wp_enqueue_script all generated parts.
  • ๐Ÿ‘‰ Use SASS/SCSS language to create stylesheets.
  • ๐Ÿ‘‰ Use postcss autoprefixer to automatically make your CSS work with needed vendor prefixes.
  • ๐Ÿ‘‰ Implement all the above to your existing wamp, mamp, vvv (basically any) dev server.
  • ๐Ÿ‘‰ Create production grade, super optimized and minified files with one command (hello CI).

Here are a few more bonus you get for using wpackio.

  • ๐Ÿ˜Ž Using ES6 Modules you will never run into namespace collision.

    Remember when that third-party plugin was using that old version of foo library which caused your system to completely fail? No more!.

  • ๐Ÿ˜Ž Zero configuration for a sane default of all the tooling involved (babel, sass, webpack).
  • ๐Ÿ˜Ž Your CSS/SCSS changes will reflect instantly.
  • ๐Ÿ˜Ž Typescript and Flowtype to take your js carrier to the next level. This tooling itself is written in typescript ๐Ÿ˜‰.
  • ๐Ÿ˜Ž All the stuff you need to start developing using react. Hello Gutenberg!

Getting Started

Everything is documented in our website.

TL;DR

  • Add @wpackio/scripts to a project by running this.
    npx @wpackio/cli
    and after that
    npm run bootstrap
  • Edit the wpackio.project.js file to write your javascript entry-points.
  • Use wpackio/enqueue from composer to consume the assets.
  • Start the server using npm start.
  • Create production file using npm run build.

How wpack.io solves the problems?

Behind the scene wpack.io uses webpack along with browsersync.

It doesn't concern itself with providing boilerplate or starter templates. It assumes that you (the awesome developer ๐Ÿ‘จโ€๐Ÿ’ป || ๐Ÿ‘ฉโ€๐Ÿ’ป) is already doing that and what you want is a simple to configure, yet hackable to the core tooling for bundling all your frontend assets (js, css, images, svgs) in the most optimized way and make it work within your WordPress theme or plugin.

Keeping that in mind, wpack.io provides three dependencies for your projects:

  1. @wpackio/entrypoint - As main dependency of your package.json.
  2. @wpackio/scripts - As main dev dependency of your package.json.
  3. wpackio/enqueue - As main dependency of your composer.json.

The first handles all the tasks for building the assets and providing a damn good DX.

The second handles enqueuing the assets using WordPress' API (wp_enqueue_script and wp_enqueue_style).

Both the tools communicate with each other through the means of manifest.json file. The first tell the later which files to consume and the later publicPath to the first.

See it in action

We have examples inside examples directory of this repo. Each of them has instructions in the readme file, so be sure to check out.

npx @wpackio/cli

Add wpack.io into any existing or new project. This command has to be run from within the project.

npm run bootstrap / yarn bootstrap

Bootstrap needed dependencies, dev dependencies according to the type of your project. This command is enabled by npx @wpackio/cli.

Setup JS entry-points

Talking about example in plugins, we setup the entry-points in wpackio.project.js file.

module.exports = {
	// Project Identity
	appName: 'wpackplugin', // Unique name of your project
	type: 'plugin', // Plugin or theme
	slug: 'wpackio-plugin', // Plugin or Theme slug, basically the directory name under `wp-content/<themes|plugins>`
	// Used to generate banners on top of compiled stuff
	bannerConfig: {
		name: 'WordPress WebPack Bundler',
		author: 'Swashata Ghosh',
		license: 'GPL-3.0',
		link: 'https://wpack.io',
		version: '1.0.0',
		copyrightText:
			'This software is released under the GPL-3.0 License\nhttps://opensource.org/licenses/GPL-3.0',
		credit: true,
	},
	// Files we need to compile, and where to put
	files: [
		// App just for showing react
		{
			name: 'reactapp',
			entry: {
				main: ['./src/reactapp/index.jsx'],
			},
		},
	],
	// Output path relative to the context directory
	// We need relative path here, else, we can not map to publicPath
	outputPath: 'dist',
	// Project specific config
	// Needs react?
	hasReact: true,
	// Needs sass?
	hasSass: true,
	// Externals
	externals: {
		jquery: 'jQuery',
	},
	// Webpack Aliases
	alias: undefined,
	// Show overlay on development
	errorOverlay: true,
	// Auto optimization by webpack
	// Split all common chunks with default config
	// <https://webpack.js.org/plugins/split-chunks-plugin/#optimization-splitchunks>
	// Won't hurt because we use PHP to automate loading
	optimizeSplitChunks: true,
	// Usually PHP and other files to watch and reload when changed
	watch: 'inc/**/*.php',
	// Hook into babeloverride so that we can add react-hot-loader plugin
	jsBabelOverride: defaults => ({
		...defaults,
		plugins: ['react-hot-loader/babel'],
	}),
};

Setup PHP Library to consume build files

Now we do

composer require wpackio/enqueue

to install PHP Consumer Library. We instruct it to load files the right way (using WordPress APIs like wp_enqueue_script and wp_enqueue_style).

<?php
/*
Plugin Name: WPackIo Sample
Plugin URI: https://wpack.io
Description: A sample to demonstrate wpackio
Version: 0.1.0
Author: Swashata Ghosh
Author URI: https://swas.io
Text Domain: wpack-io
Domain Path: /languages
*/
// Assuming this is the main plugin file.

// Require the composer autoload for getting conflict-free access to enqueue
require_once __DIR__ . '/vendor/autoload.php';

// Do stuff through this plugin
class MyPluginInit {
	/**
	 * @var \WPackio\Enqueue
	 */
	public $enqueue;

	public function __construct() {
		// It is important that we init the Enqueue class right at the plugin/theme load time
		$this->enqueue = new \WPackio\Enqueue( 'wpackplugin', 'dist', '1.0.0', 'plugin', __FILE__ );
		// Enqueue a few of our entry points
		add_action( 'wp_enqueue_scripts', [ $this, 'plugin_enqueue' ] );
	}


	public function plugin_enqueue() {
		// Enqueue the `main` entry from `reactapp` file entry.
		$this->enqueue->enqueue( 'reactapp', 'main', [] );
	}
}


// Init
new MyPluginInit();

npm start / yarn start

After configuring all entry-points and using the PHP library for consuming, we start the development server.

HMR

We edit the files and with proper setup, we can see things load live, without page refresh. It is called, Hot Module Replacement (HMR).

In the above image we see, we are changing the label of from Todo App to Awesome todo. The changes are reflected live on the page, without any page-reload.

Stop Dev Server

Once done, we press Ctrl + c to stop it.

npm run build / yarn build

Now we create production build.

Our plugin/theme is now ready to go live.

Learn more

This Readme is not an extensive source of documentation. Please visit our website wpack.io to learn more.

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer].


Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]. (please ask your company to also support this open source project by becoming a sponsor).


wp-webpack-script's People

Contributors

adambrgmn avatar renovate-bot avatar robsonsobral avatar ruelluna avatar swashata avatar triliput 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  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  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  avatar

Watchers

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

wp-webpack-script's Issues

Accept a function in `"files[n].webpackConfig"`

We can accept a function with following call signature in files[n].webpackConfig

(config:webpack.Configuration, merge: merge) => webpack.Configuration

It will pass the calculated configuration from system and would expect a modified configuration from userland.

Improve typechecking

  • Add explicity hasTypeScript in FileConfig to explicitly enable or disable typechecking for a file entry.
  • Add typeWatchFiles to report for corresponding files (userland).
  • Add docs.

Use project babel.config.js file if present

Right now, we do not use any babel.config.js file or .babelrc file at all. From the babel loader, we just ignore them.

While this works for small or quick projects, large projects could have some shortcoming. For example, one would have to dig through the code to properly create a similar babel.config.js for writing tests. In any case, the following approach might be good.

  1. Do not change functionality if babel.config.js is not present.
  2. If babel.config.js is present, then don't do any babel configuration from @wpakckio/scripts. Instead delegate the config to user.

This would also mean that we would need to

  • Provide and document proper usage of @wpackio/babel-preset-default.
  • Add examples and maybe create a stub file.

Update maintenance

  • Add optional chaining to babel config.
  • Update ESLint to v6 and airbnb config.
  • Disable some react and file related airbnb rules. Check ongoing projects.

Project Structure

NPM Packages

We will use lerna for having a mono-repo. We will have two major packages:

  1. wpws-cli to install wpws-scripts into project.
  2. wpws-scripts to actually do all the things.

Composer Packages

We will have one single composer package right now

  1. wpws-enqueue to handle all enqueue and providing publicpath along with user provided data. This will heavily use WordPress APIs.

webpack postcss and css import order of operation

Hello,

I'm noticing that when using postcss-preset-env with css imports wherein custom properties and custom media queries are defined in external files, the post-css plugins are not finding the variable definitions.

It seems as tho the post-css plugins are running on the individual css files before the imports are resolved, and thus are not finding the variable declarations in the external files.

If i declare the variables and custom media inside of the same css file, the plugin transformation is executed as expected. However, if those same variables are declared in an external file and imported, the plugin transformation does not work.

Do you have suggestions on best approach to a webpack and/or postcss config that ensures that the imports are available to postcss?

thank you!

SVGO example outputs wrong path at build for SVG loaded via SCSS

Using the SVGO example from the documentation, I get the wrong paths in compiled CSS when referencing SVG files. Dev server works fine.

To make sure this wasn't just something dumb I was doing, I created a minimal theme based on the example theme and added an svg background to the body.

Files

wpackio-theme
 |
 +-- src
 |  |  
 |  +-- theme
 |  |  |
 |  |  + heart.svg
 |  |  + main.js
 |  |  + main.scss

wpackio.project.js (copied straight from documentation)

webpackConfig: (config, api) => {
	// Create a new config
	const newConfig = { ...config };
	// Extend the rules for some great svg experience
	newConfig.module.rules = [
		...newConfig.module.rules,
		// SVGO Loader
		// https://github.com/rpominov/svgo-loader
		{
			test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
			use: [
				{ loader: 'file-loader' },
				{
					loader: 'svgo-loader',
					options: {
						plugins: [
							{ removeTitle: true },
							{ convertColors: { shorthex: false } },
							{ convertPathData: false },
						],
					},
				},
			],
		},
	];
	// Return it
	return newConfig;
},

main.scss

body {
  background-image:url('heart.svg');
}

CSS output using dev server: (THIS WORKS!)

body {
  background-image: url(//localhost:3000/wp-content/themes/wpackio-theme/dist/5e1d0848e37267eb1456fa12bee167f9.svg);
}

CSS output using build (PATH IS WRONG)

body {
  background-image: url(5e1d0848e37267eb1456fa12bee167f9.svg);
}

Compile node_modules

Not all node_modules packages come compiled to ES5 or the target. Just like CRA, it would be good if we transform node_modules as well.

Fix webpackJsonp and runtime for multiple entry

There could always be multiple entry from same plugin/theme or different plugin/theme. We need a way to handle it.

  • Use an unique output.jsonpFunction so that they don't override each other.
  • Have optimization.runtimeChunk, set to single. This will generate one runtime chunk for all entrypoints.
  • Have PHP load the runtime only once.

Feature Request: wpackio-scripts watch

Would it be possible to have an extra command like

wpackio-scripts watch

that does pretty much what build does but keep watching for file changes and recompile?

The fact that wpackio-scripts start does not output any files on the filesystem while it runs gives me a bit the chills, when I imagine a possible power outage after hours of developing.
And yes I know UPS exist :)
But since watch mode is already included in webpack, why not have a command that does that?

Please consider it. :)
Thank you

How to work with static files ?

Hello,

I am setting up wpack.io in a new Wordpress Starter with Bedrock & Timber. I've extended the Webpack config to add a first plugin : SVG Spritemap Plugin. At the moment everything is perfect and fast :)

Now the next step is to handle images / static files, but i dont know in which way to go ^^ and i found nothing in the documentation :/

I would like to view static files during development and have a compression when compiling to production.

I was thinking about a static folder in src/theme (or maybe better at the theme root) and extend Webpack config to copy+compress it in dist/ folder when compiling for production. You think it is good or there is a better way ?

EDIT: hum, no it's not a good solution because it would be necessary to change the path to /dist in all templates ๐Ÿ˜…
Well i guess, i'm going to keep all the static files in a static folder at the root of the theme and compress files inside when compiling to production..

Thanks :)

Feature freeze tests

** unit/intg tests**

The scripts is very low on test. While I am not super focused on e2e cli tests right now, I do need these

  • Test everything inside configs.

e2e idea

  • Test everything inside scripts.
  • Tests for files inside bin.
  • Create a server (serve) and run wpackio/scripts on top of it.
  • Use cypress to check files.
  • Change content of a file.
  • Use cypress to check reload/hmr.

outputPath as subfolder

Thanks for great toolkit!
If I use subfolder as an output path outputPath: 'assets/built' it breaks the dynamic import functionality because of the wrong variable name.

/* wpack.io publicPath */
window.__wpackIotestassets/built='https://www.wp.local/wp-content/themes/test/assets/built/';
window["__wpackIo".concat("test").concat("assets/built")]

I think appname and outputPath should be escaped/sanitized.
For example, WP has sanitize_key() function for this.

jsBabelOverride

Hey there, and first: thanks for the great project you've created.

I'm currently struggling with the wpackio.project.js file. Especially with the jsBabelOverride attribute. I wanted to integrate the @wordpress/babel-plugin-makepot but it seems that it's not executed.

This is the file I'm currently working with:

module.exports = {
	...
	useBabelConfig     : false,
	// Hook into babeloverride so that we can add react-hot-loader plugin
	jsBabelOverride    : defaults => {
		return {
			...defaults,
			plugins: [
				[ '@wordpress/babel-plugin-makepot', {
					output: 'myplugin.pot'
				} ],
				'react-hot-loader/babel',
			],
		};
	},
};

Can anyone help on this?

Proxy as https url returns empty response

I have a local working https://wordpress.local with a valid autogenerated local ssl certificate (green lock in all browsers), but if i try to configure wpackio.server.js this way:

	host: 'localhost',
	proxy: 'https://wordpress.local',
	port: 3000,

i got empty response.

I'm on linux using latest master version (with latest version of all packages).

I'm not a browser-sync/webpack-dev-server expert, so surely i'm missing something, but is it possible to develop in https environment with wpack?

Thanks in advance

Improvements for v3.0.0 - v3.1.0

  • Make timestamp HH:ii:ss format. Right now, anything doesn't pad correctly like ๏ฝขwpack.io 20:33:4๏ฝฃ.
  • Notify on browserSync reload (possibly).
  • See if we can show compilation time in success message.

Better CLI output

We can make the CLI output slim, especially the logo. It is just too huge.

Dependency deprecation warning: @types/chalk (npm)

On registry https://registry.npmjs.org/, the "latest" version (v2.2.0) of dependency @types/chalk has the following deprecation notice:

This is a stub types definition for chalk (https://github.com/chalk/chalk). chalk provides its own type definitions, so you don't need @types/chalk installed!

Marking the latest version of an npm package as deprecated results in the entire package being considered deprecated, so contact the package author you think this is a mistake.

Affected package file(s): packages/cli/package.json

If you don't care about this, you can close this issue and not be warned about @types/chalk's deprecation again. If you would like to completely disable all future deprecation warnings then add the following to your config:

"suppressNotifications": ["deprecationWarningIssues"]

Create documentation

  • Finish up writing the basic docs.
  • Create a gatsby site using one of the starter template.
  • Move the basic doc files into the site.
  • Host the site with netlify at wpack.io

Updating the scripts.

Hello. Thank you for these excellent scripts. I just wanted to ask how should we handle the updating of the script, for when our project was created some time ago?

Thank you in advance.

Better bootstrap error message

We basically need to rewrite the error output during bootstrap.

The target is to return better error messages during require project and server config files.

  • if no wpackio.project.js is found.
  • if no wpackio.server.js is found.
  • when files under wpackio.project.js is empty.
  • when the items under files doesn't match the schema.

Improve asset naming

While on development mode, it is cool to have regular [name].[ext].

But for production, we can optimize with [name]-[hash:6].[ext]. It will bust cache.

Responsibility of the PHP Script

  1. Read webpack manifest or custom config and figure out the relative path to enqueue (depending on whether it's a plugin or theme).
  2. Provide data to the entry point about publicPath #1

Shorten site topics

Right now, in the sidebar, we show the full title of the article, it messes up with algolia and also doesn't look good in the sidebar. We can have it fixed by defining a new frontmatter shortTitle in the docs and showing that instead.

EntryPoint handle for wp_localize_script()

How does wpack.io handle localisation of strings within the scripts?

Using a vanilla WordPress install, one can do wp_localize_script('scriptHandle', 'globalVariable', $array);

But now that wpack.io takes over the registration and enqueueing of the assets, how can we know the handle of a specific script so we can call wp_localize_script() on it?

proxy client side urls

When rendering site permalinks on the client side, the absolute urls are not mapped back to the wpack.io proxy server.

For example, using the REST api to retrieve post data, peramlinks are returned relative to the local wp dev server. When these links are rendered on the client, the do not get proxied to the wpack.io server and so following the url will ink out of the wpack.io server proxy.

To be clear: if my dev server is hosted at http://wp-dev.test and is being proxied by wpack io to something likehttp://192.168.2.1, my rest api is returning data with permalinks like http://wp-dev.test/permalink-post.

I've tried configureing webpack proxy setting inside of wpackio.project.js like so:

newConfig.devServer = {
          proxy: {
            "/*": {
              host: "wp-dev.test",
              target: "http://192.168.2.1"
            }
          }
        }

but have not had any luck with that approach. Is there a way to configure webpack to catch these client-rendered urls and proxy them back to the wpack.io proxy server ? eg: http://192.168.2.1/permalink-post ?

many thanks.

Add built in option for less support

Many popular libraries like antd, elemental ui uses less. So we should have it built in. Right now, once can do it like

const webpackConfigWithLess = (config, merge, appDir, isDev) => {
	const configWithLess = {
		module: {
			rules: [
				{
					test: /\.less$/,
					use: [
						isDev
							? 'style-loader'
							: {
									loader: MiniCssExtractPlugin.loader,
									options: {
										sourceMap: true,
									},
							  },
						{
							loader: 'css-loader',
							options: {
								importLoaders: 1,
								sourceMap: true,
							},
						},
						{
							loader: 'postcss-loader',
							options: {
								sourceMap: true,
							},
						},
						{
							loader: 'less-loader',
							options: {
								sourceMap: true,
							},
						},
					],
				},
			],
		},
	};

	return merge(config, configWithLess);
};

Tasks

  • Add prompt Does your project require less.
  • Add hasLess in project config, defaulting to undefined which would behave as false.
  • Add less-loader in project.
  • Add less in devDependencies of the user if hasLess.
  • Add less-loader if needed.
  • Turn on inlineJs of less-loader because antd needs it that way.

Changes in webpack/babel config and presets

  • Don't use object-rest-spread in typescript rule because it is already handled.
  • @wpackio/base should have plugin-proposal-class-properties. Remove the same from typescript rule.
  • Add support for flow.
  • Provide config for .jsx? babel-loader. (jsBabelPresetOptions).
  • Provide config for .tsx? babel-loader. (tsBabelPresetOptions).
  • Option to override .jsx? options. (jsBabelOverride).
  • Option to override .tsx? options. (tsBabelOverride).

To override, users can also pass in {} (empty object) and use local babel.config.js or .babelrc.js.

In the above, rule means what we've defined in webpack.

Things to watch out for when defining publicPath

We cannot have compile time publicPath because, let's face it, WordPress can be installed almost anywhere (subdirectory, subdomain, what-not).

So a PHP script should handle enqueuing and spitting out publicPath and webpack should that. This seems possible

  1. webpack/webpack#443 (comment)
  2. webpack/webpack#2776 (comment)

For the webpack dev server, we can:

  1. Assume (since browsersync is running anyway), WordPress is installed in a TLD (like localhost) and have the entry point publicPath /wp-content/<themes|plugins>/<slug>/dist/.

  2. Force write it using webpack writetodisk plugin and forget about entry-point dynamic publicPath.

For approach 2, it would actually cause a lot of disk write. Better if we harness webpack-dev-server serve from memory and go with 1.

Include @babel/plugin-transform-runtime by default

Hi,
First, thanks for a great tool โ€“ a lifesaver!

But I've encountered the not so uncommon Uncaught ReferenceError: regeneratorRuntime is not defined-error while writing async/await code.

It's not a big issue in itself โ€“ย I was able to solve it with a custom babel.config.js according to your instructions (though jsBabelPresetOptions and jsBabelOverride doesn't seem to be applied, but that's probably a separate issue).

I've made a repo reconstructing my issue and solution here (in that repo you can also see that jsBabelPresetOptions and jsBabelOverride doesn't get applied).

I just needed to add @babel/plugin-transform-runtime to the list of plugins and the problem was solved.

Therefore this is not as much an issue as it is a question โ€“ what do you think about adding @babel/plugin-transform-runtime to @wpackio/babel-preset-base by default?

My suggestion is to use something similar to what create-react-app is doing in their preset.

I would be happy to support with a PR if you're interested, even though I'll have to get acquainted with the code first ๐Ÿ˜„.

Path of assets is not correct when called from .scss files

Hello,

For some weird reason, if I import let's say an image from within a .js file and console.log it, the url is correct.
But if I reference the same image from within an .scss file then I get a 404 because the url has the entrypoint name twice in the url
eg:

import image from '../img/about-bckr.jpg';

Correct url when imported from a .js file:
http://somehost/wp-content/themes/vg-twig/build/app/assets/asset-601792add27d5248500ec253301b723d.jpg

body { background: #f1f1f1 url(../img/about-bckr.jpg); }

Wrong url when imported/called from an .scss file:
http://somehost/wp-content/themes/vg-twig/build/app/app/assets/asset-601792add27d5248500ec253301b723d.jpg

Notice the double /app/app/ there.

move fork-ts-checker-webpack-plugin from direct dependency

This one has a peerDep of typescript. We can completely remove it since we are requiring it at runtime anyway.

Also update the docs to reflect the change. If user needs support for typescript, then npm i -D fork-ts-checker-webpack-plugin is required.

Use project wide eslint

  • Completely migrate from tslint (for all packages).
  • Create a sharable eslint config for projects.

General Idea and Structure

  1. Use webpack along with webpack-dev-middleware, webpack-hot-middleware, browsersync.
  2. Ask for project config like wpws.config.js and environment config .wpws.
  3. wpws.config.js provides entry point, output path, compile mode (single or multi) and custom webpack configuration. We will use webpack-merge to merge it.
  4. .wpws tells the URL of the WordPress server (vvv, docker, lamp, mamp, wamp, what-ever), browserSync port, weiner config etc. Basically all browserSync stuff.
  5. Use webpack-manifest to spit out compilation and chunks.
  6. Provide a php script (through composer) which will read the wpws.config.js and the manifest output and provide methods to enqueue CSS/JS and spit out publicPath.
  7. Have webpack-dev-middleware handle compiling during development and webpack-hot-middleware handle hot reloading.
  8. Have webpack handle compile production scripts.

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.