8 Star 47 Fork 17

sanluan/ueditor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Gruntfile.js 5.88 KB
一键复制 编辑 原始数据 按行查看 历史
sanluan 提交于 2023-04-27 11:38 . update doc
'use strict';
module.exports = function (grunt) {
var fs = require("fs"),
Util = {
jsBasePath: '_src/',
parseBasePath: '_parse/',
cssBasePath: 'themes/default/_css/',
fetchScripts: function (readFile, basePath) {
var sources = fs.readFileSync(readFile);
sources = /\[([^\]]+\.js'[^\]]+)\]/.exec(sources);
sources = sources[1].replace(/\/\/.*\n/g, '\n').replace(/'|"|\n|\t|\s/g, '');
sources = sources.split(",");
sources.forEach(function (filepath, index) {
sources[ index ] = basePath + filepath;
});
return sources;
},
fetchStyles: function () {
var sources = fs.readFileSync(this.cssBasePath + "ueditor.css"),
filepath = null,
pattern = /@import\s+([^;]+)*;/g,
src = [];
while (filepath = pattern.exec(sources)) {
src.push(this.cssBasePath + filepath[ 1 ].replace(/'|"/g, ""));
}
return src;
}
},
packageJson = grunt.file.readJSON('package.json'),
encode = grunt.option('encode') || 'utf8',
disDir = "dist/",
banner = '/*!\n * UEditor\n * version: ' + packageJson.name + '-'+ packageJson.version+'\n */\n\n';
//init
(function () {
encode = typeof encode === "string" ? encode.toLowerCase() : 'utf8';
disDir = 'dist/' + packageJson.name + '-'+packageJson.version+'/';
})();
grunt.initConfig({
pkg: packageJson,
concat: {
js: {
options: {
banner: banner + '(function(){\n\n',
footer: '\n\n})();\n',
process: function (src, s) {
var filename = s.substr(s.indexOf('/') + 1);
return '// ' + filename + '\n' + src.replace('/_css/', '/css/') + '\n';
}
},
src: Util.fetchScripts("_examples/editor_api.js", Util.jsBasePath),
dest: disDir + packageJson.name + '.all.js'
},
parse: {
options: {
banner: banner + '(function(){\n\n',
footer: '\n\n})();\n'
},
src: Util.fetchScripts("ueditor.parse.js", Util.parseBasePath),
dest: disDir + packageJson.name + '.parse.js'
},
css: {
src: Util.fetchStyles(),
dest: disDir + 'themes/default/css/ueditor.css'
}
},
cssmin: {
options: {
banner: banner
},
files: {
expand: true,
cwd: disDir + 'themes/default/css/',
src: ['*.css', '!*.min.css'],
dest: disDir + 'themes/default/css/',
ext: '.min.css'
}
},
uglify: {
options: {
banner: banner
},
dest: {
src: disDir + '<%= pkg.name %>.all.js',
dest: disDir + '<%= pkg.name %>.all.min.js'
},
parse: {
src: disDir + '<%= pkg.name %>.parse.js',
dest: disDir + '<%= pkg.name %>.parse.min.js'
}
},
copy: {
base: {
files: [
{
src: [ '*.html', 'themes/iframe.css', 'themes/default/dialogbase.css', 'themes/default/images/**', 'dialogs/**', 'lang/**', 'third-party/**' , 'themes/ueditor-list/**'],
dest: disDir
}
]
},
demo: {
files: [
{
src: '_examples/completeDemo.html',
dest: disDir + 'index.html'
}
]
}
},
transcoding: {
options: {
charset: encode
},
src: [disDir + '**/*.html', disDir + '**/*.js', disDir + '**/*.css', disDir + '**/*.json']
},
replace: {
demo: {
src: disDir + 'index.html',
overwrite: true,
replacements: [
{
from: /\.\.\//gi,
to: ''
},
{
from: 'editor_api.js',
to: packageJson.name + '.all.min.js'
}
]
}
},
clean: {
build: {
src: [
disDir + ".DS_Store",
disDir + "**/.DS_Store",
disDir + ".git",
disDir + "**/.git"
]
}
}
});
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-transcoding');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('default', 'UEditor build', function () {
var tasks = [ 'concat', 'cssmin', 'uglify', 'copy:base', 'copy:demo', 'replace:demo', 'clean' ];
tasks.push('transcoding');
//config修改
updateConfigFile();
grunt.task.run(tasks);
});
function updateConfigFile() {
var filename = 'ueditor.config.js',
file = grunt.file.read(filename);
//写入到dist
if (grunt.file.write(disDir + filename, file)) {
grunt.log.writeln('config file update success');
} else {
grunt.log.warn('config file update error');
}
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sanluan/ueditor.git
git@gitee.com:sanluan/ueditor.git
sanluan
ueditor
ueditor
dev

搜索帮助

344bd9b3 5694891 D2dac590 5694891