You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
const path = require("path");
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
|
|
// Ref: https://stackoverflow.com/a/60021512/6133998
|
|
const populateHtmlPlugins = (pagesArray) => {
|
|
res = [];
|
|
pagesArray.forEach((page) => {
|
|
res.push(
|
|
new HtmlWebpackPlugin({
|
|
page,
|
|
filename: `${page.toLowerCase()}.html`,
|
|
template: `./src/${page.toLowerCase()}.html`,
|
|
})
|
|
);
|
|
});
|
|
return res;
|
|
};
|
|
const pages = populateHtmlPlugins(["index", "cards"]);
|
|
|
|
module.exports = {
|
|
entry: {
|
|
main: ["./src/main.js"],
|
|
spacelab: ["./src/scss/spacelab-theme.scss"],
|
|
cyborg: ["./src/scss/cyborg-theme.scss"]
|
|
},
|
|
output: {
|
|
path: path.resolve(__dirname, "dist"),
|
|
filename: "js/[name].js",
|
|
},
|
|
resolve: {
|
|
modules: ["node_modules"],
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(sa|sc|c)ss$/,
|
|
use: [
|
|
// 取代 style-loader。作用: 提取 js 中的 css 成單獨文件
|
|
MiniCssExtractPlugin.loader,
|
|
// 將 css 文件整合倒 js 文件中
|
|
"css-loader",
|
|
// 將 sass/scss 編譯成 css
|
|
"sass-loader",
|
|
],
|
|
},
|
|
{
|
|
test: /\.html$/,
|
|
loader: "raw-loader",
|
|
},
|
|
],
|
|
},
|
|
plugins: [
|
|
new MiniCssExtractPlugin({
|
|
filename: "css/[name].css",
|
|
}),
|
|
...pages,
|
|
],
|
|
devServer: {
|
|
// contentBase: path.join(__dirname, "dist"),
|
|
compress: true,
|
|
port: 9000,
|
|
open: true,
|
|
hot: true,
|
|
},
|
|
};
|