Replace Asset References with a data file instead of paths (#96)

* Add assets-webpack-plugin

Signed-off-by: budparr <budparr@gmail.com>

* Add generated Webpack Assets file

This file is generated by Webpack and writes the names of our hashed assets

Signed-off-by: budparr <budparr@gmail.com>

* Update stylesheet

Note sure why this was updated

Signed-off-by: budparr <budparr@gmail.com>

* Add CSS file from generated file

Replaces hardcoded path

Signed-off-by: budparr <budparr@gmail.com>
This commit is contained in:
Bud Parr 2018-04-10 18:35:56 -04:00 committed by GitHub
parent 1f3b6f5598
commit 8b43f4662e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 152 additions and 23 deletions

6
data/webpack_assets.json Normal file
View File

@ -0,0 +1,6 @@
{
"app": {
"js": "js/app.3fc0f988d21662902933.js",
"css": "css/app.ab4b67a3ea25990fa8279f3b7ef08b61.css"
}
}

View File

@ -17,13 +17,12 @@
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
{{ end }}
{{ $css_path := $.Param "dev.css_path" | default "themes/gohugo-theme-ananke/static/dist/css" }}
{{ with $css_path }}
{{ range readDir . }}
<link href='/dist/css/{{ .Name }}' rel='stylesheet' type="text/css" data-turbolinks-track="reload" />
{{ end }}
{{ $stylesheet := .Site.Data.webpack_assets.app }}
{{ with $stylesheet.css }}
<link href="{{ printf "%s%s" "/dist/" . }}" rel="stylesheet">
{{ end }}
{{ block "favicon" . }}
{{ partial "site-favicon.html" . }}
{{ end }}

View File

@ -1,6 +1,4 @@
{{ $css_path := $.Param "dev.js_path" | default "themes/gohugo-theme-ananke/static/dist/js" }}
{{ with $css_path }}
{{ range readDir . }}
<link href='/dist/js/{{ .Name }}' rel='stylesheet' type="text/css" data-turbolinks-track="reload" />
{{ end }}
{{ $script := .Site.Data.webpack_assets.app }}
{{ with $script.js }}
<script src="{{ printf "%s%s" "/dist/" . }}"></script>
{{ end }}

View File

@ -12,6 +12,7 @@
"start": "npm run build"
},
"devDependencies": {
"assets-webpack-plugin": "^3.5.1",
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.4.0",

View File

@ -1,6 +1,8 @@
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var webpack = require('webpack');
var AssetsPlugin = require('assets-webpack-plugin');
module.exports = {
entry: {
app: './js/main.js'
@ -14,7 +16,6 @@ module.exports = {
loader: 'babel-loader',
options: {
presets: ['env']
// plugins: [require('babel-plugin-transform-object-rest-spread')]
}
}
},
@ -38,16 +39,17 @@ module.exports = {
},
plugins: [
new AssetsPlugin({
filename: 'webpack_assets.json',
path: path.join(__dirname, '../data'),
prettyPrint: true
}),
new ExtractTextPlugin({
filename: getPath => {
return getPath('css/[name].[contenthash].css');
},
allChunks: true
})
// new webpack.ProvidePlugin({
// $: "jquery",
// jQuery: "jquery"
// })
],
watchOptions: {
watch: true

View File

@ -119,6 +119,16 @@ assert@^1.1.1:
dependencies:
util "0.10.3"
assets-webpack-plugin@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/assets-webpack-plugin/-/assets-webpack-plugin-3.5.1.tgz#931ce0d66d42e88ed5e7f18d65522943c57a387d"
dependencies:
camelcase "^1.2.1"
escape-string-regexp "^1.0.3"
lodash.assign "^3.2.0"
lodash.merge "^3.3.2"
mkdirp "^0.5.1"
async-each@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d"
@ -764,7 +774,7 @@ builtin-status-codes@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8"
camelcase@^1.0.2:
camelcase@^1.0.2, camelcase@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39"
@ -1221,7 +1231,7 @@ error-ex@^1.2.0:
dependencies:
is-arrayish "^0.2.1"
escape-string-regexp@^1.0.2:
escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.3:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
@ -1821,18 +1831,124 @@ loader-utils@^1.0.2:
emojis-list "^2.0.0"
json5 "^0.5.0"
lodash._arraycopy@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._arraycopy/-/lodash._arraycopy-3.0.0.tgz#76e7b7c1f1fb92547374878a562ed06a3e50f6e1"
lodash._arrayeach@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._arrayeach/-/lodash._arrayeach-3.0.0.tgz#bab156b2a90d3f1bbd5c653403349e5e5933ef9e"
lodash._baseassign@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e"
dependencies:
lodash._basecopy "^3.0.0"
lodash.keys "^3.0.0"
lodash._basecopy@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36"
lodash._basefor@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash._basefor/-/lodash._basefor-3.0.3.tgz#7550b4e9218ef09fad24343b612021c79b4c20c2"
lodash._bindcallback@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
lodash._createassigner@^3.0.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/lodash._createassigner/-/lodash._createassigner-3.1.1.tgz#838a5bae2fdaca63ac22dee8e19fa4e6d6970b11"
dependencies:
lodash._bindcallback "^3.0.0"
lodash._isiterateecall "^3.0.0"
lodash.restparam "^3.0.0"
lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
lodash._isiterateecall@^3.0.0:
version "3.0.9"
resolved "https://registry.yarnpkg.com/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz#5203ad7ba425fae842460e696db9cf3e6aac057c"
lodash._reinterpolate@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
lodash.assign@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-3.2.0.tgz#3ce9f0234b4b2223e296b8fa0ac1fee8ebca64fa"
dependencies:
lodash._baseassign "^3.0.0"
lodash._createassigner "^3.0.0"
lodash.keys "^3.0.0"
lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
lodash.isarguments@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a"
lodash.isarray@^3.0.0:
version "3.0.4"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55"
lodash.isplainobject@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-3.2.0.tgz#9a8238ae16b200432960cd7346512d0123fbf4c5"
dependencies:
lodash._basefor "^3.0.0"
lodash.isarguments "^3.0.0"
lodash.keysin "^3.0.0"
lodash.istypedarray@^3.0.0:
version "3.0.6"
resolved "https://registry.yarnpkg.com/lodash.istypedarray/-/lodash.istypedarray-3.0.6.tgz#c9a477498607501d8e8494d283b87c39281cef62"
lodash.keys@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a"
dependencies:
lodash._getnative "^3.0.0"
lodash.isarguments "^3.0.0"
lodash.isarray "^3.0.0"
lodash.keysin@^3.0.0:
version "3.0.8"
resolved "https://registry.yarnpkg.com/lodash.keysin/-/lodash.keysin-3.0.8.tgz#22c4493ebbedb1427962a54b445b2c8a767fb47f"
dependencies:
lodash.isarguments "^3.0.0"
lodash.isarray "^3.0.0"
lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
lodash.merge@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-3.3.2.tgz#0d90d93ed637b1878437bb3e21601260d7afe994"
dependencies:
lodash._arraycopy "^3.0.0"
lodash._arrayeach "^3.0.0"
lodash._createassigner "^3.0.0"
lodash._getnative "^3.0.0"
lodash.isarguments "^3.0.0"
lodash.isarray "^3.0.0"
lodash.isplainobject "^3.0.0"
lodash.istypedarray "^3.0.0"
lodash.keys "^3.0.0"
lodash.keysin "^3.0.0"
lodash.toplainobject "^3.0.0"
lodash.restparam@^3.0.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
lodash.template@^4.2.4:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0"
@ -1846,6 +1962,13 @@ lodash.templatesettings@^4.0.0:
dependencies:
lodash._reinterpolate "~3.0.0"
lodash.toplainobject@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash.toplainobject/-/lodash.toplainobject-3.0.0.tgz#28790ad942d293d78aa663a07ecf7f52ca04198d"
dependencies:
lodash._basecopy "^3.0.0"
lodash.keysin "^3.0.0"
lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
@ -3155,9 +3278,9 @@ svgo@^0.7.0:
sax "~1.2.1"
whet.extend "~0.9.9"
tachyons@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/tachyons/-/tachyons-4.7.0.tgz#228eed0badca01cf793ef7cc6103a60c8f8b0f3e"
tachyons@^4.9.1:
version "4.9.1"
resolved "https://registry.yarnpkg.com/tachyons/-/tachyons-4.9.1.tgz#f88d7059d6e53c833bf9351a26f18314c8fdc76a"
tapable@^0.2.5, tapable@~0.2.5:
version "0.2.6"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long