问题
I've configured my Angular app with Yeoman, and have included many JS libraries like d3. The application works fine when I use grunt serve to see the app. But when I try to build it using grunt build, and open the generated index.html, the app breaks because it cannot find D3. If I manually include the script tag for loading D3 in final index.html, then it starts working, but that's not how it's supposed to work, right?
The grunt build also removes google Fonts which I've included in my app:
<link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
This link tag is missing from final index.html
My bower.json looks like this:
{
"name": "myApp",
"version": "0.0.0",
"main": "index.html",
"ignore": [
"**/.*",
"node_modules",
"bower_components"
],
"dependencies": {
"jquery": "~2.2",
"lodash": "~4.9",
"bootstrap": "^3.3.6",
"angular": "~1.5",
"angular-route": "~1.5",
"angular-animate": "~1.5",
"angular-resource": "~1.5",
"angular-cookies": "^1.5.7",
"angular-mocks": "~1.5",
"angular-bootstrap": "~1.3.1",
"moment": "~2.12",
"less.js": "~2.6",
"font-awesome": "~4.5",
"d3": "^3.5.17"
}
}
I have not tested the issue with other libraries, as they might also be not working after the build. However, angular, bootstrap, font-awesome and LESS is working fine. This is driving me crazy!
回答1:
I noticed that I was using dom_munger task in gruntfile. It removed all script with data-concat="false".
D3 script was being removed because it specified data-concat="false".
The problem is fixed now.
来源:https://stackoverflow.com/questions/38693973/grunt-build-removes-d3-js-and-google-fonts-from-application