Skip to content

Instantly share code, notes, and snippets.

@ikuwow
Created April 23, 2017 06:12
Show Gist options
  • Save ikuwow/e0e1cacbf7f42ad9c2ed7d13ee296e4c to your computer and use it in GitHub Desktop.
Save ikuwow/e0e1cacbf7f42ad9c2ed7d13ee296e4c to your computer and use it in GitHub Desktop.
YarnやWebpackでアセットがうまく管理されたWebページを作ってみる その1 ref: http://qiita.com/ikuwow/items/420aed9079604d8d6e90
$ yarn
yarn install v0.23.2
info No lockfile found.
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
success Saved lockfile.
✨ Done in 0.44s.
$ ls
LICENSE README.md
php -S localhost:8383
yarn add lodash
/* jshint browser: true */
'use strict';
+import _ from 'lodash';
+// const _ = require('lodash');
+
function component() {
var element = document.createElement('div');
element.innerHTML = _.join(['Hello', 'Webpack'], ' ');
<head>
<meta charset="UTF-8">
<title>Webpack 2 demo</title>
- <script src="https://cdn.jsdelivr.net/lodash/4.17.4/lodash.min.js"></script>
</head>
<body>
<h1>webpack 2 demo</h1>
- <script src="app/index.js"></script>
+ <script src="dist/bundle.js"></script>
</body>
</html>
mkdir dist/
$(yarn bin)/webpack app/index.js dist/bundle.js
echo dist >> .gitignore
git add .gitignore app/index.js index.html package.json yarn.lock
git commit -m 'First webpack use'
$(yarn bin)/webpack
$ yarn init
yarn init v0.23.2
question name (yarn-and-webpack):
question version (1.0.0): 0.1.0
question description: my test repository
question entry point (index.js):
question repository url ([email protected]:ikuwow/yarn-and-webpack.git):
question author (Ikuo Degawa <[email protected]>):
question license (MIT):
success Saved package.json
✨ Done in 25.44s.
IkuosMacmini:yarn-and-webpack degawaikuo$ ls
LICENSE README.md node_modules package.json yarn.lock
echo node_modules > .gitignore
git add .
git commit -m 'Initialize yarn'
$ yarn add webpack
yarn add v0.23.2
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
(略...)
success Saved lockfile.
success Saved 280 new dependencies.
✨ Done in 21.03s.
$ rm -rf node_modules
$ npm cache clean
$ time npm install
(...略...)
real 0m29.508s
user 0m13.474s
sys 0m4.642s
$ rm -rf node_modules
$ yarn cache clean
$ time yarn
yarn install v0.23.2
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
✨ Done in 9.82s.
real 0m10.065s
user 0m8.322s
sys 0m5.152s
$ git add package.json yarn.lock
$ git commit -m 'install webpack'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Webpack 2 demo</title>
<script src="https://cdn.jsdelivr.net/lodash/4.17.4/lodash.min.js"></script>
</head>
<body>
<h1>webpack 2 demo</h1>
<script src="app/index.js"></script>
</body>
</html>
/* jshint browser: true */
'use strict';
function component() {
var element = document.createElement('div');
element.innerHTML = _.join(['Hello', 'Webpack'], ' ');
return element;
}
document.body.appendChild(component());
'use strict';
const path = require('path');
module.exports = {
entry: './app/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment