diff --git a/config.yml.example b/config.yml.example index 1cc2639..1db2eb5 100644 --- a/config.yml.example +++ b/config.yml.example @@ -1,7 +1,17 @@ development: - password: + password: theme_id: "" - store: + store: + directory: dist/ + ignore_files: + - config/settings_data.json + - "*.js" + - "*.hot-update.json" + +production: + password: + theme_id: "" + store: directory: dist/ ignore_files: - config/settings_data.json diff --git a/package.json b/package.json index f02a138..12d074e 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,9 @@ "author": "Mike Salvati", "private": true, "scripts": { - "start": "webpack --mode=development --watch", + "start": "webpack serve --mode=development", "build": "webpack --mode=production && npx tailwindcss build src/components/tailwind.css -o dist/assets/tailwind.css.liquid", - "deploy": "webpack --mode=production && npx tailwindcss build src/components/tailwind.css -o dist/assets/tailwind.css.liquid && shopify-themekit deploy" + "deploy": "webpack --mode=production && npx tailwindcss build src/components/tailwind.css -o dist/assets/tailwind.css.liquid && shopify-themekit deploy --env=production" }, "dependencies": { "tailwindcss": "^1.9.6", diff --git a/src/components/sections/header/header.liquid b/src/components/sections/header/header.liquid index 6fe4bbf..91c183f 100644 --- a/src/components/sections/header/header.liquid +++ b/src/components/sections/header/header.liquid @@ -141,4 +141,4 @@ max-width: {{section.settings.logo_max_width}}px; } -{%- endif -%} \ No newline at end of file +{%- endif -%} diff --git a/src/components/snippets/message/message.js b/src/components/snippets/message/message.js index c20d2a4..4d447fc 100644 --- a/src/components/snippets/message/message.js +++ b/src/components/snippets/message/message.js @@ -1,5 +1,5 @@ // testing importing scss -import "./message.scss"; +import './message.scss'; // Testing arrow functions const messageFunction = () => 'Message JS ES6 Function'; diff --git a/src/components/snippets/message/message.liquid b/src/components/snippets/message/message.liquid index b469e6c..4319327 100644 --- a/src/components/snippets/message/message.liquid +++ b/src/components/snippets/message/message.liquid @@ -4,4 +4,4 @@

This is a message from a snippet

-{{ 'bundle.message.js' | asset_url | script_tag }} \ No newline at end of file +{{ 'bundle.message.js' | asset_url | script_tag }} diff --git a/webpack.config.js b/webpack.config.js index 8c2199d..68b3522 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,13 +2,15 @@ const path = require('path'); const glob = require('glob'); const { argv } = require('yargs'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); -const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const CopyPlugin = require('copy-webpack-plugin'); const WebpackShellPluginNext = require('webpack-shell-plugin-next'); -const isDev = argv.mode === 'development'; -const stats = isDev ? 'errors-warnings' : { children: false }; + +const isDevMode = argv.mode === 'development'; +const stats = isDevMode ? 'errors-warnings' : { children: false }; +const port = 9000; +const publicPath = isDevMode ? `https://localhost:${port}/` : ''; module.exports = { stats: stats, @@ -19,14 +21,18 @@ module.exports = { }, {}), output: { filename: './assets/bundle.[name].js', + hotUpdateChunkFilename: './hot/[id].[fullhash].hot-update.js', + hotUpdateMainFilename: './hot/[fullhash].hot-update.json', path: path.resolve(__dirname, 'dist'), + publicPath, }, + cache: false, module: { rules: [ { test: /\.(sc|sa|c)ss$/, use: [ - MiniCssExtractPlugin.loader, + isDevMode ? 'style-loader' : MiniCssExtractPlugin.loader, { loader: 'css-loader', options: { @@ -58,18 +64,18 @@ module.exports = { ], }, plugins: [ - new CleanWebpackPlugin(), - isDev && - new BundleAnalyzerPlugin({ - analyzerMode: 'disabled', - generateStatsFile: true, - }), - isDev && + new CleanWebpackPlugin({ + cleanStaleWebpackAssets: false, + }), + isDevMode && new WebpackShellPluginNext({ onBuildStart: { - scripts: ['echo -- Webpack build started 🛠'], - blocking: true, - parallel: false, + scripts: [ + 'echo -- Webpack build started 🛠', + 'shopify-themekit watch --env=development', + ], + blocking: false, + parallel: true, }, onBuildError: { scripts: ['echo -- ☠️ Aw snap, Webpack build failed...'], @@ -80,39 +86,50 @@ module.exports = { 'echo -- Building TailwindCSS...', 'npx tailwindcss build src/components/tailwind.css -o dist/assets/tailwind.css.liquid', 'echo -- Deploying to theme ✈️', - 'shopify-themekit deploy', + 'shopify-themekit deploy --env=development', 'echo -- Deployment competed ✓', 'shopify-themekit open', - 'shopify-themekit watch', ], blocking: true, parallel: false, }, }), - new MiniCssExtractPlugin({ - filename: '/assets/bundle.[name].css', + filename: './assets/bundle.[name].css', }), new CopyPlugin({ patterns: [ { - from: 'src/components/*/*.liquid', + from: 'src/components/**/*.liquid', to: '[folder]/[name].[ext]', - }, - { - from: 'src/components/templates/**/*.liquid', - to: 'templates/[name].[ext]', - flatten: true, - }, - { - from: 'src/components/sections/**/*.liquid', - to: 'sections/[name].[ext]', - flatten: true, - }, - { - from: 'src/components/snippets/**/*.liquid', - to: 'snippets/[name].[ext]', flatten: true, + transformPath(targetPath, absolutePath) { + const relativePath = path.join(__dirname, 'src/components'); + const diff = path.relative(relativePath, absolutePath); + const targetFolder = diff.split(path.sep)[0]; + return path.join(targetFolder, path.basename(absolutePath)); + }, + transform: isDevMode + ? function (content) { + content = content + .toString() + .replace( + /{{\s*'([^']+)'\s*\|\s*asset_url\s*\|\s*(stylesheet_tag|script_tag)\s*}}/g, + function (matched, fileName, type) { + if (type === 'stylesheet_tag') { + if (fileName !== 'tailwind.css') { + return ''; + } + return matched; + } + + return ``; + } + ); + + return content; + } + : undefined, }, { from: 'src/assets/**/*', @@ -130,4 +147,21 @@ module.exports = { ], }), ].filter(Boolean), + devServer: { + contentBase: path.join(__dirname, 'dist'), + publicPath: '/', + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS', + 'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization', + }, + compress: true, + port, + https: true, + disableHostCheck: true, + hot: true, + liveReload: false, + overlay: true, + writeToDisk: true, + }, };