-
Notifications
You must be signed in to change notification settings - Fork 33
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
Webpack 5 upgrade (continued) #35
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 |
---|---|---|
@@ -1,15 +1,11 @@ | ||
import autoprefixer from 'autoprefixer' | ||
import TerserPlugin from 'terser-webpack-plugin' | ||
import MiniCssExtractPlugin from 'mini-css-extract-plugin' | ||
import CssoWebpackPlugin from 'csso-webpack-plugin' | ||
import WriteFilePlugin from 'write-file-webpack-plugin' | ||
|
||
const log = require('debug')('bp:webpack') | ||
import escapeRegex from 'escape-string-regexp' | ||
import builtinModules from 'builtin-modules' | ||
import webpack, { Entry } from 'webpack' | ||
// @ts-ignore | ||
import VueLoaderPlugin from 'vue-loader/lib/plugin' | ||
import VueLoaderPlugin from 'vue-loader/dist/plugin' | ||
|
||
import { Externals } from '../common.types' | ||
|
||
|
@@ -41,30 +37,12 @@ export default function makeWebpackConfig({ | |
|
||
log('external packages %o', externalsRegex) | ||
|
||
const builtInNode: NodeBuiltIn = {} | ||
builtinModules.forEach(mod => { | ||
builtInNode[mod] = 'empty' | ||
}) | ||
|
||
builtInNode['setImmediate'] = false | ||
builtInNode['console'] = false | ||
builtInNode['process'] = false | ||
builtInNode['Buffer'] = false | ||
|
||
// Don't mark an import as built in if it is the name of the package itself | ||
// eg. `events` | ||
if (builtInNode[packageName]) { | ||
builtInNode[packageName] = false | ||
} | ||
|
||
// @ts-ignore | ||
// @ts-ignore | ||
return { | ||
entry: entry, | ||
mode: 'production', | ||
// bail: true, | ||
optimization: { | ||
namedChunks: true, | ||
chunkIds: 'named', | ||
runtimeChunk: { name: 'runtime' }, | ||
minimize: true, | ||
splitChunks: { | ||
|
@@ -78,29 +56,20 @@ export default function makeWebpackConfig({ | |
}, | ||
}, | ||
minimizer: [ | ||
new TerserPlugin({ | ||
parallel: true, | ||
terserOptions: { | ||
ie8: false, | ||
output: { | ||
comments: false, | ||
}, | ||
}, | ||
}), | ||
'...', | ||
// @ts-ignore: Appears that the library might have incorrect definitions | ||
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. zoobestik/csso-webpack-plugin#18 will fix this if they publish a new version |
||
new CssoWebpackPlugin({ restructure: false }), | ||
], | ||
}, | ||
plugins: [ | ||
new webpack.IgnorePlugin(/^electron$/), | ||
new webpack.IgnorePlugin({ resourceRegExp: /^electron$/ }), | ||
new VueLoaderPlugin(), | ||
new MiniCssExtractPlugin({ | ||
// Options similar to the same options in webpackOptions.output | ||
// both options are optional | ||
filename: '[name].bundle.css', | ||
chunkFilename: '[id].bundle.css', | ||
}), | ||
...(debug ? [new WriteFilePlugin()] : []), | ||
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. i don't fully understand what this was doing, another for @pastelsky. it was writing the output to disk during watch mode i guess but to what end? the plugin doesn't support webpack 5 so im wondering/hoping we can drop it |
||
], | ||
resolve: { | ||
modules: ['node_modules'], | ||
|
@@ -135,22 +104,24 @@ export default function makeWebpackConfig({ | |
test: /\.js$/, | ||
use: [require.resolve('shebang-loader')], // support CLI tools that start with a #!/usr/bin/node | ||
}, | ||
{ | ||
test: /\.vue$/, | ||
// NOTE: vue-loader has a side-effect here where it will also match | ||
// *.vue.html, so it _must_ come before other .html loaders | ||
use: 'vue-loader', | ||
}, | ||
{ | ||
test: /\.(html|svelte)$/, | ||
use: { | ||
loader: require.resolve('svelte-loader'), | ||
loader: 'svelte-loader', | ||
options: { | ||
emitCss: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
test: /\.vue$/, | ||
loader: require.resolve('vue-loader'), | ||
}, | ||
{ | ||
test: /\.(scss|sass)$/, | ||
loader: [ | ||
use: [ | ||
MiniCssExtractPlugin.loader, | ||
require.resolve('css-loader'), | ||
{ | ||
|
@@ -174,7 +145,7 @@ export default function makeWebpackConfig({ | |
}, | ||
{ | ||
test: /\.less$/, | ||
loader: [ | ||
use: [ | ||
MiniCssExtractPlugin.loader, | ||
require.resolve('css-loader'), | ||
{ | ||
|
@@ -211,14 +182,14 @@ export default function makeWebpackConfig({ | |
}, | ||
], | ||
}, | ||
node: builtInNode, | ||
node: false, | ||
output: { | ||
filename: 'bundle.js', | ||
pathinfo: false, | ||
}, | ||
externals: (context, request, callback) => | ||
isExternalRequest(request) | ||
? callback(null, 'commonjs ' + request) | ||
externals: ({ context, request }, callback) => | ||
request && isExternalRequest(request) | ||
? callback(undefined, 'commonjs ' + request) | ||
: callback(), | ||
} | ||
} | ||
|
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.
@pastelsky this has since changed in webpack. we now set
node: false
to tell it not to polyfill any builtins. but losing thisif
concerns me, would you be able to explain what the intention of this whole block was (builtInNode
) and if disabling it entirely will suffice?