以前の3からWebpack4にバージョンアップし、
それまでファイルの圧縮に使用してきた「uglifyjs-webpack-plugin」に変わり、
「terser-webpack-plugin」を導入してうまくファイル更新の後コンパイルできるのですが、
今までできていたファイルの中身(ソースコードを一行に)というのができなくなっております。
以下が設定したwebpack.config.jsファイルです。
webpack.config.js
/* ---------------------------------------------------------------------------------- 外部ファイル読み込み ---------------------------------------------------------------------------------- */ const path = require('path'); const TerserPlugin = require('../../node_modules/terser-webpack-plugin'); //const UglifyJsPlugin = require('../../node_modules/uglifyjs-webpack-plugin'); /* ---------------------------------------------------------------------------------- 変数定義 ---------------------------------------------------------------------------------- */ var webpack = require('../../node_modules/webpack'); var jsRootDir = './src/js/'; /* ---------------------------------------------------------------------------------- コンパイルの仕方を定義 ---------------------------------------------------------------------------------- */ module.exports = { mode: 'development', // インポートファイル(ここに新規ファイルを追加していく) entry: { main: jsRootDir + 'main.js', // 共通 component: jsRootDir + 'jsx/component.jsx' // JSXページ }, // ビルド実行して実際に出力されるファイル output: { path: path.join(__dirname, 'dist'), publicPath: './public/js/', filename: "[name].js" }, module: { rules: [ { test: /.(js|jsx)$/, loader: 'jsx-loader', exclude: /node_modules/ } ] }, resolve: { extensions: ['.js', '.jsx'] }, externals: { jQuery: 'jQuery' }, node: { setImmediate: false }, optimization: { minimizer: [ new TerserPlugin({ parallel: true, cache: true, terserOptions: { ie8: false, // sourceMap: true, compress: { dead_code: true, warnings: false, properties: true, drop_debugger: true, conditionals: true, booleans: true, loops: true, unused: true, toplevel: true, if_return: true, inline: true, join_vars: true }, output: { comments: false, beautify: false, indent_level: 2 } } }) ] }, plugins: [ new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.AggressiveMergingPlugin(), new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), /* new webpack.optimize.UglifyJsPlugin({ compress: { screw_ie8: false, dead_code: true, warnings: false }, comments: false, mangle: false, sourceMap: true }), */ new webpack.HotModuleReplacementPlugin() ], devtool: 'source-map' };
package.json
{ "name": "template", "version": "0.0.0", "description": "template", "main": "gulpfile.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "webpack-dev-server --mode development --open" }, "author": "", "license": "ISC", "devDependencies": { "babel-cli": "^6.26.0", "babel-core": "^6.26.3", "babel-preset-env": "^1.7.0", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", "browser-sync": "^2.18.2", "css-loader": "^1.0.0", "css-mqpacker": "^6.0.2", "gulp": "^3.9.1", "gulp-autoprefixer": "^3.1.1", "gulp-cached": "^1.1.1", "gulp-changed": "^1.3.2", "gulp-clean-css": "^3.7.0", "gulp-combine-media-queries": "^0.2.0", "gulp-compass": "^2.1.0", "gulp-concat": "^2.6.1", "gulp-connect-php": "0.0.8", "gulp-csscomb": "^3.0.8", "gulp-cssmin": "^0.1.7", "gulp-csso": "^3.0.1", "gulp-ejs": "^3.1.1", "gulp-gzip": "^1.4.1", "gulp-htmlhint": "^0.3.1", "gulp-imagemin": "^3.1.1", "gulp-notify": "^2.2.0", "gulp-plumber": "^1.1.0", "gulp-postcss": "^7.0.1", "gulp-rename": "^1.2.2", "gulp-sass": "^3.0.0", "gulp-sftp": "^0.1.5", "gulp-uglify": "^2.0.0", "gulp-util": "^3.0.8", "gulp-watch": "^4.3.11", "gulp-webpack": "^1.5.0", "imagemin-pngquant": "^5.0.0", "jquery": "^3.3.1", "jsx-loader": "^0.13.2", "postcss-cssnext": "^3.1.0", "react": "^16.5.2", "react-dom": "^16.5.2", "rimraf": "^2.6.1", "run-sequence": "^1.2.2", "style-loader": "^0.23.0", "vinyl-ftp": "^0.5.0", "webpack": "^4.20.2", "webpack-cli": "^3.1.2", "webpack-stream": "^4.0.0" }, "dependencies": { "@fancyapps/fancybox": "^3.5.1", "ajv": "^6.5.4", "animejs": "^2.2.0", "del": "^2.2.2", "imagemin-pngquant": "^5.0.0", "slick-carousel": "^1.8.1", "terser": "^3.9.3", "terser-webpack-plugin": "^1.1.0" } }
ご教授のほどよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/05 11:02