Created
April 23, 2017 06:12
-
-
Save ikuwow/e0e1cacbf7f42ad9c2ed7d13ee296e4c to your computer and use it in GitHub Desktop.
YarnやWebpackでアセットがうまく管理されたWebページを作ってみる その1 ref: http://qiita.com/ikuwow/items/420aed9079604d8d6e90
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ls | |
LICENSE README.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php -S localhost:8383 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yarn add lodash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* jshint browser: true */ | |
'use strict'; | |
+import _ from 'lodash'; | |
+// const _ = require('lodash'); | |
+ | |
function component() { | |
var element = document.createElement('div'); | |
element.innerHTML = _.join(['Hello', 'Webpack'], ' '); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir dist/ | |
$(yarn bin)/webpack app/index.js dist/bundle.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo dist >> .gitignore | |
git add .gitignore app/index.js index.html package.json yarn.lock | |
git commit -m 'First webpack use' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(yarn bin)/webpack |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo node_modules > .gitignore | |
git add . | |
git commit -m 'Initialize yarn' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rm -rf node_modules | |
$ npm cache clean | |
$ time npm install | |
(...略...) | |
real 0m29.508s | |
user 0m13.474s | |
sys 0m4.642s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git add package.json yarn.lock | |
$ git commit -m 'install webpack' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* jshint browser: true */ | |
'use strict'; | |
function component() { | |
var element = document.createElement('div'); | |
element.innerHTML = _.join(['Hello', 'Webpack'], ' '); | |
return element; | |
} | |
document.body.appendChild(component()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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