weprovide/aviate-wordpress

此包已被放弃,不再维护。未建议替代包。

WordPress 的 Aviate 实现

安装: 543

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 4

分支: 0

类型:wordpress-muplugin

0.1.1 2017-10-31 12:42 UTC

This package is not auto-updated.

Last update: 2024-05-28 09:45:31 UTC


README

Aviate 的 WordPress 实现。

安装

composer require weprovide/aviate-wordpress

使用

const path = require('path')
const env = process.env.NODE_ENV || 'development'
const isDev = env === 'development'

module.exports = {
    distLocations: [
        path.join(__dirname, 'web/app/themes/yourtheme/dist')
    ],
    decorateConfig(config) {
        config.output.publicPath = isDev ? host : './'

        config.entry = Object.assign({}, config.entry, {
            'styles': [
                path.join(__dirname, 'web/app/themes/yourtheme/assets/styles/main.scss')
            ],
            'javascript': [
                path.join(__dirname, 'web/app/themes/yourtheme/assets/javascript/main.js')
            ]
        })

        return config
    }
}

添加自定义文件

aviate.config.js:

const path = require('path')
const env = process.env.NODE_ENV || 'development'
const isDev = env === 'development'

module.exports = {
    distLocations: [
        path.join(__dirname, 'web/app/themes/yourtheme/dist')
    ],
    decorateConfig(config) {
        config.output.publicPath = isDev ? host : './'

        config.entry = Object.assign({}, config.entry, {
            'styles': [
                path.join(__dirname, 'web/app/themes/yourtheme/assets/styles/main.scss')
            ],
            'javascript': [
                path.join(__dirname, 'web/app/themes/yourtheme/assets/javascript/main.js')
            ],
            'your-file': [
                path.join(__dirname, 'web/app/themes/yourtheme/assets/javascript/example.js')
            ]
        })

        return config
    }
}

functions.php:

<?php
namespace YourVendor\YourTheme;

function aviateFiles($files, $aviate) {
	if($aviate->isDevelopment()) {
		$files['js'][] = $aviate->getDevServerUrl('your-file.js');
		return $files;
	}

	$files['js'][] = $aviate->getProductionUrl('your-file.js');

	return $files;
}

add_filter('aviate_files', __NAMESPACE__.'\\aviateFiles', 10, 2);