一個基於react+webpack的多頁面應用配置

簡單介紹

首先本文不會對webpack代碼進行解釋,其全部配置均可以在文檔上找到。react

平時工做中會寫一些多頁面應用,由於習慣了react的開發模式,故此寫了一個簡單的配置,跟你們一塊兒分享。若是你也喜歡,對你的開發有所幫助,但願給點鼓勵(start)webpack

github地址:https://github.com/ivan-GM/Gm...git

項目目錄介紹:github

打包後文件目錄:web

打包成cli

若是你厭煩了新項目的複製、粘貼,也能夠構建成cli

1,首先建立個文件夾,npm init初始化項目;npm

2, 建立bin目錄,touch index.js 編寫配置文件;json

const commander = require('commander');
const inquirer = require('inquirer');
const download = require('download-git-repo')
const ora = require('ora');

const questions = [
    {
        type: 'input',
        name: 'projectName',
        message: 'project name:',
        filter: function (val) {
            return val;
        }
    }
]

commander
    .option('init', 'create project')
    .version('1.0', '-v, --version')

commander
    .command('init')
    .description('')
    .action(() => {
        inquirer.prompt(questions).then(answers => {
            const { projectName } = answers;
            const spinner = ora('Loading unicorns').start();
            spinner.color = 'green';
            spinner.text = 'downloading template...';
            download('direct:https://github.com/ivan-GM/live', projectName, { clone: true }, (err) => {
                if (err) {
                    console.log(err)
                } else {
                    spinner.stop()
                    console.log('sucess')
                }
            })
        })
    });

commander.parse(process.argv);

3,添加命令:打開package.jsonui

"bin": {
     "my-cli": "./bin/index.js"
    },

4,發佈npmspa

*上面代碼只是對打包成cli進行了簡單的說明,若是感興趣了,能夠深刻研究code

相關文章
相關標籤/搜索