-
Notifications
You must be signed in to change notification settings - Fork 0
Create shared configuration builders. #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
edf74ad
Create getReactifiedConfig and getVanillaConfig.
Hug0-Drelon 4519f36
Lint transformers.
Hug0-Drelon 0d0836b
Create CI.
Hug0-Drelon 55b400c
Update deps.
Hug0-Drelon e9bd1b5
Add sassLoadPaths to getReactifiedConfig.
Hug0-Drelon 8ec204f
Refactor config generation with getSassRules and getMainConfig.
Hug0-Drelon 564650c
Indent package.json
Hug0-Drelon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: ESLint | ||
|
|
||
| on: | ||
| push: | ||
| branches: master | ||
| pull_request: | ||
| branches: master | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| js-and-style: | ||
| name: ESLint | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Check out the source code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Run ESLint | ||
| run: npm run lint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| name: Spell Check | ||
|
|
||
| on: | ||
| push: | ||
| branches: master | ||
| pull_request: | ||
| branches: master | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| testing: | ||
| name: Spell Check with Typos | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout Actions Repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Check spelling | ||
| uses: crate-ci/typos@master | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: Unit Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: master | ||
| pull_request: | ||
| branches: master | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| name: Jest Unit Tests | ||
|
|
||
| steps: | ||
| - name: Check out the source code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Run Jest Unit Tests | ||
| run: npm run test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,104 @@ | ||
| # Polylang Build Scripts | ||
|
|
||
| These are the scripts needed to build Polylang. They are meant to be use as **dependencies** of both [Polylang](https://github.com/polylang/polylang) and [Polylang Pro](https://polylang.pro/products). Outside of this context, we do not guarantee that they provide you any value. | ||
| Webpack configuration helpers for building Polylang projects. Provides two main functions for generating webpack configs: `getVanillaConfig` for vanilla JS/CSS files and `getReactifiedConfig` for React-based builds. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install @wpsyntex/polylang-build-scripts | ||
| ``` | ||
|
|
||
| ## getVanillaConfig | ||
|
|
||
| Generates webpack configurations for vanilla JS and CSS files. Creates both minified and unminified versions. | ||
|
|
||
| **Required options:** | ||
| - `workingDirectory` - Working directory for glob resolution (typically `__dirname`) | ||
| - `jsBuildDirectory` - Output directory for JS files | ||
| - `cssBuildDirectory` - Output directory for CSS files | ||
| - `isProduction` - Enable production mode optimizations | ||
|
|
||
| **Optional options:** | ||
| - `jsPatterns` - Glob patterns for JS files (default: `['**/*.js']`) | ||
| - `jsIgnorePatterns` - Patterns to ignore for JS files (default: `[]`) | ||
| - `cssPatterns` - Glob patterns for CSS files (default: `['**/*.css']`) | ||
| - `cssIgnorePatterns` - Patterns to ignore for CSS files (default: `[]`) | ||
|
|
||
| **Example:** | ||
|
|
||
| ```javascript | ||
| const { getVanillaConfig } = require( '@wpsyntex/polylang-build-scripts' ); | ||
|
|
||
| const vanillaConfigs = getVanillaConfig( { | ||
| workingDirectory: __dirname, | ||
| jsPatterns: [ '**/*.js' ], | ||
| jsIgnorePatterns: [ 'node_modules/**', '**/build/**', '**/*.min.js' ], | ||
| cssPatterns: [ '**/*.css' ], | ||
| cssIgnorePatterns: [ 'node_modules/**', '**/build/**', '**/*.min.css' ], | ||
| jsBuildDirectory: path.resolve( __dirname, 'js/build' ), | ||
| cssBuildDirectory: path.resolve( __dirname, 'css/build' ), | ||
| isProduction: mode === 'production', | ||
| } ); | ||
|
|
||
| module.exports = vanillaConfigs; | ||
| ``` | ||
|
|
||
| ## getReactifiedConfig | ||
|
|
||
| Generates webpack configurations for React-based builds (blocks, editors). Creates minified and unminified builds with Babel transpilation. | ||
|
|
||
| **Required options:** | ||
| - `entryPoints` - Entry points for webpack (e.g., `{ blocks: './js/src/blocks/index.js' }`) | ||
| - `outputPath` - Base path for output files (typically `__dirname`) | ||
| - `libraryName` - Library name for the bundle (e.g., `'polylang'`) | ||
| - `isProduction` - Enable production mode optimizations | ||
| - `wpDependencies` - WordPress package dependencies to mark as externals (e.g., `['blocks', 'element', 'i18n']`) | ||
|
|
||
| **Optional options:** | ||
| - `additionalExternals` - Additional external dependencies (e.g., `{ jquery: 'jQuery' }`) | ||
|
|
||
| **Example:** | ||
|
|
||
| ```javascript | ||
| const { getReactifiedConfig } = require( '@wpsyntex/polylang-build-scripts' ); | ||
|
|
||
| const wpDependencies = [ | ||
| 'api-fetch', | ||
| 'block-editor', | ||
| 'blocks', | ||
| 'components', | ||
| 'data', | ||
| 'element', | ||
| 'i18n', | ||
| ]; | ||
|
|
||
| const reactConfigs = getReactifiedConfig( { | ||
| entryPoints: { blocks: './js/src/blocks/index.js' }, | ||
| outputPath: __dirname, | ||
| libraryName: 'polylang', | ||
| isProduction: mode === 'production', | ||
| wpDependencies, | ||
| } ); | ||
|
|
||
| module.exports = reactConfigs; | ||
| ``` | ||
|
|
||
| ## Combined Usage | ||
|
|
||
| ```javascript | ||
| const { getVanillaConfig, getReactifiedConfig } = require( '@wpsyntex/polylang-build-scripts' ); | ||
|
|
||
| module.exports = ( env, argv ) => { | ||
| const mode = argv.mode || 'development'; | ||
| const isProduction = mode === 'production'; | ||
|
|
||
| return [ | ||
| ...getVanillaConfig( { /* options */ } ), | ||
| ...getReactifiedConfig( { /* options */ } ), | ||
| ]; | ||
| }; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| These scripts are meant to be used as dependencies of Polylang-related projects but can easily be adapted for any WordPress project requiring JS or React build tools. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.