More progress in webpack guides
This commit is contained in:
3752
frontend/package-lock.json
generated
3752
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,14 +5,21 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"watch": "webpack --watch",
|
||||
"start": "webpack serve --open",
|
||||
"server": "node server.js",
|
||||
"build": "webpack"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"express": "^4.17.1",
|
||||
"html-webpack-plugin": "^5.3.1",
|
||||
"webpack": "^5.31.0",
|
||||
"webpack-cli": "^4.6.0"
|
||||
"webpack-cli": "^4.6.0",
|
||||
"webpack-dev-middleware": "^4.1.0",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.21"
|
||||
|
||||
20
frontend/server.js
Normal file
20
frontend/server.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const express = require('express');
|
||||
const webpack = require('webpack');
|
||||
const webpackDevMiddleware = require('webpack-dev-middleware');
|
||||
|
||||
const app = express();
|
||||
const config = require('./webpack.config.js');
|
||||
const compiler = webpack(config);
|
||||
|
||||
// Tell express to use the webpack-dev-middleware and use the webpack.config.js
|
||||
// configuration file as a base.
|
||||
app.use(
|
||||
webpackDevMiddleware(compiler, {
|
||||
publicPath: config.output.publicPath,
|
||||
})
|
||||
);
|
||||
|
||||
// Serve the files on port 3000.
|
||||
app.listen(3000, function () {
|
||||
console.log('Example app listening on port 3000!\n');
|
||||
});
|
||||
@@ -1,18 +1,12 @@
|
||||
import _ from "lodash";
|
||||
import "./style.css";
|
||||
import Icon from './ship.png';
|
||||
import Print from "./print";
|
||||
|
||||
function component() {
|
||||
const element = document.createElement("div");
|
||||
|
||||
// Lodash, currently included via a script, is required for this line to work
|
||||
// Lodash, now imported by this script
|
||||
element.innerHTML = _.join(["Hello", "webpack"], " ");
|
||||
element.classList.add("hello");
|
||||
|
||||
const myIcon = new Image();
|
||||
myIcon.src = Icon;
|
||||
|
||||
element.appendChild(myIcon);
|
||||
element.onclick = Print.bind(null, "Hello webpack!");
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
3
frontend/src/print.js
Normal file
3
frontend/src/print.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function print(text) {
|
||||
console.log(text);
|
||||
}
|
||||
@@ -1,9 +1,35 @@
|
||||
const path = require("path");
|
||||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
entry: "./src/index.js",
|
||||
mode: 'development',
|
||||
entry: './src/index.js',
|
||||
devtool: 'inline-source-map',
|
||||
devServer: {
|
||||
contentBase: './dist',
|
||||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
title: 'Caching',
|
||||
})
|
||||
],
|
||||
output: {
|
||||
filename: "bundle.js",
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
filename: '[name].[contenthash].js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
clean: true,
|
||||
publicPath: '/',
|
||||
},
|
||||
optimization: {
|
||||
moduleIds: 'deterministic',
|
||||
runtimeChunk: 'single',
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
vendor: {
|
||||
test: /[\\/]node_modules[\\/]/,
|
||||
name: 'vendors',
|
||||
chunks: 'all',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user