1 Star 0 Fork 21

紫荆桂/bricks

forked from 终端组/bricks 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.config.js 2.77 KB
一键复制 编辑 原始数据 按行查看 历史
张桂梅 提交于 2019-06-19 14:55 . add variables theme config
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const webpack = require('webpack');
const themeConfig = require('./themes.config.ts');
const devMode = process.env.NODE_ENV !== 'production'
const minimizer = [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true // set to true if you want JS source maps
}),
new OptimizeCSSAssetsPlugin({})
];
const commonCssLoaders = [
MiniCssExtractPlugin.loader, // creates style nodes from JS strings or extra css
"css-loader", // translates CSS into CommonJS
"postcss-loader",
];
const themeCssEntry = () => {
let entryList = {};
for(let theme in themeConfig) {
entryList[theme] = `./src/styles/bricks_${theme}.scss`;
}
return entryList;
};
module.exports = {
mode: devMode ? 'development' : 'production',
devtool: devMode ? "inline-source-map" : 'hidden-source-map',
entry: {
bricks: "./src/index.ts",
...themeCssEntry()
},
output: {
path: __dirname + '/dist',
filename: devMode ? "[name].development.js" : '[name].production.js',
library: 'bricks',
libraryTarget: 'umd'
},
optimization: {
minimizer: devMode ? [] : minimizer,
sideEffects: false
},
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), // 忽略moment的语言包
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: devMode ? "[name].development.css" : "[name].production.css",
chunkFilename: "[id].css"
})
],
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: [".ts", ".tsx", ".js"]
},
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{
test: /\.tsx?$/,
use: [
"babel-loader",
"ts-loader"
]
},
{
test: /\.css/,
use: commonCssLoaders,
},
{
test: /\.scss$/,
use: [
...commonCssLoaders,
"sass-loader", // compiles Sass to CSS
]
},
{
test: /(\.(eot|ttf|woff|woff2)|font)$/,
loader: 'file-loader',
options: {
outputPath: 'fonts/'
}
},
{
test: /\.(png|jpg|gif|svg|jpeg)$/,
loader: 'file-loader',
options: {
outputPath: 'images/'
}
}
]
},
externals: {
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
},
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/tray_yan/bricks.git
git@gitee.com:tray_yan/bricks.git
tray_yan
bricks
bricks
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385