Skip to content

Commit

Permalink
debug webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Oct 11, 2024
1 parent fea3cb9 commit 2cabcbc
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 84 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ci
on: [push, pull_request]
on: push

jobs:
test:
Expand All @@ -11,7 +11,6 @@ jobs:
with:
node-version: '20'
- run: npm install
- run: npm test
- run: npm run build

- name: Get REV
Expand Down
164 changes: 82 additions & 82 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,88 +224,88 @@ function makeContentScript(name) {
if (!DEV) fse.emptyDirSync(DST + ASSETS);

module.exports = [
mergeCfg({
entry: Object.fromEntries(PAGES.map(p => [p, `/${p}/index`])),
output: {
filename: ASSETS + '[name].js',
chunkFilename: ASSETS + '[name].js',
},
optimization: {
splitChunks: {
chunks: /^(?!.*[/\\]shim)/,
cacheGroups: {
codemirror: {
test: new RegExp(String.raw`(${anyPathSep([
SRC + 'cm/',
String.raw`codemirror(/|-(?!factory))`,
].join('|'))}).+\.js$`),
name: 'codemirror',
},
...Object.fromEntries([
[2, 'common-ui', `^${SRC}(content/|js/(dom|localization|themer))`],
[1, 'common', `^${SRC}js/|/lz-string(-unsafe)?/`],
].map(([priority, name, test]) => [name, {
test: new RegExp(String.raw`(${anyPathSep(test)})[^./\\]*\.js$`),
name,
priority,
}])),
},
},
},
plugins: [
defineVars({
PAGE: true,
THEMES: THEME_NAMES,
}),
new MiniCssExtractPlugin({
filename: ASSETS + '[name].css',
chunkFilename: ASSETS + '[name].css',
}),
...PAGES.map(p => new HtmlWebpackPlugin({
chunks: [p],
filename: p + '.html',
template: SRC + p + '.html',
templateParameters: (compilation, files, tags, options) => {
const {bodyTags, headTags} = tags;
// The main entry goes into BODY to improve performance (2x in manage.html)
headTags.push(...bodyTags.splice(0, bodyTags.length - 1));
return {
compilation: compilation,
webpackConfig: compilation.options,
htmlWebpackPlugin: {tags, files, options},
};
},
scriptLoading: 'blocking',
inject: false,
})),
new CopyPlugin({
patterns: [
{context: SRC + 'content', from: 'install*.js', to: DST + JS, info: {minimized: true}},
{context: SRC + 'images', from: 'eyedropper/**', to: DST + ASSETS},
{context: SRC + 'images', from: 'icon/**', to: DST + ASSETS},
{context: SRC, from: 'manifest.json', to: DST},
{context: SRC, from: '_locales/**', to: DST},
{context: THEME_PATH, from: '*.css', to: DST + ASSETS_CM},
...[
['stylelint-bundle', 'stylelint.js'],
['less/dist/less.min.js', 'less.js'],
['stylus-lang-bundle/dist/stylus-renderer.min.js', 'stylus-lang.js'],
].map(([npm, to]) => ({
from: require.resolve(npm),
to: DST + JS + to,
info: {minimized: true},
transform: stripSourceMap,
})),
],
}),
],
resolve: {
modules: [
SHIM,
'node_modules',
],
},
}),
// mergeCfg({
// entry: Object.fromEntries(PAGES.map(p => [p, `/${p}/index`])),
// output: {
// filename: ASSETS + '[name].js',
// chunkFilename: ASSETS + '[name].js',
// },
// optimization: {
// splitChunks: {
// chunks: /^(?!.*[/\\]shim)/,
// cacheGroups: {
// codemirror: {
// test: new RegExp(String.raw`(${anyPathSep([
// SRC + 'cm/',
// String.raw`codemirror(/|-(?!factory))`,
// ].join('|'))}).+\.js$`),
// name: 'codemirror',
// },
// ...Object.fromEntries([
// [2, 'common-ui', `^${SRC}(content/|js/(dom|localization|themer))`],
// [1, 'common', `^${SRC}js/|/lz-string(-unsafe)?/`],
// ].map(([priority, name, test]) => [name, {
// test: new RegExp(String.raw`(${anyPathSep(test)})[^./\\]*\.js$`),
// name,
// priority,
// }])),
// },
// },
// },
// plugins: [
// defineVars({
// PAGE: true,
// THEMES: THEME_NAMES,
// }),
// new MiniCssExtractPlugin({
// filename: ASSETS + '[name].css',
// chunkFilename: ASSETS + '[name].css',
// }),
// ...PAGES.map(p => new HtmlWebpackPlugin({
// chunks: [p],
// filename: p + '.html',
// template: SRC + p + '.html',
// templateParameters: (compilation, files, tags, options) => {
// const {bodyTags, headTags} = tags;
// // The main entry goes into BODY to improve performance (2x in manage.html)
// headTags.push(...bodyTags.splice(0, bodyTags.length - 1));
// return {
// compilation: compilation,
// webpackConfig: compilation.options,
// htmlWebpackPlugin: {tags, files, options},
// };
// },
// scriptLoading: 'blocking',
// inject: false,
// })),
// new CopyPlugin({
// patterns: [
// {context: SRC + 'content', from: 'install*.js', to: DST + JS, info: {minimized: true}},
// {context: SRC + 'images', from: 'eyedropper/**', to: DST + ASSETS},
// {context: SRC + 'images', from: 'icon/**', to: DST + ASSETS},
// {context: SRC, from: 'manifest.json', to: DST},
// {context: SRC, from: '_locales/**', to: DST},
// {context: THEME_PATH, from: '*.css', to: DST + ASSETS_CM},
// ...[
// ['stylelint-bundle', 'stylelint.js'],
// ['less/dist/less.min.js', 'less.js'],
// ['stylus-lang-bundle/dist/stylus-renderer.min.js', 'stylus-lang.js'],
// ].map(([npm, to]) => ({
// from: require.resolve(npm),
// to: DST + JS + to,
// info: {minimized: true},
// transform: stripSourceMap,
// })),
// ],
// }),
// ],
// resolve: {
// modules: [
// SHIM,
// 'node_modules',
// ],
// },
// }),
makeContentScript('apply.js'),
makeLibrary([
'/background/background-worker.js',
Expand Down

0 comments on commit 2cabcbc

Please sign in to comment.