// [!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript) // src/vue/ItemPrice.vue?vue&type=script&lang.ts (35:13) // TODO 官方提供ts插件在vue模版中使用ts语言时报错 // import typescript from "@rollup/plugin-typescript"; // TODO 在rollup watch模式中不更新vue模版ts部分代码 import typescript2 from "rollup-plugin-typescript2"; import json from "@rollup/plugin-json"; import html from "rollup-plugin-string-html"; import resolve from "@rollup/plugin-node-resolve"; import replace from "@rollup/plugin-replace"; import alias from "@rollup/plugin-alias"; import postcss from 'rollup-plugin-postcss'; import vue from "@vitejs/plugin-vue"; let node_env = process.env.NODE_ENV; let vuePath = node_env === 'production' ? 'vue/dist/vue.runtime.esm-browser.prod.js' : 'vue/dist/vue.runtime.esm-browser.js'; export default { input: 'src/ts/index.ts', output: { file: 'dist/bundle.js', format: 'iife', name: 'bundle.js', }, plugins: [ json(), html({ // include: ["**/*.html", "src/static/css/*.css"], // include: ["**/*.html", "**/*.css"], include: ["**/*.html"], minifier: { includeAutoGeneratedTags: true, removeAttributeQuotes: false, removeComments: true, removeRedundantAttributes: false, removeScriptTypeAttributes: true, removeStyleLinkTypeAttributes: true, sortClassName: true, useShortDoctype: true, collapseWhitespace: true, minifyCSS: true, } }), // 根据环境更改vue源 alias({ entries: [{ find: 'vue', replacement: vuePath }] }), // 为vue替换环境变量 replace({ values: { 'process.env.NODE_ENV': () => JSON.stringify(node_env), '__VUE_OPTIONS_API__': () => JSON.stringify(false), '__VUE_PROD_DEVTOOLS__': () => JSON.stringify(true), }, preventAssignment: true, }), // 引入node相关方法 resolve({ browser: true, preferBuiltins: false, }), vue({ isProduction: node_env === 'production' }), typescript2({ tsconfig: "tsconfig.json", // clean: true, // check: false, }), postcss({ minimize: true }), // typescript(), ], };