You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/config/webpack.common.ts

151 lines
4.4 KiB

import AddAssetHtmlPlugin from "add-asset-html-webpack-plugin";
import HtmlWebPackPlugin from "html-webpack-plugin";
import * as path from 'path';
import * as webpack from 'webpack';
import { outputDir } from "./outputPath";
import CleanTerminalPlugin from "clean-terminal-webpack-plugin";
const WebpackBar = require('webpackbar');
export const buildVersion = new Date().toLocaleString();
function getpath(fileName: string)
{
return path.resolve(__dirname, fileName);
}
const TS_LOADER = [
{ loader: 'cache-loader', options: { cacheDirectory: "node_modules/.cache_loader" } },
{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
}
];
const config: webpack.Configuration = {
entry: "./src/index.tsx",
output: {
filename: "[hash].main.js",
path: getpath(outputDir),
globalObject: "this"
},
8 years ago
resolve: {
alias: {
"dat.gui": getpath('../node_modules/dat.gui/build/dat.gui.js'),
},
7 years ago
extensions: [".ts", ".tsx", ".js", "json"]
8 years ago
},
module: {
rules: [
{
test: /\.worker\.ts$/,
exclude: /node_modules/,
use: [
4 years ago
{ loader: 'worker-loader', },
...TS_LOADER
]
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: TS_LOADER,
},
{
test: /\.[(png)|(obj)|(json)]$/,
loader: "file-loader"
},
//样式加载 css
7 years ago
{
test: /\.css$/,
6 years ago
use: ['style-loader', 'css-loader']
},
//样式加载 less
{
test: /\.less$/,
use: [
{ loader: "style-loader" },
{ loader: 'css-loader', options: { sourceMap: false } },
{
loader: "less-loader",
options: {
lessOptions: {
strictMath: true,
noIeCompat: true
}
}
}
]
},
//字体加载 blueprint
{
test: /\.(ttf|eot|svg)$/,
use: {
loader: 'file-loader',
4 years ago
options: { name: 'fonts/[hash].[ext]' }
}
},
//字体加载 blueprint
{
test: /\.(woff|woff2|jpg|png)$/,
use: {
loader: 'url-loader',
options: {
name: 'fonts/[hash].[ext]',
limit: 5000,
mimetype: 'application/font-woff'
}
}
},
{
test: /\.(glsl|vs|fs)$/,
loader: 'shader-loader'
}
7 years ago
]
8 years ago
},
externals: {
},
7 years ago
plugins: [
new HtmlWebPackPlugin({
title: "webCAD",
template: getpath('../src/index.html')
}),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require(`${outputDir}/manifest.json`)
}),
new AddAssetHtmlPlugin(
[
{
filepath: "./src/loading.css",
typeOfAsset: "css",
},
{
filepath: "./node_modules/normalize.css/normalize.css",
typeOfAsset: "css",
},
{
filepath: "./node_modules/@blueprintjs/core/lib/css/blueprint.css",
typeOfAsset: "css",
},
4 years ago
{ filepath: "./dist/*.dll.js", },
]
),
7 years ago
new webpack.ProvidePlugin({
ReactDOM: 'react-dom',
React: 'react',
THREE: "three"
7 years ago
}),
new webpack.DefinePlugin({ 'process': "globalThis", version: JSON.stringify(buildVersion) }),
new CleanTerminalPlugin(),
new WebpackBar()
// new HardSourceWebpackPlugin(),
// new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }),
],
node: false
};
export default config;