webpack多入口问题

需求:webpack多种类型(css--js..)入口,多种类型(css--js..)输入;

clipboard.png

var webpack =require('webpack');
var path=require('path');
var fs=require('fs');
let  join = require('path').join;
let fileNames=findSync('./js');
let entryL={
};
function findSync(startPath) {
    let result=[];
    function finder(path) {
        let files=fs.readdirSync(path);
        files.forEach((val,index) => {
            let fPath=join(path,val);
            let stats=fs.statSync(fPath);
            if(stats.isDirectory()) finder(fPath);
            if(stats.isFile()) result.push(fPath);
        });

    }
    finder(startPath);
    return result;
}
fileNames.forEach(function (e) {
    let c=e.toString().replace(/.*\\(.+)$/g,'$1');
    let d=e.toString().replace(/.*\\(.+)\..*$/g,'$1');
    entryL[d]=__dirname+'/js/'+c
});


var ExtractTextPlugin=require('extract-text-webpack-plugin');
var HtmlWebpackPlugin=require('html-webpack-plugin');
module.exports={
    entry:entryL,
    output:{
        path:path.join(__dirname,'dist'),
      //  library:'umd',  //导出格式
        filename:'[name].js'
    },
    module:{
        rules:[
            {
                test:/\.js$/,
                loaders:'babel-loader'
            },
            {
                test:/\.css$/,
                use:ExtractTextPlugin.extract({
                    fallback:'style-loader',
                    use:'css-loader'
                })
            }
        ]
    },
    plugins: [
        new ExtractTextPlugin({
            filename:  'css/style.css',
            allChunks: true
        }),
        new HtmlWebpackPlugin()
    ]
};

求大神解惑

阅读 2.7k
1 个回答

据我所知,入口(entry)不能是css吧,一般只能是js。webpack是天然的支持js的。给你一个链接看看先:

  1. 我的GitHub有个demo,内容本身简洁,但涉及webpack相关的配置还比较全。有用的话,麻烦给star :)
    https://github.com/JackieGe/E...

  2. 另外一篇关于unit test配置的 https://segmentfault.com/a/11...

推荐问题
宣传栏