-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 [#274] Declutter - move vite plugins to separate file
Set up a build directory for vite configuration/plugins to not clutter the vite.config.mts file too much.
- Loading branch information
1 parent
e30128a
commit 589392a
Showing
4 changed files
with
53 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
|
||
# production | ||
/storybook-static | ||
/build | ||
/dist | ||
/dist-vite | ||
/lib | ||
|
This file contains 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,35 @@ | ||
import lodashTemplate from 'lodash/template'; | ||
|
||
// inspired on https://dev.to/koistya/using-ejs-with-vite-48id and | ||
// https://github.com/difelice/ejs-loader/blob/master/index.js | ||
export const ejsPlugin = () => ({ | ||
name: 'compile-ejs', | ||
async transform(src: string, id: string) { | ||
const options = { | ||
variable: 'ctx', | ||
evaluate: /\{%([\s\S]+?)%\}/g, | ||
interpolate: /\{\{([\s\S]+?)\}\}/g, | ||
escape: /\{\{\{([\s\S]+?)\}\}\}/g, | ||
}; | ||
if (id.endsWith('.ejs')) { | ||
// @ts-ignore | ||
const code = lodashTemplate(src, options); | ||
return {code: `export default ${code}`, map: null}; | ||
} | ||
}, | ||
}); | ||
|
||
export const cjsTokens = () => ({ | ||
name: 'process-cjs-tokens', | ||
async transform(src, id) { | ||
if ( | ||
id.endsWith('/design-tokens/dist/tokens.js') || | ||
id.endsWith('node_modules/@utrecht/design-tokens/dist/tokens.cjs') | ||
) { | ||
return { | ||
code: src.replace('module.exports = ', 'export default '), | ||
map: null, | ||
}; | ||
} | ||
}, | ||
}); |
This file contains 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,15 @@ | ||
import {dependencies, peerDependencies} from '../package.json'; | ||
|
||
const externalPackages = [ | ||
...Object.keys(dependencies || {}), | ||
...Object.keys(peerDependencies || {}), | ||
'formiojs', | ||
'lodash', | ||
'@formio/vanilla-text-mask', | ||
'@babel/runtime', | ||
'@utrecht/component-library-react', | ||
]; | ||
|
||
// Creating regexes of the packages to make sure subpaths of the | ||
// packages are also treated as external | ||
export const packageRegexes = externalPackages.map(packageName => new RegExp(`^${packageName}(/.*)?`)); |
This file contains 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