-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
64 lines (59 loc) · 1.9 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Generated using webpack-cli https://github.com/webpack/webpack-cli
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const glob = require('glob');
const buildTime = Math.floor(Date.now() / 1000);
const isProduction = process.env.NODE_ENV == "production";
const productionPlugins = [];
if (isProduction) {
const siteDirectory = path.resolve(__dirname, "./_site");
const pages = glob.sync("**/*.html", { cwd: siteDirectory });
console.log(pages);
const htmlWebpackPlugins = pages.map(page => new HtmlWebpackPlugin({
template: `${siteDirectory}/${page}`,
filename: `${siteDirectory}/${page}`,
inject: false
}));
productionPlugins.push(...htmlWebpackPlugins);
productionPlugins.push( new HtmlReplaceWebpackPlugin([{
pattern: 'bundle.js',
replacement: `bundle.${buildTime}.js`
},{
pattern: 'styles.css',
replacement: `styles.${buildTime}.css`
}]));
}
const config = {
entry: ["./src/stimulus.ts", "./css/styles.css"],
output: {
filename: isProduction ? `bundle.${buildTime}.js` : `bundle.js`,
path: path.resolve(__dirname, "./_site"),
},
plugins: [
...productionPlugins,
new MiniCssExtractPlugin({
filename: isProduction ? `styles.${buildTime}.css` : `styles.css`,
}),],
module: {
rules: [
{
test: /\.(ts|tsx)$/i,
loader: "ts-loader",
exclude: ["/node_modules/"],
},{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader']
}
],
},
resolve: {
extensions: [".tsx", ".ts", ".jsx", ".js", "..."],
}
};
module.exports = () => {
config.mode = isProduction ? "production" : "development";
//config.devtools = isProduction ? "none" : "eval-source-map";
return config;
};