-
Notifications
You must be signed in to change notification settings - Fork 3k
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
jquery #943
Comments
@tavo379 try to fetch it trough NPM by running |
I get this error: How can I fix this? |
@kr1stjans when do you get this error? could you describe your setup? |
I solved it with browserify & babelify. If I understand correctly the basic gulp configuration doesn't replace require calls with actual libraries. Perhaps it would be cool to add this to basic configuration, because it took me quite some time to set it up (I am completely new to frontend build systems).
|
I think I must be missing something. Could I ask for some help with this? I haven't found any useful information on the web. Here are my steps: wget https://github.com/google/web-starter-kit/releases/download/v0.6.5/web-starter-kit-0.6.5.zip
unzip web-starter-kit-0.6.5.zip
cd web-starter-kit-0.6.5
node --version
v8.0.0
yarn install
gulp serve Ok, so far so good. Now let's add jquery. Should be easy, right? Attempt 1Edit <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://code.getmdl.io/1.2.1/material.min.js"></script> Let's start the server again, we should be in business: gulp serve Go to the console in Chrome, let's see if it's working: $("a")
null Nope. Doesn't work. EDIT: This does work, unless you or browsersync reloads the page. If the page is reloaded, jquery becomes unloaded somehow and no longer works. I don't understand why that would happen. So, I still consider this broken, because it's not possible to work on a project without reloading the page. Attempt 2Ok, let's try something I found on the web: Edit <script src="https://code.getmdl.io/1.2.1/material.min.js"></script>
<!-- build:js scripts/main.min.js -->
<script src="scripts/jquery-3.2.1.min.js"></script>
<script src="scripts/main.js"></script>
<!-- endbuild --> Download jquery into the cd app/scripts
wget https://code.jquery.com/jquery-3.2.1.min.js Edit gulp.task('scripts', () =>
gulp.src([
// Note: Since we are not using useref in the scripts build pipeline,
// you need to explicitly list your scripts here in the right order
// to be correctly concatenated
'./app/scripts/jquery-3.2.1.min.js',
'./app/scripts/main.js'
// Other scripts
]) Now we're ready to run gulp again: gulp
|
I tried your proposed answer, and it doesn't work for me. First of all, I had to do:
Then I modified the // Concatenate and minify JavaScript. Optionally transpiles ES2015 code to ES5.
// to enable ES2015 support remove the line `"only": "gulpfile.babel.js",` in the
// `.babelrc` file.
//gulp.task('scripts', () =>
// gulp.src([
// // Note: Since we are not using useref in the scripts build pipeline,
// // you need to explicitly list your scripts here in the right order
// // to be correctly concatenated
// './node_modules/jquery/dist/jquery.js',
// './app/scripts/main.js'
// // Other scripts
// ])
// .pipe($.newer('.tmp/scripts'))
// .pipe($.sourcemaps.init())
// .pipe($.babel())
// .pipe($.sourcemaps.write())
// .pipe(gulp.dest('.tmp/scripts'))
// .pipe($.concat('main.min.js'))
// .pipe($.uglify({preserveComments: 'some'}))
// // Output files
// .pipe($.size({title: 'scripts'}))
// .pipe($.sourcemaps.write('.'))
// .pipe(gulp.dest('dist/scripts'))
// .pipe(gulp.dest('.tmp/scripts'))
//);
gulp.task('scripts', () => {
var environment = {
NODE_ENV: 'production'
};
return browserify('./app/scripts/main.js')
.transform('babelify', {presets: ['es2015']})
.bundle()
.pipe(source('main.js'))
.pipe(envify(environment))
.pipe($.uglify())
.pipe(gulp.dest('.tmp/scripts'))
.pipe(gulp.dest('dist/scripts'))
}); I had to delete the line: .pipe(buffer()) because the Still, it doesn't work:
|
Attempt 3 (it works!)Download the web-starter-kit and install dependencieswget https://github.com/google/web-starter-kit/releases/download/v0.6.5/web-starter-kit-0.6.5.zip
unzip web-starter-kit-0.6.5.zip
cd web-starter-kit-0.6.5
# Make sure you have a recent version of node
node --version
v8.0.0
# Install the dependencies
yarn install
# Start a server, should see a page load
gulp serve Ok, now 1. Install jQueryyarn add jquery The yarn command will download jQuery into "dependencies": {
"jquery": "^3.2.1"
} 2. Edit
|
@slowkow thank you so much! Your third attempt helped me! |
How can i use external libraries like jquery with google stater kit? , is i used for a cdn doesnt works, if i use in the code dont work for the eslint plugin.
The text was updated successfully, but these errors were encountered: