我设法将我的 css 和较少的资源(从 javascript“导入”)编译到all-my-LESS|CSS
,使用提取它们并将它们与toExtractTextPlugin
合并在一起。MergeFilesPlugin
combinedStyles.css
我缺少的一点:如何在此之上运行 cssnano(例如通过 postcss?)作为整理位?(哦,虽然我拥有内联源映射,但我没有设法生成外部combinedStyles.map
文件)。
这是我的组合webpack.config.babel.js
(忽略 babel 位,只是意味着,你可以用 ES6 编写它,使用更高级的 import 语句):
import path from 'path';
const webpack = require('webpack'); //to access built-in plugins
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import MergeFilesPlugin from 'merge-files-webpack-plugin';
const extractCSS = new ExtractTextPlugin("all-my-CSS.css");
const extractLESS = new ExtractTextPlugin("all-my-LESS.css");
export default {
entry: [ './src/index_5.js' ],
output: {
path: path.resolve( 'dist')
filename: 'bundle.js',
sourceMapFilename: './bundle.js.map'
},
module: {
rules: [{
test: /\.css$/,
use: extractCSS.extract(
[{ // This is basically "use"
loader: "css-loader",
options: {
minimize: false, // done later
sourceMap: true,
modules: false, // no css modules, all global styles
}
}]
)
},
{
test: /\.less$/,
use: extractLESS.extract( // This is basically "use"
[// No style-loader here! We want this external!
{
loader: "css-loader", // translates CSS into CommonJS
options: {
minimize: false,
sourceMap: true
}
}, {
loader: "less-loader", // compiles Less to CSS
options: {
sourceMap: true,
}
}]
)
}
] // rules
}, // module
devtool: 'inline-source-map',
devServer: { inline: true },
plugins: [
extractCSS,
extractLESS,
new MergeFilesPlugin({
filename: 'combinedStyles.css', //output filename
test: /\.css$/,
deleteSourceFiles: false // for now
})
]
};