npm install coffee-script coffee-loader --save-dev

utils.js

var glob = require('glob');

exports.getEntries = function (globPath, extension) {
    var entries = {}
    glob.sync(globPath).forEach(function (entry) {
        var tmp = new RegExp('\./src/([^\.]+)', 'g').exec(entry)[1]
        if (extension) {
            entries[tmp] = entry.replace(/\.\w+$/g, '.' + extension)
        }
        else {
            entries[tmp] = entry
        }
    });
    return entries;
}

webpack.dev.conf.js / webpack.prod.conf.js

var pages = utils.getEntries('./src/views/**/*.coffee', 'html')
for (var page in pages) {
    var conf = {
        filename: pages[page].substr(12),
        template: pages[page],
        inject: true,
        excludeChunks: Object.keys(pages).filter(item => {
            return (item != page)
        })
    }
    module.exports.plugins.push(new HtmlWebpackPlugin(conf))
}

entry

entry: utils.getEntries('./src/views/**/*.coffee')

Chobits
7.4k 声望171 粉丝

保卫骡博 Chobits#3780