我正在尝试在我的项目中使用 yeoman,但在尝试使用 Grunt 构建它时遇到了问题:
我有一个 application.js,它是应用程序使用的主文件,使用 require.js。运行 Grunt build 后,会在 dist 文件夹中创建 js 文件,并将其连接并缩小。
问题是当我尝试创建第二个 javascript 文件(例如 application2.js)以在应用程序的另一个页面中使用时。运行 Grunt 后,文件已创建但为空。我尝试使用与排除某些 js 或 require.js 问题的 js 相同的 js,但结果相同。
我唯一能想到的是,Grunt 中的某处被配置为仅处理该文件,实际上在运行时我可以在控制台中看到以下内容:
Found a block:
<!-- build:js scripts/application.js -->
<script data-main="scripts/application" src="components/requirejs/require.js"></script>
<!-- endbuild -->
Updating config with the following assets:
- dist/scripts/application.js
Found a block:
<!-- build:js scripts/application2.js -->
<script data-main="scripts/application2" src="components/requirejs/require.js"></script>
<!-- endbuild -->
Updating config with the following assets:
- dist/scripts/application2.js
Configuration is now:
cssmin:
{ dist: {} }
concat:
{ 'dist/scripts/application.js': [ 'dist/scripts/application.js' ],
'dist/scripts/vendor/modernizr.js': [ 'app/components/modernizr/modernizr.js' ],
'dist/scripts/application2.js': [ 'dist/scripts/application2.js' ] }
uglify:
{ 'dist/scripts/application.js': 'dist/scripts/application.js',
'dist/components/requirejs/require.js': 'app/components/requirejs/require.js',
'dist/scripts/vendor/modernizr.js': 'dist/scripts/vendor/modernizr.js',
'dist/scripts/application2.js': 'dist/scripts/application2.js' }
requirejs:
{ dist:
{ options:
{ baseUrl: 'app/scripts',
optimize: 'none',
preserveLicenseComments: false,
useStrict: true,
wrap: true,
uglify2: {},
name: 'application',
out: 'dist/scripts/application.js',
mainConfigFile: 'app/scripts/application.js' } } }
Running "requirejs:dist" (requirejs) task
>> RequireJS optimizer finished
Uncompressed size: 1361156 bytes.
Compressed size: 304370 bytes gzipped.
Concat 和 Uglify 任务引用第二个 javascript 文件,但需要 js。我尝试更改属性“mainConfigFile”,以包括两者,但它不断被覆盖......
有任何想法吗??