|
1 | 1 | const path = require('path'); |
2 | | -const glob = require("glob"); |
| 2 | +const glob = require('glob'); |
| 3 | +const { argv } = require('yargs'); |
3 | 4 | const { CleanWebpackPlugin } = require('clean-webpack-plugin'); |
4 | 5 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; |
5 | 6 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); |
6 | 7 | const CopyPlugin = require('copy-webpack-plugin'); |
7 | 8 | const WebpackShellPluginNext = require('webpack-shell-plugin-next'); |
8 | 9 |
|
9 | | -const mode = process.env.NODE_ENV === 'development' ? 'development' : 'production'; |
10 | | -const stats = mode === 'development' ? 'errors-warnings' : { children: false }; |
11 | | - |
| 10 | +const isDev = argv.mode === 'development'; |
| 11 | +const stats = isDev ? 'errors-warnings' : { children: false }; |
12 | 12 |
|
13 | 13 | module.exports = { |
14 | | - mode: mode, |
15 | 14 | stats: stats, |
16 | 15 | entry: glob.sync('./src/components/**/*.js').reduce((acc, path) => { |
17 | | - const entry = path.replace(/^.*[\\\/]/, '').replace('.js',''); |
| 16 | + const entry = path.replace(/^.*[\\\/]/, '').replace('.js', ''); |
18 | 17 | acc[entry] = path; |
19 | 18 | return acc; |
20 | | - }, {}), |
| 19 | + }, {}), |
21 | 20 | output: { |
22 | 21 | filename: './assets/bundle.[name].js', |
23 | 22 | path: path.resolve(__dirname, 'dist'), |
24 | 23 | }, |
25 | | - plugins: [ |
26 | | - new CleanWebpackPlugin(), |
27 | | - new BundleAnalyzerPlugin({ |
28 | | - analyzerMode: 'disabled', |
29 | | - generateStatsFile: true |
30 | | - }), |
31 | | - new MiniCssExtractPlugin({ |
32 | | - filename: '/assets/bundle.[name].css' |
33 | | - }), |
34 | | - new CopyPlugin([{ |
35 | | - from: 'src/components/**/*', |
36 | | - to: '[folder]/[name].[ext]', |
37 | | - ignore: [ |
38 | | - 'src/components/**/*.js', |
39 | | - 'src/components/**/*.scss', |
40 | | - 'src/assets/**/*', |
41 | | - 'src/components/sections/**/*', |
42 | | - 'src/components/templates/**/*', |
43 | | - 'src/components/snippets/**/*', |
44 | | - 'src/components/tailwind.css' |
45 | | - ] |
46 | | - }, |
47 | | - { |
48 | | - from: 'src/components/templates/**/*.liquid', |
49 | | - to: 'templates/[name].[ext]', |
50 | | - flatten: true |
51 | | - }, |
52 | | - { |
53 | | - from: 'src/components/sections/**/*.liquid', |
54 | | - to: 'sections/[name].[ext]', |
55 | | - flatten: true |
56 | | - }, |
57 | | - { |
58 | | - from: 'src/components/snippets/**/*.liquid', |
59 | | - to: 'snippets/[name].[ext]', |
60 | | - flatten: true |
61 | | - }, |
62 | | - { |
63 | | - from: 'src/assets/**/*', |
64 | | - to: 'assets/', |
65 | | - flatten: true |
66 | | - }, |
67 | | - { |
68 | | - from: 'src/config/*.json', |
69 | | - to: 'config/[name].[ext]', |
70 | | - }, |
71 | | - { |
72 | | - from: 'src/locales/*.json', |
73 | | - to: 'locales/[name].[ext]', |
74 | | - }, |
75 | | - ]) |
76 | | - ], |
77 | 24 | module: { |
78 | | - rules: [{ |
| 25 | + rules: [ |
| 26 | + { |
79 | 27 | test: /\.(sc|sa|c)ss$/, |
80 | 28 | use: [ |
81 | 29 | MiniCssExtractPlugin.loader, |
82 | 30 | { |
83 | 31 | loader: 'css-loader', |
84 | 32 | options: { |
85 | | - url: false |
86 | | - } |
| 33 | + url: false, |
| 34 | + }, |
87 | 35 | }, |
88 | 36 | 'postcss-loader', |
89 | 37 | { |
90 | 38 | loader: 'sass-loader', |
91 | 39 | options: { |
92 | 40 | sourceMap: true, |
93 | | - } |
94 | | - } |
95 | | - ] |
| 41 | + }, |
| 42 | + }, |
| 43 | + ], |
96 | 44 | }, |
97 | 45 | { |
98 | 46 | test: /\.(png|svg|jpg|gif)$/, |
99 | | - use: [ |
100 | | - 'file-loader' |
101 | | - ] |
| 47 | + use: ['file-loader'], |
102 | 48 | }, |
103 | 49 | { |
104 | 50 | test: /\.(woff|woff2|eot|ttf|otf)$/, |
105 | | - use: [ |
106 | | - 'file-loader' |
107 | | - ] |
108 | | - }, |
109 | | - { |
110 | | - test: /\.m?js$/, |
111 | | - exclude: /(node_modules|bower_components)/, |
112 | | - use: { |
113 | | - loader: 'babel-loader', |
114 | | - options: { |
115 | | - presets: ['@babel/preset-env'], |
116 | | - plugins: ['transform-class-properties'], |
117 | | - plugins: ['babel-plugin-transform-class-properties'] |
118 | | - } |
119 | | - } |
| 51 | + use: ['file-loader'], |
120 | 52 | }, |
121 | 53 | { |
122 | 54 | test: /\.js$/, |
123 | 55 | exclude: /node_modules/, |
124 | | - loader: "babel-loader" |
125 | | - } |
126 | | - ] |
127 | | - } |
128 | | -}; |
| 56 | + loader: 'babel-loader', |
| 57 | + }, |
| 58 | + ], |
| 59 | + }, |
| 60 | + plugins: [ |
| 61 | + new CleanWebpackPlugin(), |
| 62 | + isDev && |
| 63 | + new BundleAnalyzerPlugin({ |
| 64 | + analyzerMode: 'disabled', |
| 65 | + generateStatsFile: true, |
| 66 | + }), |
| 67 | + isDev && |
| 68 | + new WebpackShellPluginNext({ |
| 69 | + onBuildStart: { |
| 70 | + scripts: ['echo -- Webpack build started 🛠'], |
| 71 | + blocking: true, |
| 72 | + parallel: false, |
| 73 | + }, |
| 74 | + onBuildError: { |
| 75 | + scripts: ['echo -- ☠️ Aw snap, Webpack build failed...'], |
| 76 | + }, |
| 77 | + onBuildEnd: { |
| 78 | + scripts: [ |
| 79 | + 'echo -- Webpack build complete ✓', |
| 80 | + 'echo -- Building TailwindCSS...', |
| 81 | + 'npx tailwindcss build src/components/tailwind.css -o dist/assets/tailwind.css.liquid', |
| 82 | + 'echo -- Deploying to theme ✈️', |
| 83 | + 'shopify-themekit deploy', |
| 84 | + 'echo -- Deployment competed ✓', |
| 85 | + 'shopify-themekit open', |
| 86 | + 'shopify-themekit watch', |
| 87 | + ], |
| 88 | + blocking: true, |
| 89 | + parallel: false, |
| 90 | + }, |
| 91 | + }), |
129 | 92 |
|
130 | | -// Run Shell commmands during Webpack operations |
131 | | -if (mode === 'development') { |
132 | | - module.exports.plugins.push( |
133 | | - new WebpackShellPluginNext({ |
134 | | - onBuildStart:{ |
135 | | - scripts: ['echo -- Webpack build started 🛠'], |
136 | | - blocking: true, |
137 | | - parallel: false |
138 | | - }, |
139 | | - onBuildError:{ |
140 | | - scripts: ['echo -- ☠️ Aw snap, Webpack build failed...'], |
141 | | - }, |
142 | | - onBuildEnd:{ |
143 | | - scripts: [ |
144 | | - 'echo -- Webpack build complete ✓', |
145 | | - 'echo -- Building TailwindCSS...', |
146 | | - 'npx tailwindcss build src/components/tailwind.css -o dist/assets/tailwind.css.liquid', |
147 | | - 'echo -- Deploying to theme ✈️', |
148 | | - 'shopify-themekit deploy', |
149 | | - 'echo -- Deployment competed ✓', |
150 | | - 'shopify-themekit open', |
151 | | - 'shopify-themekit watch'], |
152 | | - blocking: true, |
153 | | - parallel: false |
154 | | - } |
155 | | - }) |
156 | | - ) |
157 | | - } |
| 93 | + new MiniCssExtractPlugin({ |
| 94 | + filename: '/assets/bundle.[name].css', |
| 95 | + }), |
| 96 | + new CopyPlugin({ |
| 97 | + patterns: [ |
| 98 | + { |
| 99 | + from: 'src/components/*/*.liquid', |
| 100 | + to: '[folder]/[name].[ext]', |
| 101 | + }, |
| 102 | + { |
| 103 | + from: 'src/components/templates/**/*.liquid', |
| 104 | + to: 'templates/[name].[ext]', |
| 105 | + flatten: true, |
| 106 | + }, |
| 107 | + { |
| 108 | + from: 'src/components/sections/**/*.liquid', |
| 109 | + to: 'sections/[name].[ext]', |
| 110 | + flatten: true, |
| 111 | + }, |
| 112 | + { |
| 113 | + from: 'src/components/snippets/**/*.liquid', |
| 114 | + to: 'snippets/[name].[ext]', |
| 115 | + flatten: true, |
| 116 | + }, |
| 117 | + { |
| 118 | + from: 'src/assets/**/*', |
| 119 | + to: 'assets/', |
| 120 | + flatten: true, |
| 121 | + }, |
| 122 | + { |
| 123 | + from: 'src/config/*.json', |
| 124 | + to: 'config/[name].[ext]', |
| 125 | + }, |
| 126 | + { |
| 127 | + from: 'src/locales/*.json', |
| 128 | + to: 'locales/[name].[ext]', |
| 129 | + }, |
| 130 | + ], |
| 131 | + }), |
| 132 | + ].filter(Boolean), |
| 133 | +}; |
0 commit comments