Skip to content
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

Don't create Pinia outside development #678

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import createCentralRouter from './router';
import createUnsavedChanges from './unsaved-changes';
import defaultConfig from './config';
import { createRequestData } from './request-data';
import { noop } from './util/util';

const provide = [
'alert',
Expand All @@ -28,6 +29,8 @@ const provide = [
'logger'
];

const piniaMock = { install: noop };

export default ({
// `router` must be a function that returns an object. The function will be
// passed a partial container. It is also possible to create a container
Expand All @@ -45,7 +48,7 @@ export default ({
logger = console
} = {}) => {
const container = {
pinia: createPinia(),
pinia: process.env.NODE_ENV === 'development' ? createPinia() : piniaMock,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally, my strategy was going to be to use webpack to alias the pinia package to src/util/pinia.js. That way, only our webpack config would change, not this file. However, at the end of the day, I think this approach is clearer: there's less webpack magic involved. Plus, now that we're planning to move to Vite (#671), it seems good to have as little webpack-specific code as possible. I checked the build, and even though this file still imports Pinia, if it doesn't use Pinia at all, which it won't outside development, the import is removed from the bundle.

Since we won't use it after all, I've removed src/util/pinia.js.

i18n: i18n.global,
alert,
unsavedChanges,
Expand Down
15 changes: 0 additions & 15 deletions src/util/pinia.js

This file was deleted.