Skip to content

Commit

Permalink
update misc test dependencies, update test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
bholloway committed May 20, 2021
1 parent 5ff7a18 commit aab579b
Show file tree
Hide file tree
Showing 17 changed files with 248 additions and 450 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "webpack4-sassloader8-nodesass4",
"version": "1.0.0",
"engines": {
"node": ">=10"
"node": ">=12.0.0"
},
"dependencies": {
"css-loader": "^4.3.0",
"file-loader": "^5.1.0",
"css-loader": "^5.2.4",
"file-loader": "^6.2.0",
"last-call-webpack-plugin": "^3.0.0",
"mini-css-extract-plugin": "^0.8.0",
"mini-css-extract-plugin": "^1.6.0",
"node-sass": "^4.14.1",
"optimize-css-assets-webpack-plugin": "^5.0.4",
"sass-loader": "^8.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const path = require('path');
const LastCallWebpackPlugin = require('last-call-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const processFn = require('adjust-sourcemap-loader/lib/process');

module.exports = {
entry: path.join(__dirname, process.env.ENTRY),
output: {
path: path.join(__dirname, process.env.OUTPUT),
filename: '[name].js',
publicPath: '',
devtoolModuleFilenameTemplate: '[resource-path]',
devtoolFallbackModuleFilenameTemplate: '[resource-path]',
},
Expand All @@ -26,6 +26,12 @@ module.exports = {
{
loader: 'css-loader',
options: JSON.parse(process.env.CSS_OPTIONS)
}, {
loader: 'adjust-sourcemap-loader',
options: {
debug: true,
format: 'projectRelative'
}
}, {
loader: 'resolve-url-loader',
options: Object.assign(
Expand Down Expand Up @@ -61,8 +67,11 @@ module.exports = {
phase: LastCallWebpackPlugin.PHASES.EMIT,
regExp: /\.css\.map/,
processor: (assetName, asset) => Promise.resolve(JSON.parse(asset.source()))
.then(obj => processFn({}, {format: 'projectRootRelative'}, obj))
.then(obj => JSON.stringify(obj))
.then((obj) => ({
...obj,
sources: obj.sources.map((source) => source.replace('webpack://', ''))
}))
.then((obj) => JSON.stringify(obj))
}]
})
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
},
"dependencies": {
"css-loader": "^5.2.4",
"css-minimizer-webpack-plugin": "^3.0.0",
"file-loader": "^6.2.0",
"last-call-webpack-plugin": "^3.0.0",
"mini-css-extract-plugin": "^1.6.0",
"node-sass": "^6.0.0",
"optimize-css-assets-webpack-plugin": "^5.0.4",
"sass-loader": "^11.0.1",
"webpack": "^5.36.2",
"webpack-cli": "^4.7.0"
},
"scripts": {
"webpack-d": "webpack --no-color --output-pathinfo --mode=development",
"webpack-p": "webpack --no-color --mode=production"
"webpack-d": "cross-env NODE_ENV=development webpack --no-color --output-pathinfo",
"webpack-p": "cross-env NODE_ENV=production webpack --no-color"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';

const path = require('path');
const LastCallWebpackPlugin = require('last-call-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const SourceMapDevToolPlugin = require('webpack').SourceMapDevToolPlugin;
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const processFn = require('adjust-sourcemap-loader/lib/process');

class DegeneratePlugin {
apply() {}
}

module.exports = {
entry: path.join(__dirname, process.env.ENTRY),
Expand All @@ -15,7 +18,7 @@ module.exports = {
devtoolModuleFilenameTemplate: '[resource-path]',
devtoolFallbackModuleFilenameTemplate: '[resource-path]',
},
devtool: JSON.parse(process.env.DEVTOOL) && 'nosources-source-map',
devtool: false,
resolve: {
modules: [path.join(__dirname, 'modules'), 'node_modules'] // specifically for isolation in module-relative test
},
Expand Down Expand Up @@ -53,29 +56,27 @@ module.exports = {
}]
},
plugins: [
JSON.parse(process.env.DEVTOOL) ? new SourceMapDevToolPlugin({
filename: '[file].map',
moduleFilenameTemplate: '[resource-path]',
append: process.env.NODE_ENV !== 'production' && undefined,
noSources: true
}) : new DegeneratePlugin(),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
}),
// currently devtoolModuleFilenameTemplate is not respected by OptimizeCSSAssetsPlugin so we must do it ourselves
new LastCallWebpackPlugin({
assetProcessors: [{
phase: LastCallWebpackPlugin.PHASES.EMIT,
regExp: /\.css\.map/,
processor: (assetName, asset) => Promise.resolve(JSON.parse(asset.source()))
.then(obj => processFn({}, {format: 'projectRootRelative'}, obj))
.then(obj => JSON.stringify(obj))
}]
})
],
optimization: {
minimizer: [
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
map: !!JSON.parse(process.env.DEVTOOL),
// the following optimisations are fine but e2e assertions are easier without them
cssDeclarationSorter: false,
normalizeUrl: false,
discardUnused: false
new CssMinimizerPlugin({
minimizerOptions: {
processorOptions: {
map: !!JSON.parse(process.env.DEVTOOL) && {inline: false},
// the following optimisations are fine but e2e assertions are easier without them
cssDeclarationSorter: false,
normalizeUrl: false,
discardUnused: false
}
}
})
]
Expand Down
25 changes: 3 additions & 22 deletions test/cases/absolute-asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,7 @@ module.exports = test(
assertNoErrors,
assertDebugMessages,
assertCssSourceMapComment(true),
compose(onlyMeta('meta.version.webpack == 4'), assertCssContent, outdent)`
.some-class-name {
single-quoted: url(d68e763c825dc0e388929ae1b375ce18.jpg);
double-quoted: url(d68e763c825dc0e388929ae1b375ce18.jpg);
unquoted: url(d68e763c825dc0e388929ae1b375ce18.jpg);
query: url(d68e763c825dc0e388929ae1b375ce18.jpg);
hash: url(d68e763c825dc0e388929ae1b375ce18.jpg#hash); }
.another-class-name {
display: block; }
`,
compose(onlyMeta('meta.version.webpack >= 5'), assertCssContent, outdent)`
compose(assertCssContent, outdent)`
.some-class-name {
single-quoted: url(9eb57a84abbf8abc636d0faa71f9a800.jpg);
double-quoted: url(9eb57a84abbf8abc636d0faa71f9a800.jpg);
Expand Down Expand Up @@ -159,16 +148,8 @@ module.exports = test(
assertWebpackOk,
assertNoErrors,
assertDebugMessages,
onlyMeta('meta.version.webpack >= 4')(
assertCssSourceMapComment(false)
),
compose(onlyMeta('meta.version.webpack == 4'), assertCssContent, trim)`
.some-class-name{single-quoted:url(d68e763c825dc0e388929ae1b375ce18.jpg);double-quoted:
url(d68e763c825dc0e388929ae1b375ce18.jpg);unquoted:url(d68e763c825dc0e388929ae1b375ce18.jpg);query:
url(d68e763c825dc0e388929ae1b375ce18.jpg);hash:url(d68e763c825dc0e388929ae1b375ce18.jpg#hash)}
.another-class-name{display:block}
`,
compose(onlyMeta('meta.version.webpack >= 5'), assertCssContent, trim)`
assertCssSourceMapComment(false),
compose(assertCssContent, trim)`
.some-class-name{single-quoted:url(9eb57a84abbf8abc636d0faa71f9a800.jpg);double-quoted:
url(9eb57a84abbf8abc636d0faa71f9a800.jpg);unquoted:url(9eb57a84abbf8abc636d0faa71f9a800.jpg);query:
url(9eb57a84abbf8abc636d0faa71f9a800.jpg);hash:url(9eb57a84abbf8abc636d0faa71f9a800.jpg#hash)}
Expand Down
Loading

0 comments on commit aab579b

Please sign in to comment.