-
Notifications
You must be signed in to change notification settings - Fork 705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to import ES6 module to my js? #507
Comments
Support questions are better asked on Stack Overflow: http://stackoverflow.com/questions/tagged/yeoman |
There is also recipe |
Someone has tweaked the recipe linked above and included error handling, here. Thanks! |
I am using generator-webapp 4.0.0-8 and the recipe above need some tweaks so here it is : From the original recipe, you must install these :
Then
|
@huguesbrunelle could you point out the difference from the recipe and explain what you think works in your example that doesn't in the recipe? |
I accidentally reopened, so I'm closing. I'll reopen again for real once we prove that there's an issue. |
@silvenon const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const { argv } = require('yargs');
+ const notifier = require('node-notifier');
+ const browserify = require('browserify');
+ const babelify = require('babelify');
+ const buffer = require('vinyl-buffer');
+ const source = require('vinyl-source-stream');
const $ = gulpLoadPlugins();
const server = browserSync.create();
...
function scripts() {
- return src('app/scripts/**/*.js', {
+ const b = browserify({
+ entries: 'app/scripts/main.js',
+ transform: babelify,
+ debug: true,
sourcemaps: !isProd,
})
- .pipe($.plumber())
- .pipe($.babel())
- .pipe(dest('.tmp/scripts', {
- sourcemaps: !isProd ? '.' : false,
- }))
- .pipe(server.reload({stream: true}));
+ return b.bundle()
+ .on('error', function(err){
+ notifier.notify({
+ title: 'Compile Error',
+ message: err.message
+ });
+ this.emit('end');
+ })
+ .pipe(source('main.js'))
+ .pipe($.plumber())
+ .pipe(buffer())
+ .pipe(dest('.tmp/scripts', {
+ sourcemaps: !isProd ? '.' : false,
+ }))
+ .pipe(server.reload({stream: true}));
};
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"autoprefixer": "^9.5.1",
+ "babelify": "^10.0.0",
"browser-sync": "^2.26.5",
+ "browserify": "^17.0.0",
"chai": "^4.2.0",
"cross-env": "^5.2.0",
"cssnano": "^4.1.10",
...
"gulp-useref": "^3.1.6",
"mkdirp": "^0.5.1",
"mocha": "^6.2.3",
+ "node-notifier": "^9.0.0",
+ "vinyl-buffer": "^1.0.1",
+ "vinyl-source-stream": "^2.0.0",
+ "webpack-stream": "^6.1.1",
"yargs": "13.2.4"
},
"scripts": {
...
],
"eslintConfig": {
"parserOptions": {
+ "ecmaVersion": 6,
"sourceType": "module"
},
"env": { |
import domready from 'domready';
ERROR: main.js:4Uncaught ReferenceError: require is not defined
who can help me? Thanks~
The text was updated successfully, but these errors were encountered: