Slide 49
Slide 49 text
webpack.config.js で頑張れば出来る。ふだんこんな感じでやってる。
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const RemoveEmptyScriptsPlugin = require("webpack-remove-empty-scripts");
const path = require("path");
const glob = require("glob");
/* 各ブロックのCSSファイルをentryに追加するためのオブジェクトを作成*/
const blockStyleDir = "src/styles";
const blockEntries = glob
.sync("blocks/**/*.css", { cwd: blockStyleDir })
.map((key) => [`styles/${key.replace(".css", "")}`, path.resolve(process.cwd(), blockStyleDir, key)]);
const blockEntriesObj = Object.fromEntries(blockEntries);
module.exports = {
...defaultConfig,
entry: {
...defaultConfig.entry,
"styles/theme/theme": path.resolve(process.cwd(), "src/styles/theme/theme.css"),
...blockEntriesObj,
},
plugins: [
...defaultConfig.plugins,
new RemoveEmptyScriptsPlugin({
stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS,
}),
],
watchOptions: {
ignored: ["**/node_modules", "**/build/**"],
},
};
49