-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
825 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
'use strict' | ||
const path = require('path') | ||
const chalk = require('chalk') | ||
const webpack = require('webpack') | ||
const VueLoaderPlugin = require('vue-loader/lib/plugin') | ||
const MiniCssExtractPlugin = require('mini-css-extract-plugin') | ||
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin') | ||
|
||
const options = { | ||
mode: 'production', | ||
entry: path.resolve(__dirname, '../examples/components/demo-block/index.js'), | ||
output: { | ||
path: path.resolve(__dirname, '../dist'), | ||
filename: 'index.js', | ||
publicPath: './', | ||
library: 'DemoBlock', // 定义导出到变量 | ||
libraryExport: 'default', // 定义导出指定属性 | ||
libraryTarget: 'umd', | ||
umdNamedDefine: true, // libraryTarget: "umd" | ||
globalObject: 'typeof self !== \'undefined\' ? self : this' // https://github.com/webpack/webpack/issues/6522 | ||
}, | ||
externals: { | ||
vue: { | ||
commonjs: 'vue', | ||
commonjs2: 'vue', | ||
amd: 'vue', | ||
root: 'Vue' | ||
} | ||
}, | ||
resolve: { | ||
symlinks: false, | ||
extensions: ['.vue', '.js', '.json'], | ||
alias: { | ||
'vue$': 'vue/dist/vue.esm.js' | ||
} | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.vue$/, | ||
loader: 'vue-loader' | ||
}, | ||
{ | ||
test: /\.js$/, | ||
exclude: /(node_modules)/, | ||
use: { | ||
loader: 'babel-loader', | ||
options: { | ||
presets: ['@babel/preset-env'], | ||
plugins: ['@babel/plugin-transform-runtime'] | ||
} | ||
} | ||
}, | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
{ | ||
loader: MiniCssExtractPlugin.loader, | ||
options: { | ||
// you can specify a publicPath here | ||
// by default it uses publicPath in webpackOptions.output | ||
// publicPath: '../', | ||
hmr: process.env.NODE_ENV === 'development' | ||
} | ||
}, | ||
// 'vue-style-loader', | ||
'css-loader' | ||
] | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
NODE_ENV: process.env.NODE_ENV || '"development"' | ||
} | ||
}), | ||
new VueLoaderPlugin(), | ||
new MiniCssExtractPlugin({ | ||
filename: 'css/default.css' | ||
}) | ||
], | ||
optimization: { | ||
minimizer: [new OptimizeCSSAssetsPlugin({})] | ||
} | ||
} | ||
|
||
const compiler = webpack(options) | ||
|
||
compiler.run((err, stats) => { | ||
if (err) throw err | ||
process.stdout.write(stats.toString({ | ||
colors: true, | ||
modules: false, | ||
children: false, | ||
chunks: false, | ||
chunkModules: false | ||
}) + '\n\n') | ||
|
||
if (stats.hasErrors()) { | ||
console.log(chalk.red(' Build failed with errors.\n')) | ||
process.exit(1) | ||
} | ||
|
||
const dist = require('../dist') | ||
|
||
console.log('dist:', dist) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.