problem description
this is my directory structure. I want to merge all the scss files under the css2 folder into one css file and package them to the build directory
extractTextPluginscss
scssscssjsimport
100scssscss
configuration file
const path = require("path");
const glob = require("glob");
const htmlPlugin = require("html-webpack-plugin");
const extractTextPlugin = require("extract-text-webpack-plugin");
const webpack = require("webpack");
var imJsFile = glob.sync("./im/js/core2/**/*.js");
var config = {
entry:{
entry:imJsFile
},
output:{
path:path.resolve(__dirname,"build/im"),
filename:"./js/sp.im.min.js"
},
devServer:{
contentBase:path.resolve(__dirname,"build"),
host:"localhost",
compress:true,
port:1717
},
module:{
rules:[
{
test: /\.scss$/,
use: extractTextPlugin.extract({
use: [{
loader: "css-loader"
}, {
loader: "sass-loader"
}],
fallback: "style-loader"
})
}
]
},
plugins:[
new webpack.ProvidePlugin({
jQuery:"jquery"
}),
new extractTextPlugin("/css/[name].css")
]
};
var viesObj = getView("im/view/onlineservice/chat2/*.html");
var pages = Object.keys(viesObj);
pages.forEach(function(pathname) {
var htmlName = viesObj[pathname]
var conf = {
filename: "./view/" + htmlName + ".html", //htmlpath
template: "./im/view/onlineservice/chat2/" + htmlName + ".html", //html
hash: true, //hash
//chunks: ["common",htmlName],//chunk
minify: { //HTML
removeAttributeQuotes:true, //
removeComments: true, //HTML
collapseWhitespace: false //
}
};
config.plugins.push(new htmlPlugin(conf));
});
module.exports = config;
function getView(globPath, pathDir) {
var files = glob.sync(globPath);
var entries = {},
entry, dirname, basename, pathname, extname;
for (var i = 0; i < files.length; iPP) {
entry = files[i];
dirname = path.dirname(entry); //
extname = path.extname(entry); //
basename = path.basename(entry, extname); // "/" path,entryextname
pathname = path.join(dirname, basename); // path
pathname = pathDir ? pathname.replace(new RegExp("^" + pathDir), "") : pathname;
entries[pathname] = basename;
}
return entries;
}
I want to know how to package several scss files into the build directory