hobart 2018-05-07 18:08:43 9451次浏览 3条评论 5 3 0

Yii 2.0.15 模板改造

高级版,修改 common/config/main.php

?php
return [
    'aliases' => [
        '@bower' => dirname(dirname(__DIR__)) . '/node_modules',
        '@npm' => dirname(dirname(__DIR__)) . '/node_modules',
    ],
]

这样类似 BootstrapPluginAsset 的 public $sourcePath = '@bower/bootstrap/dist'; 就会正确定位到 path/to/project/node_modules

新增、修改 package.json,将 yii2 的 composer 依赖 bower-asset/* 转换为对应的 npm 包:

{
    "private": true,
    "dependencies": {
        "jquery": "^2.2.4",
        "bootstrap": "3.3.7",
        "inputmask": "^3.3.11",
        "jquery-treegrid": "^0.3.0",
        "jquery-ui": "^1.12.1",
        "punycode": "^2.1.0",
        "typeahead.js": "^0.11.1",
        "yii2-pjax": "^2.0.7"
    },
    "devDependencies": {},
    "license": "BSD-3-Clause"
}

再修改 composer.json

{
    "provide": {
        "bower-asset/jquery": "*",
        "bower-asset/bootstrap": "*",
        "bower-asset/inputmask": "*",
        "bower-asset/punycode": "*",
        "bower-asset/typeahead.js": "*",
        "bower-asset/yii2-pjax": "*"
    },
    "scripts": {
        "post-install-cmd": [
            "yii\\composer\\Installer::postInstall",
            "yarn install"
        ],
        "post-create-project-cmd": [
            "yii\\composer\\Installer::postCreateProject",
            "yii\\composer\\Installer::postInstall",
            "yarn install"
        ]
    }

删除项目根目录下的文件夹 vendornode_modules 后,将 composer 和 npm 都设置为使用国内的镜像源,执行:

composer install

你会发现,安装速度飞起,再也不会傻叉地 bower 向 api.github.com 作死了。

觉得很赞
您需要登录后才可以评论。登录 | 立即注册