PWA for website based on html not working - javascript

I am trying to integrate PWA into this html page https://moodmap.app/ .
I have used a manifest and created the service worker required - but it won't load for some reason?
directory layout below.
└── src
├── assets
│ ├── icons.svg
│ ├── images
│ │ ├── apple-touch-icon.png
│ │ ├── favicon.png
│ │ ├── image01.jpg
│ │ ├── image02.jpg
│ │ ├── _image02.svg
│ │ └── share.jpg
│ ├── LovelyChart.custom.js
│ ├── main.css
│ ├── main.js
│ ├── main_large.css
│ ├── main.min.js
│ ├── noscript.css
│ ├── noscript_other.css
│ └── videos
│ ├── video01.mp4
│ └── video01.mp4.jpg
├── example.html
├── index.html
├── manifest.json
├── pay.html
├── serviceworker.js
├── signup.html
└── stats.html
servicework.js
const staticMoodmap = "dev-MoodMap-site-v1"
const assets = [
"/",
"/index.html",
"/stats.html",
// "/signup.html",
// "/pay.html",
// "/assets/noscript.css",
// "/assets/main.css",
"/assets/main.min.js",
"/assets/LovelyChart.custom.js",
"/assets/icons.svg",
"/assets/images/image01.jpg",
"/assets/images/image02.jpg",
"/assets/images/share.jpg",
"/assets/images/_image02.svg",
"/assets/images/favicon.png",
"/assets/images/apple-touch-icon.png",
"/assets/videos/video01.mp4.jpg",
"/assets/images/video01.mp4",
]
self.addEventListener("install", installEvent => {
installEvent.waitUntil(
caches.open(staticMoodmap).then(cache => {
cache.addAll(assets)
})
)
})
self.addEventListener("fetch", fetchEvent => {
fetchEvent.respondWith(
caches.match(fetchEvent.request).then(res => {
return res || fetch(fetchEvent.request)
})
)
})
manifest.json
{
"name": "MoodMap",
"short_name": "MoodMap",
"start_url": "./index.html",
"display": "standalone",
"background_color": "#fdfdfd",
"theme_color": "#db4938",
"orientation": "portrait-primary",
"icons": [
{
"src": "/assets/images/image01.jpg",
"type": "image/jpg", "sizes": "72x72"
}
]
}
main.js
....
if ("serviceWorker" in navigator) {
window.addEventListener("load", function() {
navigator.serviceWorker
.register("./serviceworker.js")
.then(res => console.log("service worker registered"))
.catch(err => console.log("service worker not registered", err))
})
}
So I'm thinking that it has something to do with how I am integrating the javascript? or the directory structure?

I think the problem is on setting index.html because this link is not available
https://moodmap.app/index.html
So maybe you should change
"start_url": "./index.html"
You should change it to
"start_url": "/index.html"
Or
"start_url": "/"

Related

Rollup & React- How to separate component bundles?

I currently am trying to build a UI Library for React and I am having a little bit of trouble. Currently I am using typescript and rollup, and I am able to bundle a single index.js and I am able to import those components but it is importing the whole library.
Currently:
File structure:
src
--components
-----button
-------button.tsx
-------button.types.ts
-----input
-------input.tsx
-------input.types.ts
-----index.ts
rollup.js
My rollup targets index.ts which has everything exported like so:
export { default as Button} from './button/button'
export { default as Input } from './input/input'
And I am able to import in a react project like so:
import { Button, Input } from 'my-library'
What I would Like to do
I would like that each component is bundled separately and they would be imported like so
import { Input } from 'my-library/input'
import { Button } from 'my-library/button'
What I've Tried:
After reading the docs, it seemed that the preserveModule: true is what I was looking for but then I tried importing as above but it started to complain that nothing was found.
My current rollup.js looks like this:
export default {
input: 'src/index.ts',
output: [
{
exports: 'named',
dir: 'build/',
format: 'esm',
sourcemap: true,
preserveModules: true,
},
],
plugins: [
cleaner({ targets: ['./build'] }),
peerDepsExternal(),
resolve(),
commonjs(),
terser(),
typescript({
exclude: ['**/*.stories.tsx', '**/*.test.tsx'],
}),
],
};
EDIT: I've posted a more comprehensive tutorial on medium here
I tried using preserveModules but it doesnt generate an index.js file for each Components such that I can import like so :
import Button from 'lib/Button'
Hence I came up with a work around to make rollup loop through my src folders to generate a folder with entrypoint for every Component folder i had in src at rootDir
Maintain a strict folder structure with entry point for every Component folder. Do not have loose files, other than index.ts in src folder that have no folders. Name your folders properly like how you want users to import it
src folder structure:
rollup.config.js
src
├── Accordion
│ ├── Accordion.tsx
│ ├── AccordionBody.tsx
│ ├── AccordionButton.tsx
│ ├── AccordionCollapse.tsx
│ ├── AccordionContext.ts
│ ├── AccordionHeader.tsx
│ ├── AccordionItem.tsx
│ ├── AccordionItemContext.ts
│ └── index.ts
├── Alert
│ ├── Alert.tsx
│ └── index.ts
├── Badge
│ ├── Badge.tsx
│ └── index.ts
├── Breadcrumb
│ ├── Breadcrumb.tsx
│ ├── BreadcrumbItem.tsx
│ └── index.ts
├── Button
│ ├── Button.tsx
│ └── index.ts
├── ButtonGroup
│ ├── ButtonGroup.tsx
│ └── index.ts
...
├── Tooltip
│ ├── Tooltip.tsx
│ ├── TooltipBox.tsx
│ └── index.ts
├── index.ts
Its crucial for this case to maintain an entry point for each Component folder. I still maintained an entry point for src folder so that users can still import multiple components from the library with one line
i.e. import {Button, Accordion, ...} from 'lib'
Rollup config
getFolders returns an array of Folder names that are meant for export
loop through getFolders to generate the rollup obj per folder.
For typescript projects, rollup outputs the typings file with preserved folder structure already, so I realised that the folders Accordion, Button etc. were already there with typings file only. Now we need to add the index.js file to it!
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import resolve from '#rollup/plugin-node-resolve';
import commonjs from '#rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import replace from '#rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';
const packageJson = require('./package.json');
import { getFolders } from './scripts/buildUtils';
const plugins = [
peerDepsExternal(),
resolve(),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
useTsconfigDeclarationDir: true,
}),
terser()
]
const getFolders = (entry) => {
// get the names of folders and files of the entry directory
const dirs = fs.readdirSync(entry)
// do not include folders not meant for export and do not process index.ts
const dirsWithoutIndex = dirs.filter(name => name !== 'index.ts').filter(name => name !== 'utils')
// ['Accordion', 'Button'...]
return dirsWithoutIndex
}
//loop through your folders and generate a rollup obj per folder
const folderBuilds = getFolders('./src').map(folder=> {
return {
input: `src/${folder}/index.ts`,
output: {
// ensure file destination is same as where the typings are
file: `dist/${folder}/index.js`,
sourcemap: true,
exports: 'named',
},
plugins,
external: ['react', 'react-dom'],
}
})
export default [
{
input: ['src/index.ts'],
output: [
{
file: packageJson.module,
format: 'esm',
sourcemap: true,
exports: 'named',
},
],
plugins,
external: ['react', 'react-dom'],
},
...folderBuilds,
{
input: ['src/index.ts'],
output: [
{
file: packageJson.main,
format: 'cjs',
sourcemap: true,
exports: 'named',
},
],
plugins,
external: ['react', 'react-dom'],
},
];
CJS file
finally i also added the rollup config to generate the cjs file. I did not bother to code split the cjs file since most users are using es6 imports
"frank" build
Post build, I run a script to copy paste package.json, Readme to the ./dist folder
/* eslint-disable no-console */
const { resolve, join, basename } = require('path');
const { readFile, writeFile, copy } = require('fs-extra');
const packagePath = process.cwd();
const distPath = join(packagePath, './dist');
const writeJson = (targetPath, obj) =>
writeFile(targetPath, JSON.stringify(obj, null, 2), 'utf8');
async function createPackageFile() {
const packageData = await readFile(
resolve(packagePath, './package.json'),
'utf8'
);
const { scripts, devDependencies, ...packageOthers } =
JSON.parse(packageData);
const newPackageData = {
...packageOthers,
private: false,
typings: './index.d.ts',
main: './main.js',
module: './index.js',
};
const targetPath = resolve(distPath, './package.json');
await writeJson(targetPath, newPackageData);
console.log(`Created package.json in ${targetPath}`);
}
async function includeFileInBuild(file) {
const sourcePath = resolve(packagePath, file);
const targetPath = resolve(distPath, basename(file));
await copy(sourcePath, targetPath);
console.log(`Copied ${sourcePath} to ${targetPath}`);
}
async function run() {
try {
await createPackageFile();
await includeFileInBuild('./README.md');
// await includeFileInBuild('../../LICENSE');
} catch (err) {
console.error(err);
process.exit(1);
}
}
run();
finally from root npm publish ./dist
This is how my dist folder looks like finally
dist
├── Accordion
│ ├── Accordion.d.ts
│ ├── AccordionBody.d.ts
│ ├── AccordionButton.d.ts
│ ├── AccordionCollapse.d.ts
│ ├── AccordionContext.d.ts
│ ├── AccordionHeader.d.ts
│ ├── AccordionItem.d.ts
│ ├── AccordionItemContext.d.ts
│ ├── index.d.ts
│ ├── index.js
│ └── index.js.map
├── Alert
│ ├── Alert.d.ts
│ ├── index.d.ts
│ ├── index.js
│ └── index.js.map
├── Badge
│ ├── Badge.d.ts
│ ├── index.d.ts
│ ├── index.js
│ └── index.js.map
├── Breadcrumb
│ ├── Breadcrumb.d.ts
│ ├── BreadcrumbItem.d.ts
│ ├── index.d.ts
│ ├── index.js
│ └── index.js.map
├── Button
│ ├── Button.d.ts
│ ├── index.d.ts
│ ├── index.js
│ └── index.js.map
├── ButtonGroup
│ ├── ButtonGroup.d.ts
│ ├── index.d.ts
│ ├── index.js
│ └── index.js.map
...
├── Tooltip
│ ├── Tooltip.d.ts
│ ├── TooltipBox.d.ts
│ ├── index.d.ts
│ ├── index.js
│ └── index.js.map
├── index.d.ts
├── index.js
├── index.js.map
├── main.js
├── main.js.map
├── package.json
I got my solutions after much research from rollup issue thread on gh.
Here are some references:
Franking the build : https://stackoverflow.com/questions/62518396/importing-from-subfolders-for-a-javascript-package#:~:text=Votes-,13,-This%20is%20possible
folder structuring :
https://github.com/ezolenko/rollup-plugin-typescript2/issues/136#issuecomment-792383946
inspiration for getFolders() that i wrote was from this author's getFiles()
https://www.codefeetime.com/post/rollup-config-for-react-component-library-with-typescript-scss/

Ember Module Unification Stack trace: Error: Assertion Failed: 'data-adapter' is not a recognized type

Ember data won't show on the inspector.The error is showing below.
I am using module unification in new ember. module unification ember
Can someone tell me how to fix it because I need to see data in ember inspector?
The data show an empty data which I see the model but there is nothing(image below):
Ember Inspector has errored.
This is likely a bug in the inspector itself.
You can report bugs at https://github.com/emberjs/ember-inspector.
Error message: Assertion Failed: 'data-adapter' is not a recognized type
Stack trace: Error: Assertion Failed: 'data-adapter' is not a recognized type
at assert (http://localhost:4200/assets/vendor.js:73088:19)
at Resolver._definitiveCollection (http://localhost:4200/assets/vendor.js:73063:31)
at Resolver.identify (http://localhost:4200/assets/vendor.js:73027:37)
at Resolver.resolve (http://localhost:4200/assets/vendor.js:73055:27)
at Class.resolve (http://localhost:4200/assets/vendor.js:98399:36)
at Class.resolve (http://localhost:4200/assets/vendor.js:98232:25)
at Class.superWrapper [as resolve] (http://localhost:4200/assets/vendor.js:41053:22)
at _resolve (http://localhost:4200/assets/vendor.js:12906:36)
at Registry.resolve (http://localhost:4200/assets/vendor.js:12445:21)
at Registry.resolve (http://localhost:4200/assets/vendor.js:12450:60)
warn # VM2062:92
handleError # VM2062:149
(anonymous) # VM2062:3515
_run # backburner.js:1066
run # backburner.js:748
run # index.js:111
wrap # VM2062:3511
messageReceived # VM2062:3482
get.onMessageReceived.message # VM2062:3476
get.forEach.callback # VM2062:127
_messageReceived # VM2062:126
run # VM2062:344
_run # backburner.js:1066
run # backburner.js:748
run # index.js:111
chromePort.addEventListener.event # VM2062:343
file tree:
src
├── data
│ └── models
│ ├── application
│ │ └── model.js
│ └── user
│ ├── adapter.js
│ └── model.js
├── formats.js
├── init
│ └── initializers
│ └── i18n.js
├── main.js
├── resolver.js
├── router.js
├── services
│ └── intl.ts
└── ui
├── components
├── index.html
├── routes
│ ├── about-page
│ │ ├── route.js
│ │ └── template.hbs
│ ├── application
│ │ ├── controller.js
│ │ ├── route.js
│ │ └── template.hbs
│ └── user
│ ├── controller.js
│ ├── route.js
│ └── template.hbs
├── styles
│ └── app.css
└── utils
This is the file structure of the module unification. There is nothing special in the package.json.
After adding those configuration (from #NullVoxPopuli) to the resolver.js
"data-adapter": { definitiveCollection: "main" },
"container-debug-adapter": { definitiveCollection: "main" },
"resolver-for-debugging": { definitiveCollection: "main" }
assign(moduleConfig.collections, {
data: { types: ["data-adapter", "model"], defaultType: "model" }
});
This is def one of the rougher parts of module unification at the moment.
So far, I've been able to get the data tab on the inspector to be loaded with this resolver config:
import Resolver from 'ember-resolver/resolvers/fallback';
import buildResolverConfig from 'ember-resolver/ember-config';
import config from '../config/environment';
let moduleConfig = buildResolverConfig(config.modulePrefix);
moduleConfig.types = Object.assign(moduleConfig.types, {
// ember-inspector support
'data-adapter': { definitiveCollection: 'main' },
'container-debug-adapter': { definitiveCollection: 'main' },
'resolver-for-debugging': { definitiveCollection: 'main' },
});
moduleConfig.collections.main.types.push('data');
moduleConfig.collections = Object.assign(moduleConfig.collections, {
data: {
types: ['data-adapter', 'model'],
defaultType: 'model',
},
});
export default Resolver.extend({
config: moduleConfig,
});
with this config, the models are only picked up if they are named in src/data/models/{model-name}.js -- if a model is at src/data/models/{model-name}/model.js, this does not tell the inspector where to look.

Can't test a function with a dynamic import with Jest and babel-plugin-dynamic-import-node

I'm trying to test the following function:
export async function loadLocale(language) {
return await import(`./locales/${language}.json`)
}
With the following code:
import * as utils from '#/langs/utils'
describe('language utils to interact with vue-i18n', () => {
it('should load a given locale from file', async () => {
const language = 'es'
expect.assertions(1)
const locale = await utils.loadLocale(language)
expect(locale).toEqual({ foo: 'bar' })
})
})
I have installed babel-plugin-dynamic-import-node because the dynamic imports don't work in Node and must be replaced with require.
This are the contents of the es.json I try to load:
{
"foo": "bar"
}
My .babelrc config is as follows:
{
"presets": [
"#vue/app"
],
"plugins": [
"syntax-dynamic-import"
],
"env": {
"test": {
"plugins": ["dynamic-import-node"]
}
}
}
And this is my folder structure:
│   ├── langs
│   │   ├── i18n.js
│   │   ├── locales # Actual locales
│   │   │   ├── en.json
│   │   │   └── es.json
│   │   └── utils.js
├── tests
│   └── unit
│   ├── langs
│   │   ├── locales # Mocked locales
│   │   │   ├── en.json
│   │   │   └── es.json
│   │   └── utils.spec.js
As I'm using the configuration provided by vue-cli I've tried running Jest with the --no-cache flag as this answer mentions.
The error I get is the following:
Cannot find module 'function () {
return require("./locales/".concat(language, ".json"));
}' from 'utils.js'
11 | }
12 |
> 13 | export async function loadLocale(language) {
14 | return await import(`./locales/${language}.json`)
15 | }
16 |
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
at src/langs/utils.js:13:8
Which doesn't make sense, because ./locales/es.json exists! And moreover, i've tried using require with the exact same route from the test and it loads correctly it's contents.
Any ideas?
You use dynamic-import-node plugin twice. I did the same with
"presets": [
"react-app",
],
See vue-cli/packages/#vue/babel-preset-app/index.js

Gulp using gulp-data and gulp-jade with directory

I have a gulp workflow with everything works well, but it seems like it only work on the uppermost file, for example: public/index.html, but if I would like to use public/products/item.html, gulp-data would throw an error and look for src/json/item.json instead of src/json/products/item.json.
I think there is something wrong since I used path.basename(file.path, '.jade') + '.json'), it will return the filename only, of course, if so, how to make it also provide the directory if it throws something like products/item.jade?
var basePath = {
src: 'src/',
dest: 'public/'
}
var src = {
pages: basePath.src + 'jade/',
json : basePath.src + 'json'
}
gulp.task('make:pages', function() {
return gulp.src(src.pages + '**/!(_)*.jade')
.pipe(plumber({
errorHandler: onError
}))
.pipe(data(function(file) {
return JSON.parse(fs.readFileSync('src/json/' + path.basename(file.path, '.jade') + '.json'));
}))
.pipe(jade({
pretty: true
}))
.pipe(gulp.dest(basePath.dest));
});
Providing I am using the same folder structure:
src
├── fonts
├── jade
│   ├── _layout.jade
│   ├── index.jade
│   ├── product
│   │   └── item.jade
│   ├── partials
│   │   ├── _footer.jade
│   │   └── _header.jade
├── js
├── json
│   ├── index.json
│   ├── product
│   │   └── item.json
I used this instead:
return JSON.parse(fs.readFileSync(file.path.replace(/jade/g, 'json')));
and it works! :)

Getting a strange error with grunt: Object Gruntfile.js has no method 'flatten'

I am getting this strange error trying to run grunt: TypeError: Object Gruntfile.js has no method 'flatten'
I am new to node.js, npm, grunt, etc. I thought I did a decent install of node, npm, grunt but may be I missed something. Is there a way to verify the install??
$ cat xx
$ grunt
/home/cl/node_modules/grunt/node_modules/findup-sync/lib/findup-sync.js:33
}).flatten().uniq().value();
^
TypeError: Object Gruntfile.js has no method 'flatten'
at Object.module.exports [as findup] (/home/cl/node_modules/grunt/node_modules/findup-sync/lib/findup-sync.js:33:8)
at Task.task.init (/home/cl/node_modules/grunt/lib/grunt/task.js:414:16)
at Object.grunt.tasks (/home/cl/node_modules/grunt/lib/grunt.js:113:8)
at Object.module.exports [as cli] (/home/cl/node_modules/grunt/lib/grunt/cli.js:38:9)
at Object.<anonymous> (/usr/lib/node_modules/grunt-cli/bin/grunt:41:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
The offending line/file:
/*
* findup-sync
* https://github.com/cowboy/node-findup-sync
*
* Copyright (c) 2013 "Cowboy" Ben Alman
* Licensed under the MIT license.
*/
'use strict';
// Nodejs libs.
var path = require('path');
// External libs.
var glob = require('glob');
var _ = require('lodash');
// Search for a filename in the given directory or all parent directories.
module.exports = function(patterns, options) {
// Normalize patterns to an array.
if (!Array.isArray(patterns)) { patterns = [patterns]; }
// Create globOptions so that it can be modified without mutating the
// original object.
var globOptions = Object.create(options || {});
globOptions.maxDepth = 1;
globOptions.cwd = path.resolve(globOptions.cwd || '.');
var files, lastpath;
do {
// Search for files matching patterns.
files = _(patterns).map(function(pattern) {
return glob.sync(pattern, globOptions);
}).flatten().uniq().value(); // <--------- OFFENDING LINE
// Return file if found.
if (files.length > 0) {
return path.resolve(path.join(globOptions.cwd, files[0]));
}
// Go up a directory.
lastpath = globOptions.cwd;
globOptions.cwd = path.resolve(globOptions.cwd, '..');
// If parentpath is the same as basedir, we can't go any higher.
} while (globOptions.cwd !== lastpath);
// No files were found!
return null;
};
Output of ls -l node_modules/:
$ ls -l node_modules/
total 20
drwxrwxr-x. 6 a a 4096 Oct 2 00:42 grunt
drwxrwxr-x. 4 a a 4096 Oct 2 00:42 grunt-contrib-compass
drwxrwxr-x. 6 a a 4096 Oct 2 00:42 grunt-contrib-jshint
drwxrwxr-x. 6 a a 4096 Oct 2 00:42 grunt-contrib-watch
drwxrwxr-x. 4 a a 4096 Oct 2 00:42 grunt-dustjs
Output of npm list:
$ npm list
prepscholar#0.0.0 /home/a/prep/main/web/client
├─┬ grunt#0.4.1
│ ├── async#0.1.22
│ ├── coffee-script#1.3.3
│ ├── colors#0.6.2
│ ├── dateformat#1.0.2-1.2.3
│ ├── eventemitter2#0.4.13
│ ├─┬ findup-sync#0.1.2
│ │ └── lodash#1.0.1
│ ├─┬ glob#3.1.21
│ │ ├── graceful-fs#1.2.3
│ │ └── inherits#1.0.0
│ ├── hooker#0.2.3
│ ├── iconv-lite#0.2.11
│ ├─┬ js-yaml#2.0.5
│ │ ├─┬ argparse#0.1.15
│ │ │ ├── underscore#1.4.4
│ │ │ └── underscore.string#2.3.3
│ │ └── esprima#1.0.4
│ ├── lodash#0.9.2
│ ├─┬ minimatch#0.2.12
│ │ ├── lru-cache#2.3.1
│ │ └── sigmund#1.0.0
│ ├─┬ nopt#1.0.10
│ │ └── abbrev#1.0.4
│ ├─┬ rimraf#2.0.3
│ │ └── graceful-fs#1.1.14
│ ├── underscore.string#2.2.1
│ └── which#1.0.5
├─┬ grunt-contrib-compass#0.5.0
│ ├── async#0.2.9
│ ├── dargs#0.1.0
│ └── tmp#0.0.21
├─┬ grunt-contrib-jshint#0.6.4
│ └─┬ jshint#2.1.10
│ ├─┬ cli#0.4.5
│ │ └─┬ glob#3.2.6
│ │ └── inherits#2.0.1
│ ├── console-browserify#0.1.6
│ ├─┬ minimatch#0.2.12
│ │ ├── lru-cache#2.3.1
│ │ └── sigmund#1.0.0
│ ├── shelljs#0.1.4
│ └── underscore#1.4.4
├─┬ grunt-contrib-watch#0.5.3
│ ├─┬ gaze#0.4.2
│ │ └─┬ globule#0.1.0
│ │ ├─┬ glob#3.1.21
│ │ │ ├── graceful-fs#1.2.3
│ │ │ └── inherits#1.0.0
│ │ ├── lodash#1.0.1
│ │ └─┬ minimatch#0.2.12
│ │ ├── lru-cache#2.3.1
│ │ └── sigmund#1.0.0
│ └─┬ tiny-lr#0.0.4
│ ├── debug#0.7.2
│ ├── faye-websocket#0.4.4
│ ├─┬ noptify#0.0.3
│ │ └─┬ nopt#2.0.0
│ │ └── abbrev#1.0.4
│ └── qs#0.5.6
└─┬ grunt-dustjs#1.1.1
└── dustjs-linkedin#2.0.3
Output of cat package.json:
$ cat package.json
{
"name": "prepscholar",
"version": "0.0.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.4",
"grunt-dustjs": "~1.1.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-compass": "~0.5.0"
}
}
Output of cat Gruntfile.js:
$ cat Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['Gruntfile.js', 'app/js/**/*.js', '!app/js/lib/**/*.js']
},
dustjs: {
compile: {
src: ['app/templates/**/*.html'],
dest: 'app/js/templates.js'
}
},
compass: {
dev: {
options: {
sassDir: 'app/sass',
cssDir: 'app/css',
imagesDir: 'app/img',
fontsDir: 'app/fonts',
javascriptsDir: 'app/js/app',
outputStyle: 'compressed'
}
}
},
watch: {
gruntfile: {
files: 'Gruntfile.js',
tasks: ['compile']
},
css: {
files: 'app/sass/**/*.scss',
tasks: ['compass:dev']
},
livereload: {
options: { livereload: true },
files: ['app/css/**/*']
},
dust: {
files: 'app/templates/**/*.html',
tasks: ['dustjs']
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-dustjs');
grunt.loadNpmTasks('underscore');
grunt.registerTask('default', ['compile', 'watch']);
grunt.registerTask('compile', ['dust', 'compass']);
grunt.registerTask('dust', ['dustjs']);
grunt.registerTask('lint', ['jshint']);
};
Found that this worked, as per https://github.com/gruntjs/grunt/issues/888
rm -rf node_modules/grunt
npm install grunt
This should work too.
Try reinstalling your node modules.
Delete the node_modules folder
Do npm cache clean
Do npm install
Hope it helps :)
As was written in https://github.com/gruntjs/grunt/issues/888 dist in your .gitignore
Hope that helps
That looks like one of your grunt modules is trying to use underscore.js but it's not installed. This should fix your problem:
npm install underscore
Or even better, add underscore as a development dependency in your package.json:
{
<your existing stuff here>
"devDependencies": {
"underscore": "~1.5.2"
}
}

Categories