Merge branch 'dev' into fix_hml

This commit is contained in:
Surma
2020-07-20 11:35:28 +01:00
committed by GitHub
16 changed files with 312 additions and 248 deletions

View File

@@ -18,14 +18,15 @@ const addCssTypes = require('./config/add-css-types');
const VERSION = require('./package.json').version;
module.exports = async function (_, env) {
/** @returns {Promise<import('webpack').Configuration>} */
module.exports = async function(_, env) {
const isProd = env.mode === 'production';
const nodeModules = path.join(__dirname, 'node_modules');
const componentStyleDirs = [
path.join(__dirname, 'src/components'),
path.join(__dirname, 'src/codecs'),
path.join(__dirname, 'src/custom-els'),
path.join(__dirname, 'src/lib'),
path.join(__dirname, 'src', 'components'),
path.join(__dirname, 'src', 'codecs'),
path.join(__dirname, 'src', 'custom-els'),
path.join(__dirname, 'src', 'lib')
];
await addCssTypes(componentStyleDirs, { watch: !isProd });
@@ -53,18 +54,17 @@ module.exports = async function (_, env) {
resolveLoader: {
alias: {
// async-component-loader returns a wrapper component that waits for the import to load before rendering:
async: path.join(__dirname, 'config/async-component-loader')
async: path.join(__dirname, 'config', 'async-component-loader')
}
},
module: {
// Disable the default JavaScript handling:
defaultRules: [],
rules: [
{
oneOf: [
{
test: /(\.mjs|\.esm\.js)$/i,
type: 'javascript/esm',
// don't use strict esm resolution for mjs:
type: 'javascript/auto',
resolve: {},
parser: {
harmony: true,
@@ -143,7 +143,7 @@ module.exports = async function (_, env) {
{
// All the codec files define a global with the same name as their file name. `exports-loader` attaches those to `module.exports`.
test: /\.js$/,
include: path.join(__dirname, 'src/codecs'),
include: path.join(__dirname, 'src', 'codecs'),
loader: 'exports-loader'
},
{
@@ -183,6 +183,7 @@ module.exports = async function (_, env) {
format: '\u001b[90m\u001b[44mBuild\u001b[49m\u001b[39m [:bar] \u001b[32m\u001b[1m:percent\u001b[22m\u001b[39m (:elapseds) \u001b[2m:msg\u001b[22m\r',
renderThrottle: 100,
summary: false,
total: 10,
clear: true
}),
@@ -191,17 +192,13 @@ module.exports = async function (_, env) {
'assets',
'**/*.{css,js,json,html,map}'
], {
root: path.join(__dirname, 'build'),
verbose: false,
beforeEmit: true
}),
root: path.join(__dirname, 'build'),
verbose: false,
beforeEmit: true
}),
new WorkerPlugin(),
// Automatically split code into async chunks.
// See: https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
isProd && new webpack.optimize.SplitChunksPlugin({}),
// In production, extract all CSS to produce files on disk, even for
// lazy-loaded CSS chunks. CSS for async chunks is loaded on-demand.
// This is a modern Webpack 4 replacement for ExtractTextPlugin.
@@ -302,6 +299,10 @@ module.exports = async function (_, env) {
].filter(Boolean), // Filter out any falsey plugin array entries.
optimization: {
splitChunks: {
// Automatically split code into async chunks.
// See: https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
},
minimizer: [
new TerserPlugin({
sourceMap: isProd,