Skip to content

Commit

Permalink
Merge branch 'release/3.1.0-alpha.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
titouanmathis committed Nov 20, 2021
2 parents 790ef2a + bd646a9 commit d0e8cb3
Show file tree
Hide file tree
Showing 25 changed files with 3,659 additions and 6,877 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ jobs:
registry-url: https://registry.npmjs.org/

- run: npm i
- run: cd packages/webpack-config && npm publish

- run: |
cd packages/webpack-config
VERSION=${GITHUB_REF/refs\/tags\//}
TAG='latest'
if [[ $VERSION =~ 'alpha' || $VERSION =~ 'beta' ]]; then
TAG='next'
fi
npm publish --tag $TAG
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ yarn.lock
backup/
*.ini
/packages/demo/dist/
/packages/demo-basic/dist/
/packages/*/package-lock.json
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ module.exports = {
dist: './path/to/dist',
public: '/path/to/dist',

/**
* Define which target to use when creating the bundle.
* An array of targets will create a bundle for each target.
* Defaults to `legacy`.
*
* @type {'modern'|'legacy'|Array<'modern'|'legacy'>}
* @optional
*/
target: ['modern', 'legacy'],

/**
* Analyze the bundle with the WebpackBundleAnalyzer plugin.
* @type {Boolean}
Expand Down
10,169 changes: 3,408 additions & 6,761 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/webpack-config-root",
"version": "3.0.2",
"version": "3.1.0-alpha.0",
"private": true,
"type": "commonjs",
"workspaces": [
Expand Down
8 changes: 8 additions & 0 deletions packages/demo/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"root": true,
"extends": ["@studiometa/eslint-config"],
"rules": {
"import/extensions": ["error", "always", { "ignorePackages": false }],
"import/no-extraneous-dependencies": "off"
}
}
10 changes: 0 additions & 10 deletions packages/demo/.eslintrc.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/demo/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@studiometa/stylelint-config"
}
3 changes: 0 additions & 3 deletions packages/demo/.stylelintrc.js

This file was deleted.

6 changes: 4 additions & 2 deletions packages/demo/meta.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = {
import { createConfig } from '@studiometa/webpack-config';

export default createConfig({
presets: ['prototyping', 'yaml'],
// Exclude the `test.scss` file from the merge
mergeCSS: /^(?!.*css\/test\.scss).*$/,
};
});
9 changes: 5 additions & 4 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@studiometa/webpack-config-demo",
"version": "3.0.2",
"version": "3.1.0-alpha.0",
"private": true,
"type": "commonjs",
"type": "module",
"scripts": {
"dev": "node ../webpack-config/bin/cli.js dev",
"build": "node ../webpack-config/bin/cli.js build"
Expand All @@ -18,7 +18,8 @@
"tailwindcss": "^2.2.9"
},
"dependencies": {
"@studiometa/js-toolkit": "^1.6.1",
"vue": "^2.6.14"
"@studiometa/js-toolkit": "^2.0.0-beta.0",
"@studiometa/ui": "^0.1.0",
"vue": "^3.2.22"
}
}
10 changes: 6 additions & 4 deletions packages/demo/src/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue';
import Base from '@studiometa/js-toolkit';
import { Base, createApp } from '@studiometa/js-toolkit';
import { Cursor } from '@studiometa/ui';
import { createApp as createVueApp } from 'vue';
import VueComponent from './VueComponent.vue';
import config from './config.yaml';

Expand All @@ -17,6 +18,7 @@ class App extends Base {
refs: ['content', 'vue'],
...config,
components: {
Cursor,
Component: () => import('./components/Component.js'),
},
};
Expand All @@ -39,7 +41,7 @@ class App extends Base {
*/
async onClick() {
const { default: VueCounter } = await import(/* webpackPreload: true */ './Counter.vue');
this.vue = new Vue({
this.vue = createVueApp({
components: {
VueCounter,
},
Expand All @@ -64,4 +66,4 @@ class App extends Base {
}
}

export default new App(document.querySelector('main')).$mount();
export default createApp(App, document.querySelector('main'));
2 changes: 1 addition & 1 deletion packages/demo/src/js/components/Component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base from '@studiometa/js-toolkit';
import { Base } from '@studiometa/js-toolkit';
import './Component.css';

// eslint-disable-next-line require-jsdoc
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/js/foo/Component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base from '@studiometa/js-toolkit';
import { Base } from '@studiometa/js-toolkit';

// eslint-disable-next-line require-jsdoc
export default class Component extends Base {
Expand Down
File renamed without changes.
31 changes: 13 additions & 18 deletions packages/webpack-config/bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import cac from 'cac';
import chalk from 'chalk';
import { createRequire } from "module";
import { createRequire } from 'module';
import build from '../src/build.js';
import dev from '../src/dev.js';

Expand All @@ -13,32 +13,27 @@ const cli = cac('meta');
cli
.command('build', 'Build assets.')
.option('-a, --analyze', 'Analyze bundle(s).')
.action(options => {
try {
build(options);
} catch (err) {
console.log('');
console.log(chalk.red(err));
console.log('');
}
.option('-t, --target <target>', 'Define targets to bundle for: `legacy` or `modern` or both.')
.action(({ analyze = false, target = [] } = {}) => {
const options = { analyze, target: Array.isArray(target) ? target : [target] };
build(options);
});

cli
.command('dev', 'Launch dev server.')
.option('-a, --analyze', 'Analyze bundle(s).')
.action(options => {
try {
dev(options);
} catch (err) {
console.log('');
console.log(chalk.red(err));
console.log('');
}
.action((options) => {
dev(options);
});

cli.help();
cli.version(`${name}@${version}`);
cli.parse();

try {
cli.parse();
} catch (err) {
console.log(chalk.red(err));
}

if (!cli.matchedCommandName && Object.keys(cli.options).length <= 1) {
cli.outputHelp();
Expand Down
64 changes: 32 additions & 32 deletions packages/webpack-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/webpack-config",
"version": "3.0.2",
"version": "3.1.0-alpha.0",
"description": "A basic webpack config",
"type": "module",
"main": "src/index.js",
Expand Down Expand Up @@ -36,8 +36,8 @@
"devDependencies": {
"@studiometa/eslint-config": "^2.1.3",
"@studiometa/prettier-config": "^2.0.1",
"eslint": "7.28.0",
"prettier": "2.3.1",
"eslint": "7.32.0",
"prettier": "2.4.1",
"stylelint": "13.13.1"
},
"peerDependencies": {
Expand All @@ -49,53 +49,53 @@
"stylelint": "^13.13.1"
},
"dependencies": {
"@babel/plugin-transform-runtime": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"@babel/plugin-transform-runtime": "^7.16.4",
"@babel/preset-env": "^7.16.4",
"@npmcli/move-file": "^1.1.2",
"@soda/friendly-errors-webpack-plugin": "^1.8.0",
"@types/browser-sync": "^2.26.2",
"autoprefixer": "^10.3.3",
"babel-loader": "^8.2.2",
"browser-sync": "^2.27.5",
"cac": "^6.7.3",
"@soda/friendly-errors-webpack-plugin": "^1.8.1",
"@types/browser-sync": "^2.26.3",
"autoprefixer": "^10.4.0",
"babel-loader": "^8.2.3",
"browser-sync": "^2.27.7",
"cac": "^6.7.12",
"chalk": "^4.1.2",
"common-dir": "^3.0.1",
"core-js": "^3.16.4",
"css-loader": "^6.2.0",
"css-minimizer-webpack-plugin": "^3.0.2",
"core-js": "^3.19.1",
"css-loader": "^6.5.1",
"css-minimizer-webpack-plugin": "^3.1.4",
"dotenv": "^10.0.0",
"eslint-import-resolver-webpack": "^0.13.1",
"eslint-webpack-plugin": "^3.0.1",
"find-up": "^6.0.0",
"glob": "^7.1.7",
"html-webpack-plugin": "^5.3.2",
"esbuild-loader": "^2.16.0",
"eslint-webpack-plugin": "^3.1.1",
"find-up": "^6.2.0",
"glob": "^7.2.0",
"html-webpack-plugin": "^5.5.0",
"js-yaml-loader": "^1.2.2",
"lodash.merge": "^4.6.2",
"mini-css-extract-plugin": "^2.2.0",
"postcss": "^8.3.6",
"postcss-loader": "^6.1.1",
"mini-css-extract-plugin": "^2.4.5",
"postcss": "^8.3.11",
"postcss-loader": "^6.2.0",
"postcss-preset-env": "^6.7.0",
"raw-loader": "^4.0.2",
"resolve-url-loader": "^4.0.0",
"sass": "^1.38.2",
"sass-loader": "^12.1.0",
"style-loader": "^3.2.1",
"stylelint-webpack-plugin": "^3.0.1",
"sass": "^1.43.4",
"sass-loader": "^12.3.0",
"style-loader": "^3.3.1",
"stylelint-webpack-plugin": "^3.1.0",
"tailwind-config-viewer": "^1.6.2",
"terser-webpack-plugin": "^5.1.4",
"terser-webpack-plugin": "^5.2.5",
"twig-html-loader": "^0.1.9",
"vue-loader": "^15.9.8",
"vue-svg-loader": "^0.16.0",
"vue-template-compiler": "^2.6.14",
"webpack": "^5.51.1",
"webpack": "^5.64.1",
"webpack-assets-manifest": "^5.0.6",
"webpack-bundle-analyzer": "^4.4.2",
"webpack-dev-middleware": "^5.0.0",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-dev-middleware": "^5.2.2",
"webpack-glob-entry": "^2.1.1",
"webpack-hot-middleware": "^2.25.0",
"webpack-hot-middleware": "^2.25.1",
"webpack-merge": "^5.8.0",
"webpack-module-hot-accept": "^1.0.5",
"webpack-remove-empty-scripts": "^0.7.1",
"webpackbar": "^5.0.0-3"
"webpackbar": "^5.0.2"
}
}
53 changes: 39 additions & 14 deletions packages/webpack-config/src/build.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
import { cwd } from 'process';
import webpack from 'webpack';
import getConfig from './utils/get-config.js';
import getWebpackConfig from './webpack.prod.config.js';

/**
* Build a given Webpack config.
* @param {WebpackConfig} config The Weback configuration object.
* @param {String} name The name of the build.
*/
async function build(config, name) {
console.log(`Building ${name} bundle in ${config.output.path.replace(cwd(), '.')}...`);

return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err) {
console.error(err.message);
reject(err);
return;
}
console.log(
stats.toString({
...config.stats,
colors: true,
})
);
console.log('');
resolve(stats);
});
});
}

export default async (options = {}) => {
process.env.NODE_ENV = 'production';

const config = await getConfig(options);
const webpackConfig = await getWebpackConfig(config);

webpack(webpackConfig, (err, stats) => {
if (err) {
console.error(err.message);
return;
}
console.log(
stats.toString({
...webpackConfig.stats,
colors: true,
})
);
});
if (config.modern) {
process.env.BABEL_ENV = 'modern';
const modern = await getWebpackConfig(config, { isModern: true });
await build(modern, 'modern');
}

if (config.legacy) {
process.env.BABEL_ENV = 'legacy';
const legacy = await getWebpackConfig(config, { isLegacy: true });
await build(legacy, 'legacy');
}
};
10 changes: 9 additions & 1 deletion packages/webpack-config/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ interface CacheGroupsContext {
}

export interface MetaConfig {
/**
* Toggle the modern build.
*/
modern?: boolean;
/**
* Toggle the legacy build.
*/
legacy?: boolean;
/**
* A list of glob for files to consider as entries.
*/
Expand Down Expand Up @@ -118,6 +126,6 @@ declare function createConfig(config: MetaConfig): MetaConfig;
/**
* Get the generated Webpack configuration.
*/
declare function getWebpackConfig(): WebpackConfig;
declare function getWebpackConfig(options: { mode?: 'production'|'development' }): WebpackConfig;

export { createConfig, getWebpackConfig };
Loading

0 comments on commit d0e8cb3

Please sign in to comment.