Skip to content

Commit

Permalink
Much better webpack workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
alwaysblank committed Dec 19, 2020
1 parent 684f571 commit d1675ef
Show file tree
Hide file tree
Showing 18 changed files with 4,357 additions and 2,066 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

# Webpack asset destination
/content/assets
/content/_data/assets.json
webpack.hash
.webpack
9 changes: 0 additions & 9 deletions assets/entry.js

This file was deleted.

10 changes: 0 additions & 10 deletions assets/legacy.js

This file was deleted.

3 changes: 3 additions & 0 deletions assets/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ const main = async () => {
};

main();

const yourl = new URL(window.location);
console.log(yourl);
2 changes: 1 addition & 1 deletion assets/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
@import "tailwindcss/utilities";

body {
background-color: cornflowerblue;
background: green;
}
16 changes: 16 additions & 0 deletions build/webpack.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const path = require('path')

module.exports = {
cache: {
type: 'filesystem',
cacheDirectory: path.resolve(__dirname, '..', '.webpack')
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, '..', 'content', 'assets'),
publicPath: "/",
},
mode: process.env.NODE_ENV || 'development',
devtool: 'source-map',
stats: 'errors-only',
}
48 changes: 48 additions & 0 deletions build/webpack.config.legacy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const base = require('./webpack.config.base')
const path = require('path');

module.exports = {
...base,

name: 'legacy',
entry: {
legacy: [
path.join(__dirname, '..', 'assets', 'scripts', 'main.js'),
],
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
babelrc: false,
exclude: [
/core-js/,
/regenerator-runtime/,
],
presets: [
['@babel/preset-env', {
loose: true,
modules: false,
// debug: true,
corejs: 3,
useBuiltIns: 'usage',
targets: {
browsers: [
'> 1%',
'last 2 versions',
'Firefox ESR',
],
},
}],
],
sourceType: 'unambiguous',
plugins: ['@babel/plugin-syntax-dynamic-import'],
},
},
},
]
}
}
76 changes: 76 additions & 0 deletions build/webpack.config.main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const base = require('./webpack.config.base')
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
...base,

name: 'main',
entry: {
main: [
path.join(__dirname, '..', 'assets', 'scripts', 'main.js'),
path.join(__dirname, '..', 'assets', 'styles', 'main.css'),
],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
}),
],
devServer: {
contentBase: path.join(__dirname, '..', 'dist'),
compress: true,
port: 9000,
watchContentBase: true,
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
babelrc: false,
exclude: [
/core-js/,
/regenerator-runtime/,
],
presets: [
['@babel/preset-env', {
loose: true,
modules: false,
// debug: true,
corejs: 3,
useBuiltIns: 'usage',
targets: {
browsers: [
'last 2 Chrome versions', 'not Chrome < 60',
'last 2 Safari versions', 'not Safari < 10.1',
'last 2 iOS versions', 'not iOS < 10.3',
'last 2 Firefox versions', 'not Firefox < 54',
'last 2 Edge versions', 'not Edge < 15',
],
},
}],
],
sourceType: 'unambiguous',
plugins: ['@babel/plugin-syntax-dynamic-import'],
},
},
},
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1
},
},
'postcss-loader',
]
},
]
}
}
4 changes: 3 additions & 1 deletion content/_includes/foot.njk
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{% include "partials/nomodule-polyfill.njk" %}
{% include "partials/nomodule-polyfill.njk" %}
<script type="module" src="/main.js"></script>
<script nomodule src="/legacy.js"></script>
3 changes: 1 addition & 2 deletions content/_includes/head.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
<meta name="description" content="{{ description }}">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="/{{ assets.modern.css }}" />
<script type="module" src="/{{ assets.modern.mjs }}"></script>
<link rel="stylesheet" href="/main.css" />
</head>
2 changes: 1 addition & 1 deletion content/_layouts/app.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html class="no-js" lang="en">
{% include "head.njk" %}
<body class="bg-green-50">
<body class="bg-blue-500">
{{ content | safe }}
</body>
{% include "foot.njk" %}
Expand Down
1 change: 0 additions & 1 deletion content/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ description: "11ty starter pack"
<div class="p-10">
{% cl_img { path: 'elf.jpg', css: 'max-w-full w-96 mx-auto rounded-lg', title: "hello", size: 430, srcset: [640, 768, 1024], alt: "not actually a photo", attrs: [['data-something', 'why']] } %}
</div>
<img src="/{% asset_image assets, 'dog-face.png' %}" />
</div>
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[[plugins]]
package = "netlify-plugin-cache"
[plugins.inputs]
paths = ["content/assets", "content/_data/assets.json", "webpack.hash"]
paths = ['.webpack']

[build.processing]
skip_processing = false

0 comments on commit d1675ef

Please sign in to comment.