-
Notifications
You must be signed in to change notification settings - Fork 37
Era-correctness pass: make snippets run on pinned versions #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -414,18 +414,19 @@ Now... Let's install some dependencies: | |
|
|
||
| * nodemon | ||
| * webpack | ||
| * babel-core | ||
| * @babel/core | ||
| * babel-loader | ||
| * babel-plugin-async-to-promises | ||
| * babel-plugin-syntax-dynamic-import | ||
| * @babel/plugin-syntax-dynamic-import | ||
| * babel-plugin-transform-async-to-promises | ||
| * babel-plugin-transform-runtime | ||
| * @babel/plugin-proposal-class-properties | ||
| * @babel/plugin-transform-runtime | ||
| * babel-plugin-universal-import | ||
| * babel-polyfill | ||
| * babel-preset-env | ||
| * babel-preset-es2015 | ||
| * babel-preset-react | ||
| * babel-preset-stage-2 | ||
| * @babel/polyfill | ||
| * @babel/preset-env | ||
| * @babel/preset-es2015 | ||
| * @babel/preset-react | ||
| * @babel/preset-stage-2 | ||
|
Comment on lines
+427
to
+429
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: Yes for “are they valid packages to install and reference”, but no for the intent of Babel 7 compatibility: both presets are deprecated/removed in Babel 7’s recommended preset set. 1) Citations:
Replace deprecated Babel presets for Babel 7 compatibility. Lines 427–429 list
Update the snippet and install command to reflect the correct packages for Babel 7. 🤖 Prompt for AI Agents |
||
|
|
||
| ``` | ||
| npm install --save nodemon | ||
|
|
@@ -699,17 +700,18 @@ touch public/hello.js public/hello.html public/hello.h public/hi.js | |
|
|
||
| On `webpack.config.prod.js`, add... | ||
|
|
||
| Outside the config object | ||
| Outside the config object — note we are on `clean-webpack-plugin` v3, which dropped the positional-args / `root` / `exclude` API of v1/v2 in favor of a single options object. The plugin now resolves paths from your `output.path` automatically, so we just tell it which patterns to preserve. | ||
|
|
||
| ```javascript | ||
| const path = require('path'); | ||
| const CleanWebpackPlugin = require('clean-webpack-plugin'); | ||
|
|
||
| let pathsToClean = ['dist/', 'build/', 'public/']; | ||
| const { CleanWebpackPlugin } = require('clean-webpack-plugin'); | ||
|
|
||
| let cleanOptions = { | ||
| root: path.resolve(__dirname, '../'), | ||
| exclude: ['template.html', 'manifest.json', 'favicon.ico'], | ||
| const cleanOptions = { | ||
| cleanOnceBeforeBuildPatterns: [ | ||
| '**/*', | ||
| '!template.html', | ||
| '!manifest.json', | ||
| '!favicon.ico' | ||
| ], | ||
| verbose: true, | ||
| dry: false | ||
| }; | ||
|
|
@@ -718,19 +720,18 @@ let cleanOptions = { | |
| Inside our `config/` | ||
|
|
||
| ```javascript | ||
| plugins: [new CleanWebpackPlugin(pathsToClean, cleanOptions)]; | ||
| plugins: [new CleanWebpackPlugin(cleanOptions)]; | ||
| ``` | ||
|
|
||
| Note the named import (`{ CleanWebpackPlugin }`) — v3 switched from a default export to a named one. | ||
|
|
||
| And execute: `npm run build` | ||
| _Note: It could take some time._ | ||
|
|
||
| The output will start with... | ||
| The output will look like... | ||
|
|
||
| ``` | ||
| clean-webpack-plugin: C:\practice\nocra\dist has been removed. | ||
| clean-webpack-plugin: C:\practice\nocra\build has been removed. | ||
| clean-webpack-plugin: C:\practice\nocra\public has been removed. | ||
| clean-webpack-plugin: 3 file(s) excluded - favicon.ico, manifest.json, template.html | ||
| clean-webpack-plugin: removed files inside C:\practice\nocra\public | ||
| ``` | ||
|
|
||
| And as you can see, all the dummy files were removed. Also, our bundles (\*.js) which were deleted (by clean-webpack-plugin) and re-generated (by webpack). | ||
|
|
@@ -1181,15 +1182,18 @@ const webpack = require('webpack'); | |
| const config = require('../config/webpack.config.dev.js'); | ||
| const compiler = webpack(config); | ||
|
|
||
| const webpackDevMiddleware = require('webpack-dev-middleware')( | ||
| compiler, | ||
| config.devServer | ||
| ); | ||
| // webpack-dev-middleware takes its own options object (publicPath, stats, | ||
| // mimeTypes, etc.) — NOT webpack-dev-server's `devServer` block. Passing | ||
| // `config.devServer` here would silently ignore everything inside it | ||
| // (contentBase, hot, overlay are all webpack-dev-server options). | ||
| const webpackDevMiddleware = require('webpack-dev-middleware')(compiler, { | ||
| publicPath: config.output.publicPath || '/', | ||
| stats: 'minimal' | ||
| }); | ||
|
|
||
| const webpackHotMiddleware = require('webpack-hot-middleware')( | ||
| compiler, | ||
| config.devServer | ||
| ); | ||
| // webpack-hot-middleware also has its own options object (path, log, heartbeat). | ||
| // We accept the defaults here. | ||
| const webpackHotMiddleware = require('webpack-hot-middleware')(compiler); | ||
|
|
||
| class RouterAndMiddlewares { | ||
| constructor() { | ||
|
|
@@ -1344,9 +1348,10 @@ And, in `webpack.config.js` add a new rule: | |
| { loader: 'style-loader' }, | ||
| { | ||
| loader: 'css-loader', | ||
| query: { | ||
| modules: true, | ||
| localIdentName: '[name]__[local]__[hash:base64:5]' | ||
| options: { | ||
| modules: { | ||
| localIdentName: '[name]__[local]__[hash:base64:5]' | ||
| } | ||
| } | ||
| } | ||
| ] | ||
|
|
@@ -1567,10 +1572,10 @@ And wrap everything that we don't need in `production` inside the condition: `!i | |
| let webpackDevMiddleware, webpackHotMiddleware; | ||
| if (!isProd) { | ||
| ... | ||
| webpackDevMiddleware = require('webpack-dev-middleware')( | ||
| compiler, | ||
| config.devServer | ||
| ); | ||
| webpackDevMiddleware = require('webpack-dev-middleware')(compiler, { | ||
| publicPath: config.output.publicPath || '/', | ||
| stats: 'minimal' | ||
| }); | ||
| ... | ||
| } | ||
| ``` | ||
|
|
@@ -1779,9 +1784,10 @@ In `webpack.config.js` remove or comment: | |
| { loader: 'style-loader' }, | ||
| { | ||
| loader: 'css-loader', | ||
| query: { | ||
| modules: true, | ||
| localIdentName: '[name]__[local]__[hash:base64:5]' | ||
| options: { | ||
| modules: { | ||
| localIdentName: '[name]__[local]__[hash:base64:5]' | ||
| } | ||
| } | ||
| } | ||
| ] | ||
|
|
@@ -1799,9 +1805,10 @@ module: { | |
| { loader: 'style-loader' }, | ||
| { | ||
| loader: 'css-loader', | ||
| query: { | ||
| modules: true, | ||
| localIdentName: '[name]__[local]__[hash:base64:5]' | ||
| options: { | ||
| modules: { | ||
| localIdentName: '[name]__[local]__[hash:base64:5]' | ||
| } | ||
| } | ||
| } | ||
| ] | ||
|
|
@@ -1842,9 +1849,10 @@ const cssForDev = [ | |
| { loader: 'style-loader' }, | ||
| { | ||
| loader: 'css-loader', | ||
| query: { | ||
| modules: true, | ||
| localIdentName: '[name]__[local]__[hash:base64:5]' | ||
| options: { | ||
| modules: { | ||
| localIdentName: '[name]__[local]__[hash:base64:5]' | ||
| } | ||
| } | ||
| } | ||
| ]; | ||
|
|
@@ -1972,12 +1980,13 @@ with this... | |
| ```javascript | ||
| this.app.use( | ||
| expressStaticGzip('public', { | ||
| enableBrotli: true, | ||
| orderPreference: ['br'] | ||
| enableBrotli: true | ||
| }) | ||
| ); | ||
| ``` | ||
|
|
||
| With `enableBrotli: true`, `express-static-gzip` v1 serves the pre-compressed `.br` file when the request's `Accept-Encoding` includes `br`, falling back to `.gz` (when the client only accepts gzip) and then the uncompressed asset. We don't need to spell out a preference order in v1. | ||
|
|
||
| We can also add `gzip` | ||
| Install: compression-webpack-plugin | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add language identifier to code fence.
The npm install command block should specify
bashorshellas the language identifier for proper syntax highlighting and to satisfy markdown linters.📝 Proposed fix
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
@08_redux.mdaround lines 849 - 851, The fenced code block containing the npminstall command ("npm install --save redux-thunk") lacks a language identifier;
update that fence to include a shell language (e.g., change the opening fence to
bash orshell) so the block becomesbash followed by the command and the closingto satisfy MD040 and enable proper syntax highlighting.