Skip to content

Instantly share code, notes, and snippets.

@dsk52
Created October 13, 2017 04:18
Show Gist options
  • Save dsk52/044806f3fc917d0ce04d1f453e08126a to your computer and use it in GitHub Desktop.
Save dsk52/044806f3fc917d0ce04d1f453e08126a to your computer and use it in GitHub Desktop.
webpack3でSassのビルドをしつつ、外部ファイル化する設定
import './style/style.scss';

WebPackも知らないうちにv3になってたから試しかけてみたメモ。 gulp + webpackっていう構成は単体よりも後々辛そうだし・・・

できたこと

  • Sassのimportに従った複数ファイルコンパイル
  • _*.scss も監視してくれる

わからないこと

  • 不要(main.js)なファイルが...
  • ディレクトリ内まるっと監視ができない... grob-import ?
{
"name": "test-webpack3",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"webpack": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-preset-es2017": "^6.24.1",
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.1",
"node-sass": "^4.5.3",
"sass-loader": "^6.0.6",
"style-loader": "^0.19.0",
"webpack": "^3.7.1"
}
}
@import "_style";
.hoge {
color: red;
}
const ExtractTextPlugin = require('extract-text-webpack-plugin');
// import ExtractTextPlugin from 'extract-text-webpack-plugin';
module.exports = {
entry: './main.js',
output: {
path: `${__dirname}/`,
filename: 'style.css'
},
module: {
rules: [
{
test: /\.scss/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ['css-loader', 'sass-loader']
})
},
]
},
plugins: [
new ExtractTextPlugin('style.css')
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment