This is strange. Using this tutorial: https://ntdln.com/2017/07/25/using-javascript-modules/ I tried to do get the modules thing in JS. I run npm istall grunt-browserify --save-dev
along with the other packages. My package.json file is
JavaScript
x
20
20
1
{
2
"name": "example",
3
"version": "0.1.0",
4
"devDependencies": {
5
"babel-core": "^6.26.0",
6
"babel-preset-es2015": "^6.24.1",
7
"babelify": "^8.0.0",
8
"browserify": "^14.5.0",
9
"grunt": "^0.4.5",
10
"grunt-autoprefixer": "^3.0.4",
11
"grunt-contrib-imagemin": "^2.0.1",
12
"grunt-contrib-sass": "^1.0.0",
13
"grunt-contrib-uglify": "^3.0.1",
14
"grunt-contrib-watch": "^1.0.0",
15
"grunt-es6-transpiler": "^1.0.2",
16
"grunt-typescript": "^0.8.0",
17
"typescript": "^2.4.2"
18
}
19
}
20
So the packages are there. I tried removing my nodemodules folder and installing it with npm insatll, but it didn’t help.
My grunt.js file is this
JavaScript
1
116
116
1
module.exports = function (grunt) {
2
// 1. All configuration goes here
3
grunt.initConfig({
4
pkg: grunt.file.readJSON('package.json'),
5
browserify: {
6
build: {
7
options: {
8
browserifyOptions: {
9
debug: false
10
},
11
transform: [
12
[
13
'babelify', {
14
'presets': [
15
[
16
'es2015', {
17
'loose': true
18
}
19
]
20
],
21
'comments': false,
22
'compact': true,
23
'minified': true
24
}
25
]
26
]
27
},
28
src: [
29
'_dev/js/app.js',
30
],
31
dest: './scripts/app.es5.min.js'
32
}
33
},
34
// es6transpiler: {
35
// dist: {
36
// files: {
37
// '_dev/js/app.es5.js': '_dev/js/app.js'
38
// }
39
// }
40
// },
41
// uglify: {
42
// build: {
43
// src: "_dev/js/app.es5.js",
44
// dest: "scripts/app.es5.min.js"
45
// }
46
// },
47
sass: {
48
dist: {
49
options: {
50
style: 'compressed'
51
},
52
files: {
53
'_dev/css/app.min.css': '_dev/scss/app.scss'
54
}
55
}
56
},
57
autoprefixer: {
58
dist: {
59
files: {
60
'content/app.prefixed.min.css': '_dev/css/app.min.css'
61
}
62
}
63
},
64
imagemin: {
65
dynamic: {
66
files: [{
67
expand: true,
68
cwd: '_dev/assets/images/',
69
src: ['**/*.{png,jpg,gif}'],
70
dest: 'assets/img/'
71
}]
72
}
73
},
74
watch: {
75
scripts: {
76
files: ['_dev/js/*.js'],
77
tasks: ['browserify', 'uglify'],
78
options: {
79
spawn: false,
80
}
81
},
82
css: {
83
files: '_dev/scss/app.scss',
84
tasks: ['sass', 'autoprefixer']
85
}
86
} //End watch
87
});
88
89
// 3. Where we tell Grunt we plan to use this plug-in.
90
grunt.loadNpmTasks('grunt-contrib-sass');
91
grunt.loadNpmTasks('grunt-contrib-imagemin');
92
grunt.loadNpmTasks('grunt-autoprefixer');
93
grunt.loadNpmTasks('grunt-contrib-watch');
94
grunt.loadNpmTasks('browserify');
95
grunt.loadNpmTasks('babelify');
96
grunt.loadNpmTasks('babel-preset-es2015');
97
// grunt.loadNpmTasks('grunt-contrib-uglify');
98
// grunt.loadNpmTasks('grunt-es6-transpiler');
99
// grunt.loadNpmTasks('grunt-contrib-requirejs');
100
101
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
102
grunt.registerTask(
103
'default', [
104
// 'es6transpiler',
105
// 'uglify',
106
'browserify',
107
'babelify',
108
'babel-preset-es2015',
109
'sass',
110
'autoprefixer',
111
'imagemin',
112
'watch'
113
]);
114
115
};
116
Still all I’m getting after running grunt is:
JavaScript
1
4
1
>> Local Npm module "browserify" not found. Is it installed?
2
>> Local Npm module "babelify" not found. Is it installed?
3
>> Local Npm module "babel-preset-es2015" not found. Is it installed?
4
Advertisement
Answer
Use grunt browserify like below :
JavaScript
1
2
1
npm install grunt-browserify --save-dev
2
And after installing :
JavaScript
1
2
1
grunt.loadNpmTasks('grunt-browserify');
2
And same thing for other modules