{"id":1646,"date":"2017-04-28T16:51:18","date_gmt":"2017-04-28T07:51:18","guid":{"rendered":"http:\/\/lovelinux.mydns.jp\/?p=1646"},"modified":"2017-04-28T16:51:18","modified_gmt":"2017-04-28T07:51:18","slug":"webpack%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%80%81sass%e3%82%92%e3%82%b3%e3%83%b3%e3%83%91%e3%82%a4%e3%83%ab%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95-2017%e5%b9%b44%e6%9c%88%e7%89%88","status":"publish","type":"post","link":"https:\/\/lovelinux.mydns.jp\/?p=1646","title":{"rendered":"Webpack\u3092\u4f7f\u3063\u3066\u3001Sass\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u65b9\u6cd5 2017\u5e744\u6708\u7248"},"content":{"rendered":"<h3>\u306f\u3058\u3081\u306b<\/h3>\n<p>Webpack\u3092\u4f7f\u3063\u3066\u3001Sass\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<br \/>\nWeb\u306b\u305d\u308c\u306a\u308a\u306b\u3084\u308a\u65b9\u304c\u8f09\u3063\u3066\u307e\u3059\u304c\u30012017\u5e744\u6708\u672b\u73fe\u5728\u3067\u306f\u3001\u52d5\u304f\u4f8b\u304c\u5c11\u306a\u304b\u3063\u305f\u306e\u3067\u3001<br \/>\n\u5b9f\u969b\u306b\u52d5\u3044\u305f\u4f8b\u3092\u793a\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u672b\u5c3e\u306bReact\u306a\u3093\u304b\u306e\u958b\u767a\u3067 ES6\u3092\u30ce\u30fc\u30de\u30eb\u306aJavascript\u306b\u5909\u63db\u3059\u308b\u3068\u304d\u3068\u306e\u5408\u308f\u305b\u6280\u306e\u65b9\u6cd5\u3082\u8a18\u8f09\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30b3\u30f3\u30d1\u30a4\u30eb\u74b0\u5883\u69cb\u7bc9<\/h3>\n<p>[bash]<br \/>\n$ mkdir test-saas<br \/>\n$ cd test-saas<br \/>\n$ npm init -y<br \/>\n$ npm install webpack extract-text-webpack-plugin css-loader sass-loader style-loader node-sass &#8211;save-dev<br \/>\n[\/bash]<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u306e\u30d5\u30a9\u30eb\u30c0\u30c4\u30ea\u30fc\u306bsass\u304c\u3042\u308b\u3068\u4eee\u5b9a\u3057\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/saas-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/saas-1.png\" alt=\"saas-1\" width=\"206\" height=\"267\" class=\"alignnone size-full wp-image-1647\" \/><\/a><\/p>\n<h3>webpack.config\u306e\u8abf\u6574<\/h3>\n<p>\u30eb\u30fc\u30c8\u30d5\u30a9\u30eb\u30c0\u306b webpack.config.js\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5185\u5bb9\u3067\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u76ee\u6a19\u306f sass\u30d5\u30a9\u30eb\u30c0\u306b\u3042\u308b app.scss\u3068sub.scss\u3092 dist\/css\u30d5\u30a9\u30eb\u30c0\u306bapp.css\u3068sub.css\u3068\u3057\u3066\u51fa\u529b\u3059\u308b\u3002<\/p>\n<p>[bash]<br \/>\nvar path = require(&#8216;path&#8217;);<br \/>\nvar webpack = require(&#8216;webpack&#8217;);<br \/>\nvar ExtractTextPlugin = require(&#8216;extract-text-webpack-plugin&#8217;);<\/p>\n<p>module.exports = {<br \/>\n  devtool: &#8216;source-map&#8217;,<br \/>\n  entry: {<br \/>\n    app: &#8216;.\/sass\/app.scss&#8217;,<br \/>\n    sub: &#8216;.\/sass\/sub.scss&#8217;<br \/>\n  },<br \/>\n  output: {<br \/>\n    path: path.join(__dirname, &#8216;.\/dist\/css&#8217;),<br \/>\n    filename: &#8216;[name].css&#8217;<br \/>\n  },<br \/>\n  module: {<br \/>\n    loaders: [<br \/>\n      {<br \/>\n        test: \/\\.scss$\/,<br \/>\n        loader: ExtractTextPlugin.extract(&#8216;css-loader!sass-loader&#8217;)<br \/>\n      }<br \/>\n    ]<br \/>\n  },<br \/>\n  plugins: [<br \/>\n    new ExtractTextPlugin(&#8216;[name].css&#8217;)<br \/>\n  ],<br \/>\n}<br \/>\n[\/bash]<\/p>\n<h3>\u52d5\u4f5c\u74b0\u5883\uff08\u5404\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\uff09<\/h3>\n<p>2017\u5e744\u6708\u73fe\u5728\u3067\u52d5\u3044\u305f\u306e\u306f\u4ee5\u4e0b\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u3059\u3002<\/p>\n<p>[bash]<br \/>\n  &#8220;devDependencies&#8221;: {<br \/>\n    &#8220;css-loader&#8221;: &#8220;^0.28.0&#8221;,<br \/>\n    &#8220;extract-text-webpack-plugin&#8221;: &#8220;^2.1.0&#8221;,<br \/>\n    &#8220;node-sass&#8221;: &#8220;^4.5.2&#8221;,<br \/>\n    &#8220;sass-loader&#8221;: &#8220;^6.0.3&#8221;,<br \/>\n    &#8220;style-loader&#8221;: &#8220;^0.16.1&#8221;,<br \/>\n    &#8220;webpack&#8221;: &#8220;^2.4.1&#8221;,<br \/>\n  }<br \/>\n[\/bash]<\/p>\n<h3>\u30b3\u30f3\u30d1\u30a4\u30eb<\/h3>\n<p>[bash]<br \/>\n.\/node_modules\/.bin\/webpack<br \/>\n[\/bash]<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u3067\u304d\u3066\u3044\u308c\u3070\u6210\u529f\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/saas-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/saas-2.png\" alt=\"saas-2\" width=\"206\" height=\"399\" class=\"alignnone size-large wp-image-1648\" \/><\/a><\/p>\n<h3>\u3042\u3068\u304c\u304d<\/h3>\n<p>sass\u3060\u3051\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u3044\u30b1\u30fc\u30b9\u306f\u5c11\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001React\u306a\u3093\u304b\u3067\u30a2\u30d7\u30ea\u3092\u4f5c\u308a<br \/>\n\u540c\u6642\u306bsass\u3082\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u3044\u30b1\u30fc\u30b9\u306a\u3093\u304b\u306b webpack.config.js \u3092\u3069\u3046\u8a2d\u5b9a\u3059\u308b\u304b\u3068\u3044\u3046<br \/>\n\u3053\u3068\u3067\u60a9\u3093\u3060\u308a\u3057\u307e\u3059\u3088\u306d\u3002<\/p>\n<p>ES6\u3068\u304b\u3068\u306e\u30b3\u30f3\u30d1\u30a4\u30eb\u3068\u7d44\u307f\u5408\u308f\u305b\u305f\u3044\u5834\u5408\u306f\u3001<\/p>\n<p>[bash]<br \/>\nmodule.exports = {<br \/>\n     \u3054\u306b\u3087\u3054\u306b\u3087<br \/>\n}<br \/>\n[\/bash]<\/p>\n<p>\u306e\u90e8\u5206\u3092\u914d\u5217\u5b9a\u7fa9\u306b\u5909\u3048\u3066\u3084\u3063\u3066\u3001<\/p>\n<p>[bash]<br \/>\nmodule.exports = [<br \/>\n  {<br \/>\n     \u3054\u306b\u3087\u3054\u306b\u3087<br \/>\n  },<br \/>\n  {<br \/>\n     \u3054\u306b\u3087\u3054\u306b\u3087<br \/>\n  },<br \/>\n]<br \/>\n[\/bash]<\/p>\n<p>\u3068\u3057\u3066\u3084\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>React\u3067 ES6\u3092\u30ce\u30fc\u30de\u30eb\u306aJavaScript\u306b\u5909\u63db\u3059\u308b\u3068\u304d\u306e webpack.config.js\u306e\u8a2d\u5b9a\u306f<br \/>\n<a href=\"http:\/\/lovelinux.mydns.jp\/?p=1549\">\u3053\u3061\u3089\u306e\u8a18\u4e8b\u3092\u53c2\u8003\u306b<\/a>\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b Webpack\u3092\u4f7f\u3063\u3066\u3001Sass\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002 Web\u306b\u305d\u308c\u306a\u308a\u306b\u3084\u308a\u65b9\u304c\u8f09\u3063\u3066\u307e\u3059\u304c\u30012017\u5e744\u6708\u672b\u73fe\u5728\u3067\u306f\u3001\u52d5\u304f\u4f8b\u304c\u5c11\u306a\u304b\u3063\u305f\u306e\u3067\u3001 \u5b9f\u969b\u306b\u52d5\u3044\u305f\u4f8b\u3092\u793a\u3057\u3066\u304a\u304d\u307e\u3059\u3002 \u672b\u5c3e\u306bReact\u306a\u3093\u304b\u306e\u958b\u767a\u3067 ES6\u3092\u30ce\u30fc\u30de\u30eb\u306aJavascript\u306b\u5909\u63db\u3059\u308b\u3068\u304d\u3068\u306e\u5408\u308f\u305b\u6280\u306e\u65b9\u6cd5\u3082\u8a18\u8f09\u3057\u3066\u304a\u304d\u307e\u3059\u3002 \u30b3\u30f3\u30d1\u30a4\u30eb\u74b0\u5883\u69cb\u7bc9 [bash] $ mkdir test-saas $ cd test-saas $ npm init -y $ npm install webpack extract-text-webpack-plugin css-loader sass-loader style-loader node-sass &#8211;save-dev [\/bash] \u3053\u3093\u306a\u611f\u3058\u306e\u30d5\u30a9\u30eb\u30c0\u30c4\u30ea\u30fc\u306bsass\u304c\u3042\u308b\u3068\u4eee\u5b9a\u3057\u307e\u3059\u3002 webpack.config\u306e\u8abf\u6574 \u30eb\u30fc\u30c8\u30d5\u30a9\u30eb\u30c0\u306b webpack.config.js\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5185\u5bb9\u3067\u4f5c\u6210\u3057\u307e\u3059\u3002 \u76ee\u6a19\u306f sass\u30d5\u30a9\u30eb\u30c0\u306b\u3042\u308b app.scss\u3068sub.scss\u3092 dist\/css\u30d5\u30a9\u30eb\u30c0\u306bapp.css\u3068sub.css\u3068\u3057\u3066\u51fa\u529b\u3059\u308b\u3002 [bash] var path = require(&#8216;path&#8217;); var webpack = require(&#8216;webpack&#8217;); var ExtractTextPlugin = require(&#8216;extract-text-webpack-plugin&#8217;); module.exports = { devtool: &#8216;source-map&#8217;, entry: { app: &#8216;.\/sass\/app.scss&#8217;, sub: &#8216;.\/sass\/sub.scss&#8217; }, output: { path: path.join(__dirname, &#8216;.\/dist\/css&#8217;), filename: &#8216;[name].css&#8217; }, module: { loaders: [ { test: \/\\.scss$\/, loader: ExtractTextPlugin.extract(&#8216;css-loader!sass-loader&#8217;) } ] }, plugins: [ new ExtractTextPlugin(&#8216;[name].css&#8217;) ], } [\/bash] \u52d5\u4f5c\u74b0\u5883\uff08\u5404\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\uff09 2017\u5e744\u6708\u73fe\u5728\u3067\u52d5\u3044\u305f\u306e\u306f\u4ee5\u4e0b\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u3059\u3002 [bash] &#8220;devDependencies&#8221;: { &#8220;css-loader&#8221;: &#8220;^0.28.0&#8221;, &#8220;extract-text-webpack-plugin&#8221;: &#8220;^2.1.0&#8221;, &#8220;node-sass&#8221;: &#8220;^4.5.2&#8221;, &#8220;sass-loader&#8221;: &#8220;^6.0.3&#8221;, &#8220;style-loader&#8221;: &#8220;^0.16.1&#8221;, &#8220;webpack&#8221;: &#8220;^2.4.1&#8221;, } [\/bash] \u30b3\u30f3\u30d1\u30a4\u30eb [bash] .\/node_modules\/.bin\/webpack [\/bash] \u3053\u3093\u306a\u611f\u3058\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u3067\u304d\u3066\u3044\u308c\u3070\u6210\u529f\u3067\u3059\u3002 \u3042\u3068\u304c\u304d sass\u3060\u3051\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u3044\u30b1\u30fc\u30b9\u306f\u5c11\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001React\u306a\u3093\u304b\u3067\u30a2\u30d7\u30ea\u3092\u4f5c\u308a \u540c\u6642\u306bsass\u3082\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u3044\u30b1\u30fc\u30b9\u306a\u3093\u304b\u306b webpack.config.js \u3092\u3069\u3046\u8a2d\u5b9a\u3059\u308b\u304b\u3068\u3044\u3046 \u3053\u3068\u3067\u60a9\u3093\u3060\u308a\u3057\u307e\u3059\u3088\u306d\u3002 ES6\u3068\u304b\u3068\u306e\u30b3\u30f3\u30d1\u30a4\u30eb\u3068\u7d44\u307f\u5408\u308f\u305b\u305f\u3044\u5834\u5408\u306f\u3001 [bash] module.exports = { \u3054\u306b\u3087\u3054\u306b\u3087 } [\/bash] \u306e\u90e8\u5206\u3092\u914d\u5217\u5b9a\u7fa9\u306b\u5909\u3048\u3066\u3084\u3063\u3066\u3001 [bash] module.exports = [ { \u3054\u306b\u3087\u3054\u306b\u3087 }, { \u3054\u306b\u3087\u3054\u306b\u3087 }, ] [\/bash] \u3068\u3057\u3066\u3084\u3063\u3066\u304f\u3060\u3055\u3044\u3002 React\u3067 ES6\u3092\u30ce\u30fc\u30de\u30eb\u306aJavaScript\u306b\u5909\u63db\u3059\u308b\u3068\u304d\u306e webpack.config.js\u306e\u8a2d\u5b9a\u306f \u3053\u3061\u3089\u306e\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"author":1,"featured_media":1649,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[77,3],"tags":[72,82,83],"class_list":{"0":"post-1646","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-react","8":"category-3","9":"tag-reactjs","10":"tag-sass","11":"tag-webpack"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts\/1646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1646"}],"version-history":[{"count":2,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts\/1646\/revisions"}],"predecessor-version":[{"id":1651,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts\/1646\/revisions\/1651"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/media\/1649"}],"wp:attachment":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}