104 lines
3.3 KiB
JavaScript
104 lines
3.3 KiB
JavaScript
// [!] 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 vue from "@vitejs/plugin-vue";
|
|
import styles from "rollup-plugin-styles";
|
|
import { customInjector } from "./custom-injector.js";
|
|
import terser from "@rollup/plugin-terser";
|
|
import clone from "just-clone";
|
|
|
|
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';
|
|
|
|
const devConfig = {
|
|
input: 'src/ts/index.ts',
|
|
output: {
|
|
file: 'dist/bundle.js',
|
|
format: 'iife',
|
|
name: 'bundle.js',
|
|
},
|
|
plugins: [
|
|
json(),
|
|
html({
|
|
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' }),
|
|
// 自定义注入器注入vue部分css
|
|
styles({
|
|
// modules: true,
|
|
// namedExports: true,
|
|
exclude: /static\/css\/.+\.css/,
|
|
mode: [
|
|
"inject",
|
|
(varName) => customInjector(varName),
|
|
],
|
|
minimize: true
|
|
}),
|
|
// 非vue部分css逻辑代码中手动注入
|
|
styles({
|
|
include: /static\/css\/.+\.css/,
|
|
// modules: true,
|
|
// namedExports: true,
|
|
mode: [
|
|
"inject",
|
|
() => ``,
|
|
],
|
|
minimize: true
|
|
}),
|
|
typescript2({
|
|
tsconfig: "./tsconfig.json",
|
|
}),
|
|
],
|
|
};
|
|
|
|
const prodConfig = clone(devConfig);
|
|
prodConfig.plugins.push(terser());
|
|
prodConfig.output.file = 'dist/bundle.min.js';
|
|
prodConfig.output.name = 'bundle.min.js';
|
|
|
|
export default [devConfig, prodConfig];
|
|
export { prodConfig };
|