Skip to content

Commit

Permalink
Split the webpack 4 and webpack 5 tests out.
Browse files Browse the repository at this point in the history
  • Loading branch information
iclanton committed May 6, 2022
1 parent 70b1157 commit bd51a72
Show file tree
Hide file tree
Showing 27 changed files with 293 additions and 94 deletions.
21 changes: 0 additions & 21 deletions build-tests/hashed-folder-copy-plugin-test/build.js

This file was deleted.

18 changes: 0 additions & 18 deletions build-tests/hashed-folder-copy-plugin-test/serve.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Defines configuration used by core Heft.
*/
{
"$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json",

"eventActions": [
{
/**
* The kind of built-in operation that should be performed.
* The "deleteGlobs" action deletes files or folders that match the
* specified glob patterns.
*/
"actionKind": "deleteGlobs",

/**
* The stage of the Heft run during which this action should occur. Note that actions specified in heft.json
* occur at the end of the stage of the Heft run.
*/
"heftEvent": "clean",

/**
* A user-defined tag whose purpose is to allow configs to replace/delete handlers that were added by other
* configs.
*/
"actionId": "defaultClean",

/**
* Glob patterns to be deleted. The paths are resolved relative to the project folder.
*/
"globsToDelete": ["lib", "dist-dev", "dist-prod"]
}
],

/**
* The list of Heft plugins to be loaded.
*/
"heftPlugins": [
{
/**
* The path to the plugin package.
*/
"plugin": "@rushstack/heft-webpack4-plugin"

/**
* An optional object that provides additional settings that may be defined by the plugin.
*/
// "options": { }
}
]
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{
"name": "hashed-folder-copy-plugin-test",
"description": "Building this project exercises @rushstack/hashed-folder-copy-plugin.",
"name": "hashed-folder-copy-plugin-webpack4-test",
"description": "Building this project exercises @rushstack/hashed-folder-copy-plugin with Webpack 4.",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "node build.js",
"serve": "node serve.js",
"_phase:build": "node build.js"
"build": "heft build --clean",
"serve": "heft start --clean",
"_phase:build": "heft build --clean"
},
"dependencies": {
"devDependencies": {
"@rushstack/hashed-folder-copy-plugin": "workspace:*",
"@rushstack/heft-webpack4-plugin": "workspace:*",
"@rushstack/heft": "workspace:*",
"@rushstack/module-minifier-plugin": "workspace:*",
"@rushstack/node-core-library": "workspace:*",
"@rushstack/set-webpack-public-path-plugin": "workspace:*",
"@types/webpack-env": "1.13.0",
"html-webpack-plugin": "~4.5.2",
"ts-loader": "6.0.0",
"typescript": "~4.6.3",
"webpack": "~4.44.2",
"webpack-bundle-analyzer": "~4.5.0",
"webpack-cli": "~3.3.2",
"webpack-dev-server": "~3.11.0"
"webpack": "~4.44.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,8 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
function generateConfiguration(mode, outputFolderName) {
return {
mode: mode,
module: {
rules: [
{
test: /\.tsx?$/,
loader: require.resolve('ts-loader'),
exclude: /(node_modules)/,
options: {
compiler: require.resolve('typescript'),
logLevel: 'ERROR',
configFile: path.resolve(__dirname, 'tsconfig.json')
}
}
]
},
resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx']
},
entry: {
test: path.join(__dirname, 'src', 'index.ts')
test: path.join(__dirname, 'lib', 'index.js')
},
output: {
path: path.join(__dirname, outputFolderName),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist-*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Defines configuration used by core Heft.
*/
{
"$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json",

"eventActions": [
{
/**
* The kind of built-in operation that should be performed.
* The "deleteGlobs" action deletes files or folders that match the
* specified glob patterns.
*/
"actionKind": "deleteGlobs",

/**
* The stage of the Heft run during which this action should occur. Note that actions specified in heft.json
* occur at the end of the stage of the Heft run.
*/
"heftEvent": "clean",

/**
* A user-defined tag whose purpose is to allow configs to replace/delete handlers that were added by other
* configs.
*/
"actionId": "defaultClean",

/**
* Glob patterns to be deleted. The paths are resolved relative to the project folder.
*/
"globsToDelete": ["lib", "dist-dev", "dist-prod"]
}
],

/**
* The list of Heft plugins to be loaded.
*/
"heftPlugins": [
{
/**
* The path to the plugin package.
*/
"plugin": "@rushstack/heft-webpack5-plugin"

/**
* An optional object that provides additional settings that may be defined by the plugin.
*/
// "options": { }
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"operationSettings": [
{
"operationName": "build",
"outputFolderNames": ["lib", "dist-dev", "dist-prod"]
}
]
}
21 changes: 21 additions & 0 deletions build-tests/hashed-folder-copy-plugin-webpack5-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "hashed-folder-copy-plugin-webpack5-test",
"description": "Building this project exercises @rushstack/hashed-folder-copy-plugin with Webpack 5. NOTE - THIS TEST IS CURRENTLY EXPECTED TO BE BROKEN",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "heft build --clean",
"serve": "heft start --clean",
"_phase:build": "heft build --clean"
},
"devDependencies": {
"@rushstack/hashed-folder-copy-plugin": "workspace:*",
"@rushstack/heft-webpack5-plugin": "workspace:*",
"@rushstack/heft": "workspace:*",
"@types/webpack-env": "1.13.0",
"html-webpack-plugin": "~4.5.2",
"typescript": "~4.6.3",
"webpack-bundle-analyzer": "~4.5.0",
"webpack": "~5.68.0"
}
}
25 changes: 25 additions & 0 deletions build-tests/hashed-folder-copy-plugin-webpack5-test/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ASSETS_BASE_URL2 } from './submodule';

const ASSETS_BASE_URL: string = requireFolder({
outputFolder: 'assets_[hash]',
sources: [
{
globsBase: '../assets',
globPatterns: ['**/*']
}
]
});

function appendImageToBody(url: string): void {
const image: HTMLImageElement = document.createElement('img');
image.src = url;
document.body.appendChild(image);
}

appendImageToBody(`${ASSETS_BASE_URL}/red.png`);
appendImageToBody(`${ASSETS_BASE_URL}/green.png`);
appendImageToBody(`${ASSETS_BASE_URL}/blue.png`);

appendImageToBody(`${ASSETS_BASE_URL2}/red.png`);
appendImageToBody(`${ASSETS_BASE_URL2}/green.png`);
appendImageToBody(`${ASSETS_BASE_URL2}/blue.png`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const ASSETS_BASE_URL2: string = requireFolder({
outputFolder: 'assets2_[hash]',
sources: [
{
globsBase: '../assets',
globPatterns: ['**/*']
}
]
});
23 changes: 23 additions & 0 deletions build-tests/hashed-folder-copy-plugin-webpack5-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": true,
"jsx": "react",
"lib": ["es5", "scripthost", "es2015.collection", "es2015.promise", "es2015.iterable", "dom"],
"module": "esnext",
"moduleResolution": "node",
"noUnusedLocals": true,
"sourceMap": true,
"strictNullChecks": true,
"target": "es5",
"types": ["webpack-env", "@rushstack/hashed-folder-copy-plugin/ambientTypes"],

"outDir": "lib",
"rootDir": "src",
"rootDirs": ["src", "temp/loc-json-ts"]
},
"include": ["src/**/*.ts", "src/**/*.tsx"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

const path = require('path');
const webpack = require('webpack');

const { HashedFolderCopyPlugin } = require('@rushstack/hashed-folder-copy-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const HtmlWebpackPlugin = require('html-webpack-plugin');

function generateConfiguration(mode, outputFolderName) {
return {
mode: mode,
entry: {
test: path.join(__dirname, 'lib', 'index.js')
},
output: {
path: path.join(__dirname, outputFolderName),
filename: '[name]_[contenthash].js',
chunkFilename: '[id].[name]_[contenthash].js'
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new HashedFolderCopyPlugin(),
new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: 'static',
reportFilename: path.resolve(__dirname, 'temp', 'stats.html'),
generateStatsFile: true,
statsFilename: path.resolve(__dirname, 'temp', 'stats.json'),
logLevel: 'error'
}),
new HtmlWebpackPlugin()
]
};
}

module.exports = [
generateConfiguration('development', 'dist-dev'),
generateConfiguration('production', 'dist-prod')
];
Loading

0 comments on commit bd51a72

Please sign in to comment.