1 Star 0 Fork 100

Bright/vue-uieditor

forked from days2020/vue-uieditor 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
vue.config.js 5.41 KB
一键复制 编辑 原始数据 按行查看 历史
cmpxs 提交于 2021-11-18 13:41 . OPT: @vue/composition-api
const path = require('path');
const fs = require('fs');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const uieditorName = 'vue-uieditor';
const publicPath = './';
const filename = '[name].[hash].js';
const assetPath = path.join(uieditorName, './assets').replace(/\\/g, '/');
const cssPath = path.join(assetPath, 'css').replace(/\\/g, '/');
const rawArgv = process.argv.slice(2)
const isLib = (rawArgv || []).includes('-lib');
const package = require('./package.json');
process.env.VUE_APP_UE_NAME = package.name;
process.env.VUE_APP_UE_VERSION = package.version;
process.env.VUE_APP_UE_HOMEPAGE = package.homepage;
process.env.VUE_APP_UE_DESC = package.description;
// vue.config.js
module.exports = {
publicPath,
lintOnSave: false,
outputDir: path.resolve(__dirname, isLib ? './lib' : './pages'),
assetsDir: assetPath,
runtimeCompiler: true,
parallel: true,
productionSourceMap: false,
devServer: {
open: false,
overlay: {
warning: false,
errors: false
}
},
css: {
extract: {
publicPath: cssPath,
filename: path.join(cssPath, '[name].css'),
chunkFilename: path.join(cssPath, '[name].[contenthash:8].css')
},
loaderOptions: {
less: {
// localIdentName: '[name]_[local]'
},
css: {
// localIdentName: '[name]_[local]'
}
}
},
configureWebpack: config => {
// config.output.chunkFilename = '[name].[hash].chunk.js';
if (isLib) {
Object.assign(config.output, {
filename: 'index.js',
chunkFilename: `./${uieditorName}/${filename}`,
libraryTarget: 'umd',
library: 'VueUieditor',
umdNamedDefine: true
});
if (!config.externals) config.externals = {};
config.externals['vue'] = {
root: 'Vue',
commonjs: 'vue',
commonjs2: 'vue',
amd: 'vue'
}
config.externals['lodash'] = {
root: '_',
commonjs: 'lodash',
commonjs2: 'lodash',
amd: 'lodash'
};
config.externals['vue-template-compiler'] = 'vue-template-compiler'
config.externals['@vue/composition-api'] = '@vue/composition-api'
// console.log('config.output AA', { ...config.output });
}
},
chainWebpack: config => {
console.log('process.env.NODE_ENV', process.env.NODE_ENV);
// // 不编译 layui
config.module
.rule('js')
.test(/\.jsx?$/)
.exclude
.add(path.resolve(__dirname, './src/vue-uieditor/layui'))
.end();
config.plugin('copy-assets').use(CopyWebpackPlugin, [
[{
from: './src/vue-uieditor/assets/',
to: './vue-uieditor/assets/'
}]
]);
if (isLib) {
// 为生产环境修改配置...
config.entry('app').clear();
const entryFile = path.resolve(__dirname, `./src/${uieditorName}/index.ts`);
config.entry('app').add(entryFile).end();
const tsConfigFile = path.resolve(__dirname, './tsconfig.json');
const declarationDir = path.resolve(__dirname, './lib/@types-build');
//pack 输出 types
config.module.rule('ts')
.use('ts-loader')
.loader('ts-loader')
.tap(options => {
Object.assign(options, {
context: __dirname,
configFile: tsConfigFile,
transpileOnly: false,
happyPackMode: false,
compilerOptions: {
"declaration": true,
"declarationDir": declarationDir
}
});
return options;
});
config.module.rule('ts').uses.delete('thread-loader');
config.module.rule('ts').uses.delete('cache-loader');
config.plugins.delete('html');
config.plugins.delete('preload');
config.plugins.delete('prefetch');
config.plugins.delete('copy');
const packageFile = (function saveLibPackage() {
const { name, version, description, main, keyword, types, homepage, author } = package;
const newPackage = {
name, version, author, description, main, keyword, types, homepage,
"scripts": {},
"dependencies": {
"vue": "^2.6.10",
"vue-template-compiler": "^2.6.10",
"@vue/composition-api": "^1.4.0",
"lodash": "^4.17.21"
},
"devDependencies": {}
};
const os = require('os');
const newPath = path.resolve(os.tmpdir(), './vue-uieditor');
if (!fs.existsSync(newPath)) fs.mkdirSync(newPath);
const newFile = path.resolve(newPath, 'package.json');
fs.writeFileSync(newFile, JSON.stringify(newPackage, null, 2), 'utf-8');
return newFile;
})();
config.plugin('copy-lib-files').use(CopyWebpackPlugin, [
[
{
from: packageFile,
to: './'
},
{
from: './README.md',
to: './'
}
]
]);
} else {
// 为开发环境修改配置...
// config.plugins.delete('html');
// config.plugins.delete('copy');
// const uieditorPath = path.resolve(__dirname, `./node_modules/${uieditorName}`);
// const uieditorFile = path.resolve(uieditorPath, './index.js');
// if (fs.existsSync(uieditorFile)) {
// config.plugin('copy-vue-uieditor').use(CopyWebpackPlugin, [
// [{
// from: path.resolve(uieditorPath, `./${uieditorName}`),
// to: `./${uieditorName}`
// }]
// ]);
// }
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/joshho/vue-uieditor.git
git@gitee.com:joshho/vue-uieditor.git
joshho
vue-uieditor
vue-uieditor
develop

搜索帮助