-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
104 lines (102 loc) · 2.67 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var path = require("path");
const glob = require("glob");
const mode =
process.env.NODE_ENV === "development" ? "development" : "production";
const live_watch = process.env.THEME_ENV === "live" ? "shopify-themekit watch --allow-live" : "shopify-themekit watch"
const live_deploy = process.env.THEME_ENV === "live" ? "shopify-themekit deploy --allow-live" : "shopify-themekit deploy"
const WebpackShellPluginNext = require("webpack-shell-plugin-next");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
mode: mode,
watch: mode === "development",
devtool: false,
entry: glob.sync("./src/js/**/*.js").reduce((acc, path) => {
const entry = path.replace(/^.*[\\\/]/, "").replace(".js", "");
acc[entry] = path;
return acc;
}, { index: './src/js/application.js'}),
output: {
path: path.resolve(__dirname, "./dist/assets"),
filename: "[name].bundle.js",
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].bundle.css",
}),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
// { loader: "css-loader", options: { importLoaders: 1 } },
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
require("postcss-import")(),
require("tailwindcss")("./tailwind.config.js"),
require("autoprefixer"),
],
},
},
},
],
},
],
},
optimization: {
minimizer: [
new CssMinimizerPlugin({
exclude: /\/src/,
minimizerOptions: {
preset: [
'default',
{
discardComments: { removeAll: true },
},
],
},
}),
new TerserPlugin({
exclude: /\/src/,
}),
],
},
};
if (mode === "development") {
module.exports.plugins.push(
new WebpackShellPluginNext({
onBuildStart: {
scripts: [
"echo Webpack build in progress..."
],
},
onBuildEnd: {
scripts:
[
"echo Build Complete",
"shopify-themekit open",
// live_deploy,
live_watch,
],
parallel: true,
},
})
);
}