Created
May 18, 2021 23:48
-
-
Save bendemboski/9a498a6eda26e102597d98e5b7718c9c to your computer and use it in GitHub Desktop.
Webpack config to make ember-changeset-validations work with embroider optimized
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
module.exports = { | |
module: { | |
rules: [ | |
// ember-validators (dependency of ember-changeset-validations) | |
// does dynamic imports, which isn't necessary and messes up | |
// embroider-optimized, so rewrite it to statically import the | |
// only two validators we actually use/need. | |
{ | |
test: /\/ember-validators\/index\.js$/, | |
loader: 'string-replace-loader', | |
options: { | |
search: '^[\\s\\S]+$', | |
flags: '', | |
replace: [ | |
`import presence from './presence';`, | |
`import format from './format';`, | |
``, | |
`export function validate(type, ...args) {`, | |
` return { presence, format }[type](...args);`, | |
`}`, | |
].join('\n'), | |
strict: true, | |
}, | |
}, | |
// ember-changeset-validations imports from validated-changeset, but | |
// doesn't declare a dependency on it in package.json (it relies on | |
// ember-changeset's dependency). This doesn't work under embroider | |
// optimized, so we hack ember-changeset to re-export the symbols that | |
// ember-changeset-validations needs, and then hack | |
// ember-changeset-validations to import from ember-changeset instead of | |
// directly from validated-changeset | |
{ | |
test: /\/ember-changeset\/index.js$/, | |
loader: 'string-replace-loader', | |
options: { | |
search: /^/, | |
replace: | |
"export { lookupValidator, isPromise } from 'validated-changeset';", | |
strict: true, | |
}, | |
}, | |
{ | |
test: /\/ember-changeset-validations\/(index.js|utils\/handle-multiple-validations.js)/, | |
loader: 'string-replace-loader', | |
options: { | |
search: /from 'validated-changeset'/, | |
replace: "from 'ember-changeset'", | |
strict: true, | |
}, | |
}, | |
], | |
}, | |
resolve: { | |
alias: { | |
// validated-changeset points at a browser bundle, so let's get the ES6 | |
// module instead | |
'validated-changeset': 'validated-changeset/dist/es', | |
}, | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment