Skip to content

Commit

Permalink
build: configure webpack to use inline script plugin under dev server
Browse files Browse the repository at this point in the history
  • Loading branch information
icelam committed Nov 24, 2022
1 parent 0400cc0 commit 71f3cb0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import initParticles from '@js/background';

initParticles();

// Try adding some console log below to test for webpack dev server
console.log('Change me to test hotreload ability. Also tries refreshing the browser after severl changes.');
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* eslint-disable import/no-import-module-exports */
import 'core-js/stable';

// CSS
import '@style/index.scss';
import '@js/app';

// Needed for hot reload to work under dev server
if (module.hot) {
module.hot.accept();
}
2 changes: 2 additions & 0 deletions webpack/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlInlineScriptPlugin = require('html-inline-script-webpack-plugin');
const HtmlVariablesPlugin = require('html-variables-plugin');

module.exports = {
Expand Down Expand Up @@ -37,6 +38,7 @@ module.exports = {
},
inject: 'body'
}),
new HtmlInlineScriptPlugin(),
new HtmlVariablesPlugin(process.env)
],
resolve: {
Expand Down
3 changes: 2 additions & 1 deletion webpack/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ module.exports = merge(baseWebpackConfig, {
devServer: {
host: '0.0.0.0',
port: 8888,
watchFiles: ["src/**/*"],
watchFiles: ['src/index.html'],
hot: true,
client: {
overlay: {
warnings: false,
Expand Down
4 changes: 1 addition & 3 deletions webpack/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const dotenv = require('dotenv');
const { merge } = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { default: HTMLInlineCSSWebpackPlugin } = require('html-inline-css-webpack-plugin');
const HtmlInlineScriptPlugin = require('html-inline-script-webpack-plugin');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
const baseWebpackConfig = require('./webpack.base.conf');
Expand Down Expand Up @@ -42,8 +41,7 @@ module.exports = merge(baseWebpackConfig, {
new MiniCssExtractPlugin({
filename: 'assets/css/[name].[chunkhash:8].css'
}),
new HTMLInlineCSSWebpackPlugin(),
new HtmlInlineScriptPlugin()
new HTMLInlineCSSWebpackPlugin()
],
module: {
rules: [
Expand Down

0 comments on commit 71f3cb0

Please sign in to comment.