mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +00:00
fix typescript support
This commit is contained in:
parent
a9a262f258
commit
aea527fd87
@ -8,13 +8,14 @@ import alias from '@rollup/plugin-alias'
|
|||||||
import json from '@rollup/plugin-json'
|
import json from '@rollup/plugin-json'
|
||||||
import replace from '@rollup/plugin-replace'
|
import replace from '@rollup/plugin-replace'
|
||||||
import analyze from 'rollup-plugin-analyzer'
|
import analyze from 'rollup-plugin-analyzer'
|
||||||
import esbuild from 'rollup-plugin-esbuild'
|
import ts from 'rollup-plugin-ts'
|
||||||
|
|
||||||
export type RollupConfig = InputOptions & { output: OutputOptions }
|
export type RollupConfig = InputOptions & { output: OutputOptions }
|
||||||
|
|
||||||
export const getRollupConfig = (config) => {
|
export const getRollupConfig = (config) => {
|
||||||
const mocks = [
|
const mocks = [
|
||||||
'@babel/parser',
|
'@babel/parser',
|
||||||
|
'encoding',
|
||||||
'@vue/compiler-core',
|
'@vue/compiler-core',
|
||||||
'@vue/compiler-dom',
|
'@vue/compiler-dom',
|
||||||
'@vue/compiler-ssr'
|
'@vue/compiler-ssr'
|
||||||
@ -32,7 +33,6 @@ export const getRollupConfig = (config) => {
|
|||||||
|
|
||||||
const options: RollupConfig = {
|
const options: RollupConfig = {
|
||||||
input: config.entry,
|
input: config.entry,
|
||||||
|
|
||||||
output: {
|
output: {
|
||||||
file: path.resolve(config.buildDir, 'dist/server', `index.${config.target}.js`),
|
file: path.resolve(config.buildDir, 'dist/server', `index.${config.target}.js`),
|
||||||
format: 'cjs',
|
format: 'cjs',
|
||||||
@ -40,55 +40,50 @@ export const getRollupConfig = (config) => {
|
|||||||
outro: '',
|
outro: '',
|
||||||
preferConst: true
|
preferConst: true
|
||||||
},
|
},
|
||||||
|
|
||||||
external,
|
external,
|
||||||
|
plugins: []
|
||||||
|
}
|
||||||
|
|
||||||
plugins: [
|
// https://github.com/rollup/plugins/tree/master/packages/replace
|
||||||
replace({
|
options.plugins.push(replace({
|
||||||
values: {
|
values: {
|
||||||
'process.env.NODE_ENV': '"production"'
|
'process.env.NODE_ENV': '"production"'
|
||||||
}
|
}
|
||||||
}),
|
}))
|
||||||
|
|
||||||
alias({
|
// https://github.com/rollup/plugins/tree/master/packages/alias
|
||||||
|
options.plugins.push(alias({
|
||||||
entries: {
|
entries: {
|
||||||
'~runtime': path.resolve(__dirname, 'runtime'),
|
'~runtime': path.resolve(__dirname, 'runtime'),
|
||||||
'~build': config.buildDir,
|
'~build': config.buildDir,
|
||||||
'~mock': require.resolve('./runtime/mock'),
|
'~mock': require.resolve('./runtime/mock'),
|
||||||
...mocks.reduce((p, c) => ({ ...p, [c]: '~mock' }), {})
|
...mocks.reduce((p, c) => ({ ...p, [c]: '~mock' }), {})
|
||||||
}
|
}
|
||||||
}),
|
}))
|
||||||
|
|
||||||
|
// https://github.com/wessberg/rollup-plugin-ts
|
||||||
|
options.plugins.push(ts({
|
||||||
|
transpileOnly: true,
|
||||||
|
transpiler: 'babel',
|
||||||
|
include: ['**/*.ts'],
|
||||||
|
exclude: ['*.json', 'node_modules']
|
||||||
|
}))
|
||||||
|
|
||||||
// https://github.com/rollup/plugins/tree/master/packages/node-resolve
|
// https://github.com/rollup/plugins/tree/master/packages/node-resolve
|
||||||
resolve({
|
options.plugins.push(resolve({
|
||||||
extensions,
|
extensions,
|
||||||
preferBuiltins: true,
|
preferBuiltins: true,
|
||||||
mainFields: ['main'] // Force resolve CJS (@vue/runtime-core ssrUtils)
|
mainFields: ['main'] // Force resolve CJS (@vue/runtime-core ssrUtils)
|
||||||
}),
|
}))
|
||||||
|
|
||||||
// https://github.com/rollup/plugins/tree/master/packages/commonjs
|
// https://github.com/rollup/plugins/tree/master/packages/commonjs
|
||||||
commonjs({
|
options.plugins.push(commonjs({
|
||||||
extensions: extensions.filter(ext => ext !== '.json'),
|
extensions: extensions.filter(ext => ext !== '.json'),
|
||||||
dynamicRequireTargets: ['*.js']
|
dynamicRequireTargets: ['*.js']
|
||||||
}),
|
}))
|
||||||
|
|
||||||
// https://github.com/egoist/rollup-plugin-esbuild
|
|
||||||
esbuild({
|
|
||||||
target: 'node12',
|
|
||||||
include: /\.[jt]s?$/,
|
|
||||||
tsconfig: false,
|
|
||||||
sourceMap: false,
|
|
||||||
loaders: {
|
|
||||||
'.json': 'json',
|
|
||||||
'.js': 'jsx',
|
|
||||||
'.ts': 'ts'
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
// https://github.com/rollup/plugins/tree/master/packages/json
|
// https://github.com/rollup/plugins/tree/master/packages/json
|
||||||
json()
|
options.plugins.push(json())
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.logStartup) {
|
if (config.logStartup) {
|
||||||
options.output.intro += 'global._startTime = process.hrtime();'
|
options.output.intro += 'global._startTime = process.hrtime();'
|
||||||
|
@ -16,7 +16,7 @@ const renderer = createRenderer(server, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
export async function render (url) {
|
export async function render (url) {
|
||||||
const ssrContext = {
|
const ssrContext: any = {
|
||||||
url,
|
url,
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
public: {},
|
public: {},
|
||||||
|
Loading…
Reference in New Issue
Block a user