2021-07-12 10:54:24 +00:00
|
|
|
import { resolve } from 'upath'
|
2020-09-02 12:27:27 +00:00
|
|
|
import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5'
|
2020-09-21 13:26:48 +00:00
|
|
|
import { DefinePlugin } from 'webpack'
|
2021-06-16 12:42:58 +00:00
|
|
|
import NuxtSetupTransformerPlugin from '../plugins/transform-setup'
|
2020-09-02 12:27:27 +00:00
|
|
|
import VueSSRClientPlugin from '../plugins/vue/client'
|
|
|
|
import VueSSRServerPlugin from '../plugins/vue/server'
|
|
|
|
import { WebpackConfigContext } from '../utils/config'
|
|
|
|
|
|
|
|
export function vue (ctx: WebpackConfigContext) {
|
|
|
|
const { options, config } = ctx
|
|
|
|
|
|
|
|
config.plugins.push(new VueLoaderPlugin())
|
|
|
|
|
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.vue$/i,
|
|
|
|
loader: 'vue-loader',
|
2021-09-24 09:49:04 +00:00
|
|
|
options: {
|
|
|
|
// workaround for https://github.com/vuejs/vue-next/issues/4666
|
|
|
|
compilerOptions: {
|
|
|
|
ssrRuntimeModuleName: 'vue/server-renderer/index.mjs'
|
|
|
|
},
|
|
|
|
...options.build.loaders.vue
|
|
|
|
}
|
2020-09-02 12:27:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
if (ctx.isClient) {
|
|
|
|
config.plugins.push(new VueSSRClientPlugin({
|
2021-01-18 11:49:50 +00:00
|
|
|
filename: resolve(options.buildDir, 'dist/server', `${ctx.name}.manifest.json`)
|
2020-09-02 12:27:27 +00:00
|
|
|
}))
|
|
|
|
} else {
|
|
|
|
config.plugins.push(new VueSSRServerPlugin({
|
|
|
|
filename: `${ctx.name}.manifest.json`
|
|
|
|
}))
|
|
|
|
}
|
2020-09-21 13:26:48 +00:00
|
|
|
|
2021-06-16 12:42:58 +00:00
|
|
|
config.plugins.push(new NuxtSetupTransformerPlugin())
|
|
|
|
|
2020-09-21 13:26:48 +00:00
|
|
|
// Feature flags
|
|
|
|
// https://github.com/vuejs/vue-next/tree/master/packages/vue#bundler-build-feature-flags
|
|
|
|
// TODO: Provide options to toggle
|
|
|
|
config.plugins.push(new DefinePlugin({
|
|
|
|
__VUE_OPTIONS_API__: 'true',
|
|
|
|
__VUE_PROD_DEVTOOLS__: 'false'
|
|
|
|
}))
|
2020-09-02 12:27:27 +00:00
|
|
|
}
|