Bin*_*han 22 javascript minify webpack
我希望能够在不使用grunt的情况下将文件缩小并连接到单个文件如何使用Grunt.js(0.3.x)连接和缩小多个CSS和JavaScript文件 我可以通过webpack实现这一点吗?我尝试了很多不同的组合,但问题是我使用的一些库,假设它是AMD或CommonJS格式,所以我一直在收到错误.
Des*_*Lua 11
可以使用extract-text-webpack-plugin或webpack-merge-and-include-global将多个CSS合并到单个文件中.
https://code.luasoftware.com/tutorials/webpack/merge-multiple-css-into-single-file/
要在没有AMD或CommonJS包装器的情况下将多个JavaScripts合并到单个文件中,可以使用webpack-merge-and-include-global完成.或者,您可以使用expose-loader将这些包装的模块公开为全局范围.
使用webpack-merge-and-include-global的示例.
const path = require('path');
const MergeIntoSingleFilePlugin = require('webpack-merge-and-include-globally');
module.exports = {
entry: './src/index.js',
output: {
filename: '[name]',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new MergeIntoSingleFilePlugin({
"bundle.js": [
path.resolve(__dirname, 'src/util.js'),
path.resolve(__dirname, 'src/index.js')
],
"bundle.css": [
path.resolve(__dirname, 'src/css/main.css'),
path.resolve(__dirname, 'src/css/local.css')
]
})
]
};
Run Code Online (Sandbox Code Playgroud)
小智 -9
是的,你可以使用 webpack 缩小它,如下所示
module.exports = {
// static data for index.html
metadata: metadata,
// for faster builds use 'eval'
devtool: 'source-map',
debug: true,
entry: {
'vendor': './src/vendor.ts',
'main': './src/main.ts' // our angular app
},
// Config for our build files
output: {
path: root('dist'),
filename: '[name].bundle.js',
sourceMapFilename: '[name].map',
chunkFilename: '[id].chunk.js'
},
resolve: {
// ensure loader extensions match
extensions: ['','.ts','.js','.json','.css','.html','.jade']
},
module: {
preLoaders: [{ test: /\.ts$/, loader: 'tslint-loader', exclude: [/node_modules/] }],
loaders: [
// Support for .ts files.
{
test: /\.ts$/,
loader: 'ts-loader',
query: {
'ignoreDiagnostics': [
2403, // 2403 -> Subsequent variable declarations
2300, // 2300 -> Duplicate identifier
2374, // 2374 -> Duplicate number index signature
2375 // 2375 -> Duplicate string index signature
]
},
exclude: [ /\.(spec|e2e)\.ts$/, /node_modules\/(?!(ng2-.+))/ ]
},
// Support for *.json files.
{ test: /\.json$/, loader: 'json-loader' },
// Support for CSS as raw text
{ test: /\.css$/, loader: 'raw-loader' },
// support for .html as raw text
{ test: /\.html$/, loader: 'raw-loader' },
// support for .jade as raw text
{ test: /\.jade$/, loader: 'jade' }
// if you add a loader include the resolve file extension above
]
},
plugins: [
new CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.bundle.js', minChunks: Infinity }),
// new CommonsChunkPlugin({ name: 'common', filename: 'common.js', minChunks: 2, chunks: ['main', 'vendor'] }),
// static assets
new CopyWebpackPlugin([ { from: 'src/assets', to: 'assets' } ]),
// generating html
new HtmlWebpackPlugin({ template: 'src/index.html', inject: false }),
// replace
new DefinePlugin({
'process.env': {
'ENV': JSON.stringify(metadata.ENV),
'NODE_ENV': JSON.stringify(metadata.ENV)
}
})
],
// Other module loader config
tslint: {
emitErrors: false,
failOnHint: false
},
// our Webpack Development Server config
devServer: {
port: metadata.port,
host: metadata.host,
historyApiFallback: true,
watchOptions: { aggregateTimeout: 300, poll: 1000 }
},
// we need this due to problems with es6-shim
node: {global: 'window', progress: false, crypto: 'empty', module: false, clearImmediate: false, setImmediate: false}
};
Run Code Online (Sandbox Code Playgroud)
这是 angular2 webpack 的 minify 和 concat 示例
也许你可以 先阅读它https://github.com/petehunt/webpack-howto
归档时间: |
|
查看次数: |
24657 次 |
最近记录: |