nemo64/webpack-environment

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

dev-master 2018-05-07 10:39 UTC

This package is not auto-updated.

Last update: 2019-02-20 19:22:54 UTC


README

Latest Stable Version Total Downloads License

Webpack 环境

这是 nemo64/environment 的扩展,它添加了一个默认的 webpack 文件以及一些 Makefile 和 docker 配置,以便于在 PHP 项目中轻松设置 webpack。

没有其他本地依赖。每个 node 执行都通过 docker 运行。

如何安装

只需运行 composer require --dev nemo64/webpack-environment 即可,文件将自动生成。你还需要在你的应用程序中实现 manifest.json了解更多)。

工作原理

Webpack 将作为 docker 服务执行。

services:
  webpack:
    image: 'node:carbon'
    command: 'yarn run encore dev-server --host 0.0.0.0 --port 8080'
    ports:
      8080:8080
    volumes:
      - '.:/var/www'
    working_dir: /var/www

Makefile 将扩展此安装任务

node_modules: docker-compose.log $(wildcard package.* yarn.*)
	docker-compose run --rm --no-deps webpack yarn install

示例文件

如果你想要试验 webpack,只需使用此 index.php 文件。

<?php $manifest = json_decode(file_get_contents(__DIR__ . '/build/manifest.json'), true); ?>
<!DOCTYPE html>
<html>
    <head>
        <title>Example page</title>
        <link rel="stylesheet" href="<?php echo htmlspecialchars($manifest['build/app.css']) ?>">
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col">col1</div>
                <div class="col">col2</div>
                <div class="col">col3</div>
            </div>
        </div>
        <script src="<?php echo htmlspecialchars($manifest['build/app.js']) ?>"></script>
    </body>
</html>