WebPACK包含基础框架和App SCSS编译到CSS
我想将sass编译添加到我的项目中,并编译我的app.scss文件,包括foundation sites样式 我的项目结构如下:WebPACK包含基础框架和App SCSS编译到CSS,webpack,webpack-dev-server,webpack-style-loader,Webpack,Webpack Dev Server,Webpack Style Loader,我想将sass编译添加到我的项目中,并编译我的app.scss文件,包括foundation sites样式 我的项目结构如下: -frontend -node_modules -src -css -scss -js index.html package.json webpack.config.js module: { loaders: [ { test: /\.jsx?$/,
-frontend
-node_modules
-src
-css
-scss
-js
index.html
package.json
webpack.config.js
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties'],
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader","css-loader!sass-loader"),
}
]
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new ExtractTextPlugin("./css/[name].css"),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
我用NPM安装了基础框架。我想在我的SCSS目录中创建App.SCSS文件,导入Soundation框架并将其编译到我的AppEngult.html
中链接的CSS/App.CSS。 以下是我的网页包配置:var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
module.exports = {
context: path.join(__dirname, "src"),
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/index.js",
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties'],
}
}
]
},
output: {
path: __dirname + "/src/",
filename: "index.min.js"
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
};
我在我的软件包中安装了sass加载器、样式加载器和css加载器,但我不知道如何在webpack中正确地包含这个过程
非常感谢您在这方面的帮助。您肯定走上了正确的道路。首先,确保安装了sass库的版本。我个人将节点sass用于webpack项目。更多信息。关于节点sass 此外,为了将您的SCS编译到css文件夹,您需要使用webpack extract text webpack插件info 需要配置文件顶部的插件:
var ExtractTextPlugin = require('extract-text-webpack-plugin');
安装插件后,可以使用以下方法设置加载程序:
-frontend
-node_modules
-src
-css
-scss
-js
index.html
package.json
webpack.config.js
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties'],
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader","css-loader!sass-loader"),
}
]
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new ExtractTextPlugin("./css/[name].css"),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
你的插件是这样的:
-frontend
-node_modules
-src
-css
-scss
-js
index.html
package.json
webpack.config.js
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties'],
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader","css-loader!sass-loader"),
}
]
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new ExtractTextPlugin("./css/[name].css"),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
从这里开始,您所要做的就是在entry js文件中需要主scss文件,在您的示例中是index.js。大概是这样的:
require('./path/to/app.scss');
至于基础方面,我想研究一下这个问题。看起来很有希望。你肯定走对了方向。首先,确保安装了sass库的版本。我个人将节点sass用于webpack项目。更多信息。关于节点sass 此外,为了将您的SCS编译到css文件夹,您需要使用webpack extract text webpack插件info 需要配置文件顶部的插件:
var ExtractTextPlugin = require('extract-text-webpack-plugin');
安装插件后,可以使用以下方法设置加载程序:
-frontend
-node_modules
-src
-css
-scss
-js
index.html
package.json
webpack.config.js
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties'],
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader","css-loader!sass-loader"),
}
]
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new ExtractTextPlugin("./css/[name].css"),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
你的插件是这样的:
-frontend
-node_modules
-src
-css
-scss
-js
index.html
package.json
webpack.config.js
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties'],
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader","css-loader!sass-loader"),
}
]
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new ExtractTextPlugin("./css/[name].css"),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
从这里开始,您所要做的就是在entry js文件中需要主scss文件,在您的示例中是index.js。大概是这样的:
require('./path/to/app.scss');
至于基础方面,我想研究一下这个问题。看起来很有希望