我有一个使用 weyland 作为构建优化器的旧版 asp.net + durandal.js 应用程序。我们正在尝试升级到 grunt 以使用更新的东西,但我无法让它正确生成缩小的 js 构建文件。我有以下weyland-config
文件:
exports.config = function(weyland) {
weyland.build('main')
.task.jshint({
include:'App/**/*.js'
})
.task.uglifyjs({
include: ['App/**/*.js', 'Scripts/durandal/**/*.js'],
exclude: ['App/main-built.js']
})
.task.rjs({
include:['App/**/*.{js,html}', 'Scripts/durandal/**/*.js'],
loaderPluginExtensionMaps:{
'.html':'text'
},
rjs:{
name:'../Scripts/almond-custom',
insertRequire:['main'],
baseUrl : 'App',
wrap:true,
paths : {
'text': '../Scripts/text',
'durandal': '../Scripts/durandal',
'plugins': '../Scripts/durandal/plugins',
'transitions': '../Scripts/durandal/transitions',
'knockout': 'empty:',
'bootstrap': 'empty:',
'jquery': 'empty:'
},
inlineText: true,
optimize : 'none',
pragmas: {
build: true
},
stubModules : ['text'],
keepBuildDir: true,
out:'App/main-built.js'
}
});
}
我一直在尝试gruntfile
根据这个和这个来创建,这就是我所拥有的:
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
jshint: {
include: 'App/**/*.js'
},
durandal: {
main: {
src: [
"App/**/*.*",
"Scripts/durandal/**/*.js"
],
options: {
name: '../Scripts/almond-custom',
baseUrl: './App/',
mainPath: "App/main",
paths: {
'jquery': '../Scripts/jquery-3.6.0',
'text': '../Scripts/text',
'knockout': '../Scripts/knockout-3.4.1',
'durandal': '../Scripts/durandal',
'plugins': '../Scripts/durandal/plugins',
'transitions': '../Scripts/durandal/transitions',
},
exclude: [],
optimize: 'none',
out: "App/main.js"
}
}
},
uglify: {
build: {
src: 'App/main.js',
dest: 'App/main-built.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks("grunt-durandal");
// Default task(s).
grunt.registerTask('default', ['durandal', 'uglify']);
};
但是当我尝试运行 grunt 时,出现以下错误:
Error: TypeError: Cannot read property 'normalize' of undefined
>> at Module.<anonymous> (APP_PATH\node_modules\requirejs\bin\r.js:1218:36)
如果我尝试只运行 uglify,我会得到错误的压缩文件(错误的意思是应用程序在尝试使用它时会抛出错误)。有人知道如何正确地将它从 weyland 移植到 grunt 吗?