I'm getting Error: Parsing file app.js: 'import' and 'export' may appear only with 'sourceType: module' (1:0)
while using gulp with browserify and babelify
I only get the issue with one specific import vue-masked-input
my gulp task looks like this
gulp.task('js', () => {
let b = browserify({
entries: './resources/assets/js/app.js',
debug: true,
transform: [
babelify.configure({
presets: [["es2015"]]
}),
'vueify'
]
});
return b.bundle().on('error', function (e) {
console.log(e.toString());
this.emit('end');
})
.pipe(source('app.js'))
.pipe(buffer())
.pipe(prod ? uglify() : util.noop())
.pipe(gulp.dest('./public/js'))
;
});
I tried a few suggestions I found around the web
including:
presets: [["es2015", {modules: false}]],
sourceType: 'module', (under babelify.configure)
I can't seem to get gulp-rev to have the correct paths. I've tried everything I can think of.
I have two tasks (among others) one for scripts and one for styles. I can get a merged manifest.json file successfully. However, the paths are not coming through.
Here's the merged manifest.json:
{
...
"main.css": "main-b7877c7599.css",
"main.css.map": "main-b58100898e.css.map",
"main.min.js": "main-00da8f7f74.min.js",
"main.min.js.map": "main-206550c510.min.js.map",
...
}
Here is my gulpfile.babel.js file:
import gulp from 'gulp';
import del from 'del';
import runSequence from 'run-sequence';
import browserSync from 'browser-sync';
import gulpLoadPlugins from 'gulp-load-plugins';
import { output as pagespeed } from 'psi';
import browserify from 'browserify';
import babelify from 'babelify';
import buffer from 'vinyl-buffer';
import source from 'vinyl-source-stream';
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
// Lint JavaScript
gulp.task('lint', () =>
gulp.src(['app/scripts/**/*.js', '!node_modules/**'])
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.if(!browserSync.active, $.eslint.failAfterError())),
);
// Optimize images
gulp.task('images', () =>
gulp.src('app/images/**/*')
.pipe($.cache($.imagemin({
progressive: true,
interlaced: true,
})))
.pipe(gulp.dest('build/images'))
.pipe($.size({ title: 'images' })),
);
// copy fonts
gulp.task('fonts', () =>
gulp.src('app/fonts/**/*')
.pipe(gulp.dest('build/fonts'))
.pipe($.size({ title: 'fonts' })),
);
// Copy all files at the root level (app)
gulp.task('copy', () =>
gulp.src([
'app/*',
'!app/*.html',
'!app/imports/',
// 'node_modules/apache-server-configs/build/.htaccess',
], {
dot: true,
}).pipe(gulp.dest('build'))
.pipe($.size({ title: 'copy' })),
);
// Compile and automatically prefix stylesheets
gulp.task('styles', () => {
const AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10',
];
// For best performance, don't add Sass partials to `gulp.src`
return gulp.src([
'app/styles/**/*.scss',
'app/styles/**/*.css',
])
.pipe($.newer('.tmp/styles'))
.pipe($.sourcemaps.init())
.pipe($.sass({
precision: 10,
includePaths: ['node_modules/susy/sass'],
}).on('error', $.sass.logError))
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
.pipe(gulp.dest('.tmp/styles'))
// Concatenate and minify styles
.pipe($.if('*.css', $.cssnano()))
.pipe($.size({ title: 'styles' }))
.pipe($.sourcemaps.write('./'))
.pipe($.rev())
.pipe(gulp.dest('build/styles'))
.pipe($.rev.manifest('manifest.json', {
cwd: './build',
merge: true,
}))
.pipe(gulp.dest('build/styles'))
.pipe(gulp.dest('.tmp/styles'));
});
gulp.task('scripts', () => {
const b = browserify({
entries: 'app/scripts/main.js',
transform: babelify,
debug: true,
});
return b.bundle()
.pipe(source('main.js'))
.pipe(buffer())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.sourcemaps.write())
.pipe(gulp.dest('.tmp/scripts'))
.pipe($.concat({ path: 'main.min.js', cwd: '' }))
.pipe($.uglify({ preserveComments: 'some' }))
// Output files
.pipe($.size({ title: 'scripts' }))
.pipe($.sourcemaps.write('.'))
.pipe($.rev())
.pipe(gulp.dest('build/scripts'))
.pipe($.rev.manifest('manifest.json', {
cwd: './build',
merge: true,
}))
.pipe(gulp.dest('build/scripts'))
.pipe(gulp.dest('.tmp/scripts'));
});
// Scan your HTML for assets & optimize them
gulp.task('html', () =>
gulp.src(['app/**/*.html', '!app/imports/*.html'])
.pipe($.fileInclude({
prefix: '##',
basepath: '#file',
}))
.pipe($.useref({
searchPath: '{.tmp,app}',
noAssets: true,
}))
.pipe(gulp.dest('.tmp/'))
// Minify any HTML
.pipe($.if('*.html', $.htmlmin({
removeComments: true,
collapseWhitespace: false,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeOptionalTags: true,
})))
// Output files
.pipe($.if('*.html', $.size({ title: 'html', showFiles: true })))
.pipe(gulp.dest('build')),
);
// Clean output directory
gulp.task('clean', () => del(['.tmp', 'build/*', '!build/.git'], { dot: true }));
// Watch files for changes & reload
gulp.task('serve', ['scripts', 'styles', 'html'], () => {
browserSync({
notify: false,
// Customize the Browsersync console logging prefix
logPrefix: 'WSK',
// Allow scroll syncing across breakpoints
scrollElementMapping: ['main', '.mdl-layout'],
// Run as an https by uncommenting 'https: true'
// Note: this uses an unsigned certificate which on first access
// will present a certificate warning in the browser.
// https: true,
server: ['.tmp', 'app'],
port: 3000,
});
gulp.watch(['app/**/*.html'], ['html', reload]);
gulp.watch(['app/styles/**/*.{scss,css}'], ['styles', reload]);
gulp.watch(['app/scripts/**/*.js'], ['lint', 'scripts', reload]);
gulp.watch(['app/images/**/*'], ['images', reload]);
gulp.watch(['app/fonts/**/*'], ['fonts', reload]);
});
// Build and serve the output from the distribution build
gulp.task('serve:build', ['default'], () =>
browserSync({
notify: false,
logPrefix: 'WSK',
// Allow scroll syncing across breakpoints
scrollElementMapping: ['main', '.mdl-layout'],
// Run as an https by uncommenting 'https: true'
// Note: this uses an unsigned certificate which on first access
// will present a certificate warning in the browser.
// https: true,
server: 'build',
port: 3001,
}),
);
// Build production files, the default task
gulp.task('default', ['clean'], cb =>
runSequence(
'copy',
'styles',
['lint', 'html', 'scripts', 'images', 'fonts'],
cb,
),
);
I ended up using gulp-rename to get the correct paths:
.pipe($.rename({
dirname: 'scripts',
}))
.pipe($.rev())
...Similar thing for styles but not merging the manifest files for each, opting to leave them in their respective folders.
And then used gulp-rev-collector to actually update the file mappings referenced in the manifest.
// Revision static asset files
gulp.task('rev', () =>
gulp.src(['build/**/rev-manifest.json', 'build/*.html'])
.pipe($.revCollector())
.pipe(gulp.dest('build')),
);
I have this task:
gulp.task('js', function() {
var webpackConfig = extend({}, require('./webpack.config.dev.js'), {
devtool: "source-map",
});
return gulp.src(config.paths.mainJs)
//.pipe(beautify({indent: {value: ' '}}))
.pipe(named())
.pipe(webpack(webpackConfig))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(through.obj(function (file, enc, cb) {
// Dont pipe through any source map files as it will be handled
// by gulp-sourcemaps
var isSourceMap = /\.map$/.test(file.path);
if (!isSourceMap) this.push(file);
cb();
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./deployment/deployment/js'))
.pipe(uglify())//JS_Parse_Error
The output of the previous pipe ./deployment/deployment/js/ is two files: bundle.js and bundle.js.map. So I think my pipe to uglify is wrong. How can I minify webpacks output?
All I had to do was modify my './webpack.config.dev.js` file already referenced in gulp to add the UglifyJsPlugin:
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: {
except: ['$super', '$', 'exports', 'require']
}
})
],
I am trying to customize the registration page with Stormpath and I can't figure out why the configuration options are not working. The enableXXX and requireXXX work, but none of the info inside web:{...} is showing up. I've tried reordering the options, but that doesn't work either.
Specifically, I want to:
-- Register users at /signup instead of /register. Right now only /register is working.
-- I want to redirect them to another site after registration. I randomly put google.com in there, but I'm still redirected to "/" after registration is complete.
-- I want to reorder the registration fields. I want email to be the first field, but username is currently first.
Here's app.js:
// Import required modules.
var express = require('express');
var stormpath = require('express-stormpath');
var path = require('path');
var engine = require('ejs-mate');
var app = express();
// use ejs-locals for all ejs templates:
app.engine('ejs', engine);
// Configure public views
app.set('views','./views');
app.use(stormpath.init(app, {
apiKeyFile: process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'] + ~removed
secretKey: '~removed',
application: '~removed',
enableRegistration: true,
enableGivenName: false,
requireGivenName: false,
enableSurname: false,
requireSurname: false,
website: true,
api: true,
web: {
register: {
uri: '/signup', // Use a different URL
nextUri: 'http://google.com', // Where to send the user to, if auto login is enabled
fields: {
passwordConfirm: {
enabled: true,
required: true
}
},
fieldOrder: [ "email", "username", "password", "passwordConfirm" ],
}
},
enableUsername: true,
requireUsername: true,
enableConfirmPassword: true,
requireConfirmPassword: true
}
));
app.get('/', function(req, res) {
res.render('home.ejs', {
title: 'Welcome'
});
});
app.get('/', function(req, res) {
res.send('home page!');
});
app.listen(process.env.PORT || 3000);
Other possibly relevant info:
-- The site is hosted on Heroku, but I'm not using the Stormpath add-on because I couldn't get it to work.
-- I'm on a Mac.
I've been stuck on this for days and I haven't been able to figure out what I'm doing wrong. Any help would be much appreciated.
The issue is likely this: we released a new version of this library recently which has new configuration options, and it appears you are using our OLD docs as a reference.
Here's what you'll want to do:
Update to the latest express-stormpath release. Then use the code below: (I converted your example to work with the latest release):
app.use(stormpath.init(app, {
client: {
apiKey: {
file: process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'] + '~removed'
}
},
application: {
href: '~removed',
},
web: {
register: {
enabled: true,
uri: '/signup',
nextUri: 'http://google.com', // don't send them here =)
fields: {
username: {
enabled: true,
required: true
},
givenName: {
enabled: false,
required: false
},
surname: {
enabled: false,
required: false
},
passwordConfirm: {
enabled: true,
required: true
}
},
fieldOrder: ['username', 'email', 'password', 'passwordConfirm']
}
},
website: true,
api: true
}));
my app created by generator-gulp-webapp, i load some plugins with bower, and some plugin depend on .swf files, such as zeroclipboard and uploader, and my problem is how to move swf files to * folder when i build this app?
eg:
gulp.task('extras', () => {
return gulp.src([
'app/.',
'!app/*.html'
], {
dot: true
}).pipe(gulp.dest('dist'));
});
gulp.task('extras', () => {
return gulp.src([
'app/*.swf'
], {
dot: true
}).pipe(gulp.dest('dist/scripts'));
});
how to Merger that to one task?
i just add one more task!
gulp.task('swf', () => {
return gulp.src([
'app/scripts/*.swf'
], {
dot: true
}).pipe(gulp.dest('dist/scripts'));
});
done!!!