Skip to content

Instantly share code, notes, and snippets.

@ben-rogerson
Last active February 23, 2020 02:31
Show Gist options
  • Save ben-rogerson/52936be5aef3f0c9d06f0eda33958976 to your computer and use it in GitHub Desktop.
Save ben-rogerson/52936be5aef3f0c9d06f0eda33958976 to your computer and use it in GitHub Desktop.
Config for agency-webpack-mix-config and Craft Twigpack
{# This is the base twig layout file #}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{ craft.twigpack.includeCriticalCssTags() }}
{{ craft.twigpack.includeCssModule("/main.css") }}
</head>
<body data-icons="{{ craft.twigpack.getModuleUri("/sprite.svg") }}">
{% block content %}{% endblock %}
{{ craft.twigpack.includeJsModule("/manifest.js") }}
{{ craft.twigpack.includeJsModule("/vendor.js") }}
{{ craft.twigpack.includeJsModule("/main.js") }}
{{ endBody() }}
</body>
</html>
<?php
// Place this in: config/twigpack.php
return [
// Global settings
'*' => [
// If `devMode` is on, use webpack-dev-server to all for HMR (hot module reloading)
'useDevServer' => true,
// Don't force fully qualified absolute URLs
'useAbsoluteUrl' => false,
// The JavaScript entry from the manifest.json to inject on Twig error pages
'errorEntry' => '',
// Manifest file names
'manifest' => [
'legacy' => 'dist/mix-manifest.json',
'modern' => 'dist/mix-manifest.json',
],
// Public server config
'server' => [
'manifestPath' => '@webroot/',
'publicPath' => '/dist/',
],
// webpack-dev-server config
'devServer' => [
'manifestPath' => 'https://localhost:8080/',
'publicPath' => 'https://localhost:8080/',
],
// Local files config
'localFiles' => [
'basePath' => '@webroot/',
'criticalPrefix' => 'dist/',
'criticalSuffix' => '-critical.css',
],
],
// Live (production) environment
'live' => [
],
// Staging (pre-production) environment
'staging' => [
],
// Local (development) environment
'local' => [
// If `devMode` is on, use webpack-dev-server to all for HMR (hot module reloading)
'useDevServer' => true,
],
];
@ben-rogerson
Copy link
Author

Also, when you run the webpack-dev-server (npm run dev) you can see what files it's loading into memory at: https://localhost:8080/webpack-dev-server

@ben-rogerson
Copy link
Author

ben-rogerson commented Sep 4, 2019

Read the Twigpack docs for more info: https://nystudio107.com/plugins/twigpack/documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment