这很奇怪。使用本教程:https://ntdln.com/2017/07/25/using-javascript-modules/我尝试在JS中获取模块。我和其他软件包一起运行npm istall grunt-browserify --save-dev
。我的package.json文件是
{
"name": "example",
"version": "0.1.0",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babelify": "^8.0.0",
"browserify": "^14.5.0",
"grunt": "^0.4.5",
"grunt-autoprefixer": "^3.0.4",
"grunt-contrib-imagemin": "^2.0.1",
"grunt-contrib-sass": "^1.0.0",
"grunt-contrib-uglify": "^3.0.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-es6-transpiler": "^1.0.2",
"grunt-typescript": "^0.8.0",
"typescript": "^2.4.2"
}
}
所以包裹在那里。我尝试删除我的nodemodules文件夹并使用npm insatll安装它,但它没有帮助。
我的grunt.js文件就是这个
module.exports = function (grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
build: {
options: {
browserifyOptions: {
debug: false
},
transform: [
[
'babelify', {
'presets': [
[
'es2015', {
'loose': true
}
]
],
'comments': false,
'compact': true,
'minified': true
}
]
]
},
src: [
'_dev/js/app.js',
],
dest: './scripts/app.es5.min.js'
}
},
// es6transpiler: {
// dist: {
// files: {
// '_dev/js/app.es5.js': '_dev/js/app.js'
// }
// }
// },
// uglify: {
// build: {
// src: "_dev/js/app.es5.js",
// dest: "scripts/app.es5.min.js"
// }
// },
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'_dev/css/app.min.css': '_dev/scss/app.scss'
}
}
},
autoprefixer: {
dist: {
files: {
'content/app.prefixed.min.css': '_dev/css/app.min.css'
}
}
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: '_dev/assets/images/',
src: ['**/*.{png,jpg,gif}'],
dest: 'assets/img/'
}]
}
},
watch: {
scripts: {
files: ['_dev/js/*.js'],
tasks: ['browserify', 'uglify'],
options: {
spawn: false,
}
},
css: {
files: '_dev/scss/app.scss',
tasks: ['sass', 'autoprefixer']
}
} //End watch
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('browserify');
grunt.loadNpmTasks('babelify');
grunt.loadNpmTasks('babel-preset-es2015');
// grunt.loadNpmTasks('grunt-contrib-uglify');
// grunt.loadNpmTasks('grunt-es6-transpiler');
// grunt.loadNpmTasks('grunt-contrib-requirejs');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask(
'default', [
// 'es6transpiler',
// 'uglify',
'browserify',
'babelify',
'babel-preset-es2015',
'sass',
'autoprefixer',
'imagemin',
'watch'
]);
};
运行咕噜声后我仍然得到的是:
>> Local Npm module "browserify" not found. Is it installed?
>> Local Npm module "babelify" not found. Is it installed?
>> Local Npm module "babel-preset-es2015" not found. Is it installed?
答案 0 :(得分:2)
使用如下所示的grunt browserify:
npm install grunt-browserify --save-dev
安装后:
grunt.loadNpmTasks('grunt-browserify');
其他模块也是如此