Closed as not planned
Description
webpack-encore: 1.1.2
When setting the host to craft-boilerplate.localhost
the webpack-dev-server resolves it to 127.0.0.1
and starts the dev-server:
This behaviour can be triggered using either the host
parameter in the dev-server options or via the --host
flag.
I wanted the dev server to run on a custom host craft-boilerplate.localhost
so I could use the same locally generated SSL certificate for the project.
Additionally the manifest.json
produced still points to https://localhost:8080
:
{
"theme/dist/app.css": "https://localhost:8080/theme/dist/app.css",
"theme/dist/app.js": "https://localhost:8080/theme/dist/app.js",
"theme/dist/runtime.js": "https://localhost:8080/theme/dist/runtime.js",
"theme/dist/vendors-node_modules_webpack-dev-server_client_default_index_js_https_craft-boilerplate_local-4ef0ad.js": "https://localhost:8080/theme/dist/vendors-node_modules_webpack-dev-server_client_default_index_js_https_craft-boilerplate_local-4ef0ad.js",
"theme/dist/images/pattern.png": "https://localhost:8080/theme/dist/images/pattern.c1e510cc.png",
"theme/dist/images/logo.svg": "https://localhost:8080/theme/dist/images/logo.8c23ac65.svg"
}
Dev server config:
.configureDevServerOptions(options => {
options = {
...options,
firewall: false,
https: {
key: fs.readFileSync(process.env.SSL_KEY),
cert: fs.readFileSync(process.env.SSL_CERT),
},
// liveReload and static are used to reload the whole page
// when anything in templates changes
liveReload: true,
static: {
directory: path.resolve(__dirname, 'templates'),
publicPath: '/',
serveIndex: true,
watch: true,
},
host: 'craft-boilerplate.localhost',
port: '3000'
})
bash command:
encore dev-server --host craft-boilerplate.localhost
Full webpack config:
require('dotenv-flow').config();
const path = require('path');
const fs = require('fs');
const Encore = require('@symfony/webpack-encore');
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
// directory where compiled assets will be stored
.setOutputPath('public/theme/dist/')
// public path used by the web server to access the output path
.setPublicPath('/theme/dist')
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')
/*
* ENTRY CONFIG
*
* Add 1 entry for each "page" of your app
* (including one that's included on every page - e.g. "app")
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
*/
.addEntry('app', './public/theme/src/scripts/index.js')
//.addEntry('page1', './assets/page1.js')
//.addEntry('page2', './assets/page2.js')
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
.splitEntryChunks()
// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()
/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
// .enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
// enables post-css-loader
.enablePostCssLoader()
// enables @babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = 3;
})
.copyFiles({
from: './public/theme/src/images',
to: 'images/[path][name].[hash:8].[ext]',
})
.configureDevServerOptions(options => {
options = {
...options,
firewall: false,
https: {
key: fs.readFileSync(process.env.SSL_KEY),
cert: fs.readFileSync(process.env.SSL_CERT),
},
// liveReload and static are used to reload the whole page
// when anything in templates changes
liveReload: true,
static: {
directory: path.resolve(__dirname, 'templates'),
publicPath: '/',
serveIndex: true,
watch: true,
}
}
return options;
})
;
let config = Encore.getWebpackConfig();
module.exports = config;